[LIB-10] SerialVersionUID for Serializable classes
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonEvent.java
index 2f47ee4..526389f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017. Developed by Hedgecode.
+ * Copyright (c) 2017-2020. Developed by Hedgecode.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.hedgecode.snooker.json;
 
+import java.io.Serializable;
 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;
 
 /**
@@ -29,7 +35,9 @@ import org.hedgecode.snooker.api.Season;
  *
  * @author Dmitry Samoshin aka gotty
  */
-public class JsonEvent extends JsonIdEntity implements Event {
+public class JsonEvent extends JsonIdEntity implements Event, Serializable {
+
+    private static final long serialVersionUID = 3074418501643772690L;
 
     @SerializedName("ID")
     private int eventId;
@@ -65,6 +73,7 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private String sex;
     @SerializedName("AgeGroup")
     private String ageGroup;
+    @IsURL
     @SerializedName("Url")
     private String url;
     @SerializedName("Related")
@@ -85,6 +94,8 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private boolean team;
     @SerializedName("Format")
     private int format;
+    @Expose
+    private EventFormat formatType;
     @SerializedName("Twitter")
     private String twitter;
     @SerializedName("HashTag")
@@ -93,6 +104,7 @@ public class JsonEvent extends JsonIdEntity implements Event {
     private float conversionRate;
     @SerializedName("AllRoundsAdded")
     private boolean allRoundsAdded;
+    @IsURL
     @SerializedName("PhotoURLs")
     private String photoUrls;
     @SerializedName("NumCompetitors")
@@ -103,14 +115,23 @@ 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;
+
+    JsonEvent() {
+    }
 
     @Override
     public int eventId() {
@@ -124,12 +145,16 @@ public class JsonEvent extends JsonIdEntity implements Event {
 
     @Override
     public Date startDate() {
-        return startDate;
+        return startDate == null
+                ? null
+                : new Date(startDate.getTime());
     }
 
     @Override
     public Date endDate() {
-        return endDate;
+        return endDate == null
+                ? null
+                : new Date(endDate.getTime());
     }
 
     @Override
@@ -181,14 +206,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
@@ -252,15 +279,34 @@ public class JsonEvent extends JsonIdEntity implements Event {
     }
 
     @Override
+    public EventFormat formatType() {
+        if (formatType == null)
+            formatType = EventFormat.byNumber(format);
+        return formatType;
+    }
+
+    @Override
     public String twitter() {
         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;
@@ -307,15 +353,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 previousEditionId() {
+        return previousEditionId;
+    }
+
     @Override
-    public int previousEdition() {
+    public Event previousEdition() {
         return previousEdition;
     }
 
+    public void setPreviousEdition(Event event) {
+        if (event != null && previousEditionId == event.eventId()) {
+            previousEdition = event;
+        }
+    }
+
     @Override
     public int getId() {
         return eventId;