[LIB-8] URL and HTML tag processing, new entities fields
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonEvent.java
index 0ba62ab..e7a256d 100644 (file)
@@ -21,8 +21,12 @@ import java.util.Date;
 import com.google.gson.annotations.Expose;
 import com.google.gson.annotations.SerializedName;
 
+import org.hedgecode.snooker.SnookerURLUtils;
+import org.hedgecode.snooker.annotation.IsURL;
+import org.hedgecode.snooker.annotation.WithHTMLTags;
 import org.hedgecode.snooker.api.Event;
 import org.hedgecode.snooker.api.EventFormat;
+import org.hedgecode.snooker.api.Player;
 import org.hedgecode.snooker.api.Season;
 
 /**
@@ -66,6 +70,7 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private String sex;
     @SerializedName("AgeGroup")
     private String ageGroup;
+    @IsURL
     @SerializedName("Url")
     private String url;
     @SerializedName("Related")
@@ -96,6 +101,7 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private float conversionRate;
     @SerializedName("AllRoundsAdded")
     private boolean allRoundsAdded;
+    @IsURL
     @SerializedName("PhotoURLs")
     private String photoUrls;
     @SerializedName("NumCompetitors")
@@ -106,14 +112,20 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private int numActive;
     @SerializedName("NumResults")
     private int numResults;
+    @WithHTMLTags
     @SerializedName("Note")
     private String note;
+    @WithHTMLTags
     @SerializedName("CommonNote")
     private String commonNote;
     @SerializedName("DefendingChampion")
-    private int defendingChampion;
+    private int defendingChampionId;
+    @Expose
+    private Player defendingChampion;
     @SerializedName("PreviousEdition")
-    private int previousEdition;
+    private int previousEditionId;
+    @Expose
+    private Event previousEdition;
 
     protected JsonEvent() {
     }
@@ -191,14 +203,16 @@ public class JsonEvent extends JsonIdEntity implements Event {
 
     @Override
     public Event mainEvent() {
-        if (mainEvent == null && mainEventId == eventId)
+        if (mainEvent == null && mainEventId == eventId) {
             mainEvent = this;
+        }
         return mainEvent;
     }
 
     public void setMainEvent(Event event) {
-        if (event != null && eventId == event.eventId())
+        if (event != null && eventId == event.eventId()) {
             mainEvent = event;
+        }
     }
 
     @Override
@@ -273,11 +287,23 @@ public class JsonEvent extends JsonIdEntity implements Event {
         return twitter;
     }
 
+    @IsURL
+    @Override
+    public String twitterUrl() {
+        return SnookerURLUtils.twitterUrl(twitter);
+    }
+
     @Override
     public String hashTag() {
         return hashTag;
     }
 
+    @IsURL
+    @Override
+    public String hashTagUrl() {
+        return SnookerURLUtils.hashtagUrl(hashTag);
+    }
+
     @Override
     public float conversionRate() {
         return conversionRate;
@@ -324,15 +350,37 @@ public class JsonEvent extends JsonIdEntity implements Event {
     }
 
     @Override
-    public int defendingChampion() {
+    public int defendingChampionId() {
+        return defendingChampionId;
+    }
+
+    @Override
+    public Player defendingChampion() {
         return defendingChampion;
     }
 
+    public void setDefendingChampion(Player champion) {
+        if (champion != null && defendingChampionId == champion.playerId()) {
+            defendingChampion = champion;
+        }
+    }
+
     @Override
-    public int previousEdition() {
+    public int previousEditionId() {
+        return previousEditionId;
+    }
+
+    @Override
+    public Event previousEdition() {
         return previousEdition;
     }
 
+    public void setPreviousEdition(Event event) {
+        if (event != null && previousEditionId == event.eventId()) {
+            previousEdition = event;
+        }
+    }
+
     @Override
     public int getId() {
         return eventId;