[LIB-10] SerialVersionUID for Serializable classes
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonEvent.java
1 /*
2  * Copyright (c) 2017-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.snooker.json;
18
19 import java.io.Serializable;
20 import java.util.Date;
21
22 import com.google.gson.annotations.Expose;
23 import com.google.gson.annotations.SerializedName;
24
25 import org.hedgecode.snooker.SnookerURLUtils;
26 import org.hedgecode.snooker.annotation.IsURL;
27 import org.hedgecode.snooker.annotation.WithHTMLTags;
28 import org.hedgecode.snooker.api.Event;
29 import org.hedgecode.snooker.api.EventFormat;
30 import org.hedgecode.snooker.api.Player;
31 import org.hedgecode.snooker.api.Season;
32
33 /**
34  * Event Entity to JSON deserialize.
35  *
36  * @author Dmitry Samoshin aka gotty
37  */
38 public class JsonEvent extends JsonIdEntity implements Event, Serializable {
39
40     private static final long serialVersionUID = 3074418501643772690L;
41
42     @SerializedName("ID")
43     private int eventId;
44     @SerializedName("Name")
45     private String name;
46     @SerializedName("StartDate")
47     private Date startDate;
48     @SerializedName("EndDate")
49     private Date endDate;
50     @SerializedName("Sponsor")
51     private String sponsor;
52     @SerializedName("Season")
53     private int seasonYear;
54     @Expose
55     private Season season;
56     @SerializedName("Type")
57     private String type;
58     @SerializedName("Num")
59     private int num;
60     @SerializedName("Venue")
61     private String venue;
62     @SerializedName("City")
63     private String city;
64     @SerializedName("Country")
65     private String country;
66     @SerializedName("Discipline")
67     private String discipline;
68     @SerializedName("Main")
69     private int mainEventId;
70     @Expose
71     private Event mainEvent;
72     @SerializedName("Sex")
73     private String sex;
74     @SerializedName("AgeGroup")
75     private String ageGroup;
76     @IsURL
77     @SerializedName("Url")
78     private String url;
79     @SerializedName("Related")
80     private String related;
81     @SerializedName("Stage")
82     private String stage;
83     @SerializedName("ValueType")
84     private String valueType;
85     @SerializedName("ShortName")
86     private String shortName;
87     @SerializedName("WorldSnookerId")
88     private int worldSnookerId;
89     @SerializedName("RankingType")
90     private String rankingType;
91     @SerializedName("EventPredictionID")
92     private int eventPredictionId;
93     @SerializedName("Team")
94     private boolean team;
95     @SerializedName("Format")
96     private int format;
97     @Expose
98     private EventFormat formatType;
99     @SerializedName("Twitter")
100     private String twitter;
101     @SerializedName("HashTag")
102     private String hashTag;
103     @SerializedName("ConversionRate")
104     private float conversionRate;
105     @SerializedName("AllRoundsAdded")
106     private boolean allRoundsAdded;
107     @IsURL
108     @SerializedName("PhotoURLs")
109     private String photoUrls;
110     @SerializedName("NumCompetitors")
111     private int numCompetitors;
112     @SerializedName("NumUpcoming")
113     private int numUpcoming;
114     @SerializedName("NumActive")
115     private int numActive;
116     @SerializedName("NumResults")
117     private int numResults;
118     @WithHTMLTags
119     @SerializedName("Note")
120     private String note;
121     @WithHTMLTags
122     @SerializedName("CommonNote")
123     private String commonNote;
124     @SerializedName("DefendingChampion")
125     private int defendingChampionId;
126     @Expose
127     private Player defendingChampion;
128     @SerializedName("PreviousEdition")
129     private int previousEditionId;
130     @Expose
131     private Event previousEdition;
132
133     JsonEvent() {
134     }
135
136     @Override
137     public int eventId() {
138         return eventId;
139     }
140
141     @Override
142     public String name() {
143         return name;
144     }
145
146     @Override
147     public Date startDate() {
148         return startDate == null
149                 ? null
150                 : new Date(startDate.getTime());
151     }
152
153     @Override
154     public Date endDate() {
155         return endDate == null
156                 ? null
157                 : new Date(endDate.getTime());
158     }
159
160     @Override
161     public String sponsor() {
162         return sponsor;
163     }
164
165     @Override
166     public Season season() {
167         if (season == null)
168             season = Season.getSeason(seasonYear);
169         return season;
170     }
171
172     @Override
173     public String type() {
174         return type;
175     }
176
177     @Override
178     public int num() {
179         return num;
180     }
181
182     @Override
183     public String venue() {
184         return venue;
185     }
186
187     @Override
188     public String city() {
189         return city;
190     }
191
192     @Override
193     public String country() {
194         return country;
195     }
196
197     @Override
198     public String discipline() {
199         return discipline;
200     }
201
202     @Override
203     public int mainEventId() {
204         return mainEventId;
205     }
206
207     @Override
208     public Event mainEvent() {
209         if (mainEvent == null && mainEventId == eventId) {
210             mainEvent = this;
211         }
212         return mainEvent;
213     }
214
215     public void setMainEvent(Event event) {
216         if (event != null && eventId == event.eventId()) {
217             mainEvent = event;
218         }
219     }
220
221     @Override
222     public String sex() {
223         return sex;
224     }
225
226     @Override
227     public String ageGroup() {
228         return ageGroup;
229     }
230
231     @Override
232     public String url() {
233         return url;
234     }
235
236     @Override
237     public String related() {
238         return related;
239     }
240
241     @Override
242     public String stage() {
243         return stage;
244     }
245
246     @Override
247     public String valueType() {
248         return valueType;
249     }
250
251     @Override
252     public String shortName() {
253         return shortName;
254     }
255
256     @Override
257     public int worldSnookerId() {
258         return worldSnookerId;
259     }
260
261     @Override
262     public String rankingType() {
263         return rankingType;
264     }
265
266     @Override
267     public int eventPredictionId() {
268         return eventPredictionId;
269     }
270
271     @Override
272     public boolean team() {
273         return team;
274     }
275
276     @Override
277     public int format() {
278         return format;
279     }
280
281     @Override
282     public EventFormat formatType() {
283         if (formatType == null)
284             formatType = EventFormat.byNumber(format);
285         return formatType;
286     }
287
288     @Override
289     public String twitter() {
290         return twitter;
291     }
292
293     @IsURL
294     @Override
295     public String twitterUrl() {
296         return SnookerURLUtils.twitterUrl(twitter);
297     }
298
299     @Override
300     public String hashTag() {
301         return hashTag;
302     }
303
304     @IsURL
305     @Override
306     public String hashTagUrl() {
307         return SnookerURLUtils.hashtagUrl(hashTag);
308     }
309
310     @Override
311     public float conversionRate() {
312         return conversionRate;
313     }
314
315     @Override
316     public boolean allRoundsAdded() {
317         return allRoundsAdded;
318     }
319
320     @Override
321     public String photoUrls() {
322         return photoUrls;
323     }
324
325     @Override
326     public int numCompetitors() {
327         return numCompetitors;
328     }
329
330     @Override
331     public int numUpcoming() {
332         return numUpcoming;
333     }
334
335     @Override
336     public int numActive() {
337         return numActive;
338     }
339
340     @Override
341     public int numResults() {
342         return numResults;
343     }
344
345     @Override
346     public String note() {
347         return note;
348     }
349
350     @Override
351     public String commonNote() {
352         return commonNote;
353     }
354
355     @Override
356     public int defendingChampionId() {
357         return defendingChampionId;
358     }
359
360     @Override
361     public Player defendingChampion() {
362         return defendingChampion;
363     }
364
365     public void setDefendingChampion(Player champion) {
366         if (champion != null && defendingChampionId == champion.playerId()) {
367             defendingChampion = champion;
368         }
369     }
370
371     @Override
372     public int previousEditionId() {
373         return previousEditionId;
374     }
375
376     @Override
377     public Event previousEdition() {
378         return previousEdition;
379     }
380
381     public void setPreviousEdition(Event event) {
382         if (event != null && previousEditionId == event.eventId()) {
383             previousEdition = event;
384         }
385     }
386
387     @Override
388     public int getId() {
389         return eventId;
390     }
391
392 }