Permalink
Browse files

TFJ-655 introduce a public factory class for entity classes for the b…

…etter twitter-text-java compatibility

method added:
z_T4JInternalJSONImplFactory#createHashtagEntity
z_T4JInternalJSONImplFactory#createUserMentionEntity
z_T4JInternalJSONImplFactory#createUrlEntity
  • Loading branch information...
1 parent 5482f1e commit a5f6ce7a71758d6f28fb90679da9a0a3f88890fd Yusuke Yamamoto committed May 3, 2012
@@ -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() {
@@ -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() {
@@ -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() {
@@ -254,6 +254,34 @@ public TwitterAPIConfiguration createTwitterAPIConfiguration(HttpResponse res) t
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;

0 comments on commit a5f6ce7

Please sign in to comment.