2 * Copyright (c) 2017-2020. Developed by Hedgecode.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.hedgecode.snooker.json;
19 import java.io.Serializable;
20 import java.util.Date;
22 import com.google.gson.annotations.Expose;
23 import com.google.gson.annotations.SerializedName;
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;
34 * Event Entity to JSON deserialize.
36 * @author Dmitry Samoshin aka gotty
38 public class JsonEvent extends JsonIdEntity implements Event, Serializable {
40 private static final long serialVersionUID = 3074418501643772690L;
44 @SerializedName("Name")
46 @SerializedName("StartDate")
47 private Date startDate;
48 @SerializedName("EndDate")
50 @SerializedName("Sponsor")
51 private String sponsor;
52 @SerializedName("Season")
53 private int seasonYear;
55 private Season season;
56 @SerializedName("Type")
58 @SerializedName("Num")
60 @SerializedName("Venue")
62 @SerializedName("City")
64 @SerializedName("Country")
65 private String country;
66 @SerializedName("Discipline")
67 private String discipline;
68 @SerializedName("Main")
69 private int mainEventId;
71 private Event mainEvent;
72 @SerializedName("Sex")
74 @SerializedName("AgeGroup")
75 private String ageGroup;
77 @SerializedName("Url")
79 @SerializedName("Related")
80 private String related;
81 @SerializedName("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")
95 @SerializedName("Format")
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;
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;
119 @SerializedName("Note")
122 @SerializedName("CommonNote")
123 private String commonNote;
124 @SerializedName("DefendingChampion")
125 private int defendingChampionId;
127 private Player defendingChampion;
128 @SerializedName("PreviousEdition")
129 private int previousEditionId;
131 private Event previousEdition;
137 public int eventId() {
142 public String name() {
147 public Date startDate() {
148 return startDate == null
150 : new Date(startDate.getTime());
154 public Date endDate() {
155 return endDate == null
157 : new Date(endDate.getTime());
161 public String sponsor() {
166 public Season season() {
168 season = Season.getSeason(seasonYear);
173 public String type() {
183 public String venue() {
188 public String city() {
193 public String country() {
198 public String discipline() {
203 public int mainEventId() {
208 public Event mainEvent() {
209 if (mainEvent == null && mainEventId == eventId) {
215 public void setMainEvent(Event event) {
216 if (event != null && eventId == event.eventId()) {
222 public String sex() {
227 public String ageGroup() {
232 public String url() {
237 public String related() {
242 public String stage() {
247 public String valueType() {
252 public String shortName() {
257 public int worldSnookerId() {
258 return worldSnookerId;
262 public String rankingType() {
267 public int eventPredictionId() {
268 return eventPredictionId;
272 public boolean team() {
277 public int format() {
282 public EventFormat formatType() {
283 if (formatType == null)
284 formatType = EventFormat.byNumber(format);
289 public String twitter() {
295 public String twitterUrl() {
296 return SnookerURLUtils.twitterUrl(twitter);
300 public String hashTag() {
306 public String hashTagUrl() {
307 return SnookerURLUtils.hashtagUrl(hashTag);
311 public float conversionRate() {
312 return conversionRate;
316 public boolean allRoundsAdded() {
317 return allRoundsAdded;
321 public String photoUrls() {
326 public int numCompetitors() {
327 return numCompetitors;
331 public int numUpcoming() {
336 public int numActive() {
341 public int numResults() {
346 public String note() {
351 public String commonNote() {
356 public int defendingChampionId() {
357 return defendingChampionId;
361 public Player defendingChampion() {
362 return defendingChampion;
365 public void setDefendingChampion(Player champion) {
366 if (champion != null && defendingChampionId == champion.playerId()) {
367 defendingChampion = champion;
372 public int previousEditionId() {
373 return previousEditionId;
377 public Event previousEdition() {
378 return previousEdition;
381 public void setPreviousEdition(Event event) {
382 if (event != null && previousEditionId == event.eventId()) {
383 previousEdition = event;