0ba62ab7f3f67c6cd253d327ebbb751dda695711
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonEvent.java
1 /*
2  * Copyright (c) 2017. 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.util.Date;
20
21 import com.google.gson.annotations.Expose;
22 import com.google.gson.annotations.SerializedName;
23
24 import org.hedgecode.snooker.api.Event;
25 import org.hedgecode.snooker.api.EventFormat;
26 import org.hedgecode.snooker.api.Season;
27
28 /**
29  * Event Entity to JSON deserialize.
30  *
31  * @author Dmitry Samoshin aka gotty
32  */
33 public class JsonEvent extends JsonIdEntity implements Event {
34
35     @SerializedName("ID")
36     private int eventId;
37     @SerializedName("Name")
38     private String name;
39     @SerializedName("StartDate")
40     private Date startDate;
41     @SerializedName("EndDate")
42     private Date endDate;
43     @SerializedName("Sponsor")
44     private String sponsor;
45     @SerializedName("Season")
46     private int seasonYear;
47     @Expose
48     private Season season;
49     @SerializedName("Type")
50     private String type;
51     @SerializedName("Num")
52     private int num;
53     @SerializedName("Venue")
54     private String venue;
55     @SerializedName("City")
56     private String city;
57     @SerializedName("Country")
58     private String country;
59     @SerializedName("Discipline")
60     private String discipline;
61     @SerializedName("Main")
62     private int mainEventId;
63     @Expose
64     private Event mainEvent;
65     @SerializedName("Sex")
66     private String sex;
67     @SerializedName("AgeGroup")
68     private String ageGroup;
69     @SerializedName("Url")
70     private String url;
71     @SerializedName("Related")
72     private String related;
73     @SerializedName("Stage")
74     private String stage;
75     @SerializedName("ValueType")
76     private String valueType;
77     @SerializedName("ShortName")
78     private String shortName;
79     @SerializedName("WorldSnookerId")
80     private int worldSnookerId;
81     @SerializedName("RankingType")
82     private String rankingType;
83     @SerializedName("EventPredictionID")
84     private int eventPredictionId;
85     @SerializedName("Team")
86     private boolean team;
87     @SerializedName("Format")
88     private int format;
89     @Expose
90     private EventFormat formatType;
91     @SerializedName("Twitter")
92     private String twitter;
93     @SerializedName("HashTag")
94     private String hashTag;
95     @SerializedName("ConversionRate")
96     private float conversionRate;
97     @SerializedName("AllRoundsAdded")
98     private boolean allRoundsAdded;
99     @SerializedName("PhotoURLs")
100     private String photoUrls;
101     @SerializedName("NumCompetitors")
102     private int numCompetitors;
103     @SerializedName("NumUpcoming")
104     private int numUpcoming;
105     @SerializedName("NumActive")
106     private int numActive;
107     @SerializedName("NumResults")
108     private int numResults;
109     @SerializedName("Note")
110     private String note;
111     @SerializedName("CommonNote")
112     private String commonNote;
113     @SerializedName("DefendingChampion")
114     private int defendingChampion;
115     @SerializedName("PreviousEdition")
116     private int previousEdition;
117
118     protected JsonEvent() {
119     }
120
121     @Override
122     public int eventId() {
123         return eventId;
124     }
125
126     @Override
127     public String name() {
128         return name;
129     }
130
131     @Override
132     public Date startDate() {
133         return startDate == null
134                 ? null
135                 : new Date(startDate.getTime());
136     }
137
138     @Override
139     public Date endDate() {
140         return endDate == null
141                 ? null
142                 : new Date(endDate.getTime());
143     }
144
145     @Override
146     public String sponsor() {
147         return sponsor;
148     }
149
150     @Override
151     public Season season() {
152         if (season == null)
153             season = Season.getSeason(seasonYear);
154         return season;
155     }
156
157     @Override
158     public String type() {
159         return type;
160     }
161
162     @Override
163     public int num() {
164         return num;
165     }
166
167     @Override
168     public String venue() {
169         return venue;
170     }
171
172     @Override
173     public String city() {
174         return city;
175     }
176
177     @Override
178     public String country() {
179         return country;
180     }
181
182     @Override
183     public String discipline() {
184         return discipline;
185     }
186
187     @Override
188     public int mainEventId() {
189         return mainEventId;
190     }
191
192     @Override
193     public Event mainEvent() {
194         if (mainEvent == null && mainEventId == eventId)
195             mainEvent = this;
196         return mainEvent;
197     }
198
199     public void setMainEvent(Event event) {
200         if (event != null && eventId == event.eventId())
201             mainEvent = event;
202     }
203
204     @Override
205     public String sex() {
206         return sex;
207     }
208
209     @Override
210     public String ageGroup() {
211         return ageGroup;
212     }
213
214     @Override
215     public String url() {
216         return url;
217     }
218
219     @Override
220     public String related() {
221         return related;
222     }
223
224     @Override
225     public String stage() {
226         return stage;
227     }
228
229     @Override
230     public String valueType() {
231         return valueType;
232     }
233
234     @Override
235     public String shortName() {
236         return shortName;
237     }
238
239     @Override
240     public int worldSnookerId() {
241         return worldSnookerId;
242     }
243
244     @Override
245     public String rankingType() {
246         return rankingType;
247     }
248
249     @Override
250     public int eventPredictionId() {
251         return eventPredictionId;
252     }
253
254     @Override
255     public boolean team() {
256         return team;
257     }
258
259     @Override
260     public int format() {
261         return format;
262     }
263
264     @Override
265     public EventFormat formatType() {
266         if (formatType == null)
267             formatType = EventFormat.byNumber(format);
268         return formatType;
269     }
270
271     @Override
272     public String twitter() {
273         return twitter;
274     }
275
276     @Override
277     public String hashTag() {
278         return hashTag;
279     }
280
281     @Override
282     public float conversionRate() {
283         return conversionRate;
284     }
285
286     @Override
287     public boolean allRoundsAdded() {
288         return allRoundsAdded;
289     }
290
291     @Override
292     public String photoUrls() {
293         return photoUrls;
294     }
295
296     @Override
297     public int numCompetitors() {
298         return numCompetitors;
299     }
300
301     @Override
302     public int numUpcoming() {
303         return numUpcoming;
304     }
305
306     @Override
307     public int numActive() {
308         return numActive;
309     }
310
311     @Override
312     public int numResults() {
313         return numResults;
314     }
315
316     @Override
317     public String note() {
318         return note;
319     }
320
321     @Override
322     public String commonNote() {
323         return commonNote;
324     }
325
326     @Override
327     public int defendingChampion() {
328         return defendingChampion;
329     }
330
331     @Override
332     public int previousEdition() {
333         return previousEdition;
334     }
335
336     @Override
337     public int getId() {
338         return eventId;
339     }
340
341 }