Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
TFJ-655 introduce a public factory class for entity classes for the b…
Browse files Browse the repository at this point in the history
…etter twitter-text-java compatibility

method added:
z_T4JInternalJSONImplFactory#createHashtagEntity
z_T4JInternalJSONImplFactory#createUserMentionEntity
z_T4JInternalJSONImplFactory#createUrlEntity
  • Loading branch information
Yusuke Yamamoto committed May 3, 2012
1 parent 5482f1e commit a5f6ce7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
Expand Up @@ -40,6 +40,13 @@
init(json);
}

/* package */ HashtagEntityJSONImpl(int start, int end, String text) {
super();
this.start = start;
this.end = end;
this.text = text;
}

/* For serialization purposes only. */
/* package */ HashtagEntityJSONImpl() {

Expand Down
Expand Up @@ -46,6 +46,28 @@
init(json);
}

/* package */ URLEntityJSONImpl(int start, int end, String url, String expandedURL, String displayURL) {
super();
this.start = start;
this.end = end;
try {
this.url = new URL(url);
} catch (MalformedURLException e) {
try {
this.url = new URL("http://example.com/");
} catch (MalformedURLException ignore) {
}
}
try {
this.expandedURL = new URL(expandedURL);
} catch (MalformedURLException e) {
try {
this.expandedURL = new URL("http://example.com/");
} catch (MalformedURLException ignore) {
}
}
this.displayURL = displayURL;
}
/* For serialization purposes only. */
/* package */ URLEntityJSONImpl() {

Expand Down
Expand Up @@ -42,6 +42,15 @@
init(json);
}

/* package */ UserMentionEntityJSONImpl(int start, int end, String name, String screenName, long id) {
super();
this.start = start;
this.end = end;
this.name = name;
this.screenName = screenName;
this.id = id;
}

/* For serialization purposes only. */
/* package */ UserMentionEntityJSONImpl() {

Expand Down
Expand Up @@ -254,6 +254,34 @@ public <T> ResponseList<T> createEmptyResponseList() {
return new ResponseListImpl<T>(0, null);
}

/**
* static factory method for twitter-text-java
* @return hashtag entity
* @since Twitter4J 2.2.6
*/
public static HashtagEntity createHashtagEntity(int start, int end, String text){
return new HashtagEntityJSONImpl(start, end, text);
}

/**
* static factory method for twitter-text-java
* @return user mention entity
* @since Twitter4J 2.2.6
*/
public static UserMentionEntity createUserMentionEntity(int start, int end, String name, String screenName,
long id) {
return new UserMentionEntityJSONImpl(start, end, name, screenName, id);
}

/**
* static factory method for twitter-text-java
* @return url entity
* @since Twitter4J 2.2.6
*/
public static URLEntity createUrlEntity(int start, int end, String url, String expandedURL, String displayURL) {
return new URLEntityJSONImpl(start, end, url, expandedURL, displayURL);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down

0 comments on commit a5f6ce7

Please sign in to comment.