2 * Copyright (c) 2017. 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.util.Date;
21 import com.google.gson.annotations.Expose;
22 import com.google.gson.annotations.SerializedName;
24 import org.hedgecode.snooker.SnookerURLUtils;
25 import org.hedgecode.snooker.annotation.IsURL;
26 import org.hedgecode.snooker.annotation.WithHTMLTags;
27 import org.hedgecode.snooker.api.Event;
28 import org.hedgecode.snooker.api.EventFormat;
29 import org.hedgecode.snooker.api.Player;
30 import org.hedgecode.snooker.api.Season;
33 * Event Entity to JSON deserialize.
35 * @author Dmitry Samoshin aka gotty
37 public class JsonEvent extends JsonIdEntity implements Event {
41 @SerializedName("Name")
43 @SerializedName("StartDate")
44 private Date startDate;
45 @SerializedName("EndDate")
47 @SerializedName("Sponsor")
48 private String sponsor;
49 @SerializedName("Season")
50 private int seasonYear;
52 private Season season;
53 @SerializedName("Type")
55 @SerializedName("Num")
57 @SerializedName("Venue")
59 @SerializedName("City")
61 @SerializedName("Country")
62 private String country;
63 @SerializedName("Discipline")
64 private String discipline;
65 @SerializedName("Main")
66 private int mainEventId;
68 private Event mainEvent;
69 @SerializedName("Sex")
71 @SerializedName("AgeGroup")
72 private String ageGroup;
74 @SerializedName("Url")
76 @SerializedName("Related")
77 private String related;
78 @SerializedName("Stage")
80 @SerializedName("ValueType")
81 private String valueType;
82 @SerializedName("ShortName")
83 private String shortName;
84 @SerializedName("WorldSnookerId")
85 private int worldSnookerId;
86 @SerializedName("RankingType")
87 private String rankingType;
88 @SerializedName("EventPredictionID")
89 private int eventPredictionId;
90 @SerializedName("Team")
92 @SerializedName("Format")
95 private EventFormat formatType;
96 @SerializedName("Twitter")
97 private String twitter;
98 @SerializedName("HashTag")
99 private String hashTag;
100 @SerializedName("ConversionRate")
101 private float conversionRate;
102 @SerializedName("AllRoundsAdded")
103 private boolean allRoundsAdded;
105 @SerializedName("PhotoURLs")
106 private String photoUrls;
107 @SerializedName("NumCompetitors")
108 private int numCompetitors;
109 @SerializedName("NumUpcoming")
110 private int numUpcoming;
111 @SerializedName("NumActive")
112 private int numActive;
113 @SerializedName("NumResults")
114 private int numResults;
116 @SerializedName("Note")
119 @SerializedName("CommonNote")
120 private String commonNote;
121 @SerializedName("DefendingChampion")
122 private int defendingChampionId;
124 private Player defendingChampion;
125 @SerializedName("PreviousEdition")
126 private int previousEditionId;
128 private Event previousEdition;
130 protected JsonEvent() {
134 public int eventId() {
139 public String name() {
144 public Date startDate() {
145 return startDate == null
147 : new Date(startDate.getTime());
151 public Date endDate() {
152 return endDate == null
154 : new Date(endDate.getTime());
158 public String sponsor() {
163 public Season season() {
165 season = Season.getSeason(seasonYear);
170 public String type() {
180 public String venue() {
185 public String city() {
190 public String country() {
195 public String discipline() {
200 public int mainEventId() {
205 public Event mainEvent() {
206 if (mainEvent == null && mainEventId == eventId) {
212 public void setMainEvent(Event event) {
213 if (event != null && eventId == event.eventId()) {
219 public String sex() {
224 public String ageGroup() {
229 public String url() {
234 public String related() {
239 public String stage() {
244 public String valueType() {
249 public String shortName() {
254 public int worldSnookerId() {
255 return worldSnookerId;
259 public String rankingType() {
264 public int eventPredictionId() {
265 return eventPredictionId;
269 public boolean team() {
274 public int format() {
279 public EventFormat formatType() {
280 if (formatType == null)
281 formatType = EventFormat.byNumber(format);
286 public String twitter() {
292 public String twitterUrl() {
293 return SnookerURLUtils.twitterUrl(twitter);
297 public String hashTag() {
303 public String hashTagUrl() {
304 return SnookerURLUtils.hashtagUrl(hashTag);
308 public float conversionRate() {
309 return conversionRate;
313 public boolean allRoundsAdded() {
314 return allRoundsAdded;
318 public String photoUrls() {
323 public int numCompetitors() {
324 return numCompetitors;
328 public int numUpcoming() {
333 public int numActive() {
338 public int numResults() {
343 public String note() {
348 public String commonNote() {
353 public int defendingChampionId() {
354 return defendingChampionId;
358 public Player defendingChampion() {
359 return defendingChampion;
362 public void setDefendingChampion(Player champion) {
363 if (champion != null && defendingChampionId == champion.playerId()) {
364 defendingChampion = champion;
369 public int previousEditionId() {
370 return previousEditionId;
374 public Event previousEdition() {
375 return previousEdition;
378 public void setPreviousEdition(Event event) {
379 if (event != null && previousEditionId == event.eventId()) {
380 previousEdition = event;