[LIB-8] URL and HTML tag processing, new entities fields
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonMatch.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.annotation.IsURL;
25 import org.hedgecode.snooker.annotation.WithHTMLTags;
26 import org.hedgecode.snooker.api.Event;
27 import org.hedgecode.snooker.api.Match;
28 import org.hedgecode.snooker.api.Player;
29
30 /**
31  * Match Entity to JSON deserialize.
32  *
33  * @author Dmitry Samoshin aka gotty
34  */
35 public class JsonMatch extends JsonIdEntity implements Match {
36
37     @SerializedName("ID")
38     private int matchId;
39     @SerializedName("EventID")
40     private int eventId;
41     @Expose
42     private Event event;
43     @SerializedName("Round")
44     private int round;
45     @SerializedName("Number")
46     private int number;
47     @SerializedName("Player1ID")
48     private int player1Id;
49     @Expose
50     private Player player1;
51     @SerializedName("Score1")
52     private int score1;
53     @SerializedName("Walkover1")
54     private boolean walkover1;
55     @SerializedName("Player2ID")
56     private int player2Id;
57     @Expose
58     private Player player2;
59     @SerializedName("Score2")
60     private int score2;
61     @SerializedName("Walkover2")
62     private boolean walkover2;
63     @SerializedName("WinnerID")
64     private int winnerId;
65     @Expose
66     private Player winner;
67     @SerializedName("Unfinished")
68     private boolean unfinished;
69     @SerializedName("OnBreak")
70     private boolean onBreak;
71     @SerializedName("WorldSnookerID")
72     private int worldSnookerId;
73     @IsURL
74     @SerializedName("LiveUrl")
75     private String liveUrl;
76     @IsURL
77     @SerializedName("DetailsUrl")
78     private String detailsUrl;
79     @SerializedName("PointsDropped")
80     private boolean pointsDropped;
81     @SerializedName("ShowCommonNote")
82     private boolean showCommonNote;
83     @SerializedName("Estimated")
84     private boolean estimated;
85     @SerializedName("Type")
86     private int type;
87     @SerializedName("TableNo")
88     private int tableNo;
89     @IsURL
90     @SerializedName("VideoURL")
91     private String videoUrl;
92     @SerializedName("InitDate")
93     private Date initDate;
94     @SerializedName("ModDate")
95     private Date modDate;
96     @SerializedName("StartDate")
97     private Date startDate;
98     @SerializedName("EndDate")
99     private Date endDate;
100     @SerializedName("ScheduledDate")
101     private Date scheduledDate;
102     @WithHTMLTags
103     @SerializedName("FrameScores")
104     private String frameScores;
105     @WithHTMLTags
106     @SerializedName("Sessions")
107     private String sessions;
108     @WithHTMLTags
109     @SerializedName("Note")
110     private String note;
111     @WithHTMLTags
112     @SerializedName("ExtendedNote")
113     private String extendedNote;
114
115     protected JsonMatch() {
116     }
117
118     @Override
119     public int matchId() {
120         return matchId;
121     }
122
123     @Override
124     public int eventId() {
125         return eventId;
126     }
127
128     @Override
129     public Event event() {
130         return event;
131     }
132
133     public void setEvent(Event event) {
134         if (event != null && eventId == event.eventId())
135             this.event = event;
136     }
137
138     @Override
139     public int round() {
140         return round;
141     }
142
143     @Override
144     public int number() {
145         return number;
146     }
147
148     @Override
149     public int player1Id() {
150         return player1Id;
151     }
152
153     @Override
154     public Player player1() {
155         return player1;
156     }
157
158     public void setPlayer1(Player player) {
159         if (player != null && player1Id == player.playerId())
160             this.player1 = player;
161     }
162
163     @Override
164     public int score1() {
165         return score1;
166     }
167
168     @Override
169     public boolean walkover1() {
170         return walkover1;
171     }
172
173     @Override
174     public int player2Id() {
175         return player2Id;
176     }
177
178     @Override
179     public Player player2() {
180         return player2;
181     }
182
183     public void setPlayer2(Player player) {
184         if (player != null && player2Id == player.playerId())
185             this.player2 = player;
186     }
187
188     @Override
189     public int score2() {
190         return score2;
191     }
192
193     @Override
194     public boolean walkover2() {
195         return walkover2;
196     }
197
198     @Override
199     public int winnerId() {
200         return winnerId;
201     }
202
203     @Override
204     public Player winner() {
205         return winner;
206     }
207
208     public void setWinner(Player winner) {
209         if (winner != null && winnerId == winner.playerId())
210             this.winner = winner;
211     }
212
213     @Override
214     public boolean unfinished() {
215         return unfinished;
216     }
217
218     @Override
219     public boolean onBreak() {
220         return onBreak;
221     }
222
223     @Override
224     public int worldSnookerId() {
225         return worldSnookerId;
226     }
227
228     @Override
229     public String liveUrl() {
230         return liveUrl;
231     }
232
233     @Override
234     public String detailsUrl() {
235         return detailsUrl;
236     }
237
238     @Override
239     public boolean pointsDropped() {
240         return pointsDropped;
241     }
242
243     @Override
244     public boolean showCommonNote() {
245         return showCommonNote;
246     }
247
248     @Override
249     public boolean estimated() {
250         return estimated;
251     }
252
253     @Override
254     public int type() {
255         return type;
256     }
257
258     @Override
259     public int tableNo() {
260         return tableNo;
261     }
262
263     @Override
264     public String videoUrl() {
265         return videoUrl;
266     }
267
268     @Override
269     public Date initDate() {
270         return initDate == null
271                 ? null
272                 : new Date(initDate.getTime());
273     }
274
275     @Override
276     public Date modDate() {
277         return modDate == null
278                 ? null
279                 : new Date(modDate.getTime());
280     }
281
282     @Override
283     public Date startDate() {
284         return startDate == null
285                 ? null
286                 : new Date(startDate.getTime());
287     }
288
289     @Override
290     public Date endDate() {
291         return endDate == null
292                 ? null
293                 : new Date(endDate.getTime());
294     }
295
296     @Override
297     public Date scheduledDate() {
298         return scheduledDate == null
299                 ? null
300                 : new Date(scheduledDate.getTime());
301     }
302
303     @Override
304     public String frameScores() {
305         return frameScores;
306     }
307
308     @Override
309     public String sessions() {
310         return sessions;
311     }
312
313     @Override
314     public String note() {
315         return note;
316     }
317
318     @Override
319     public String extendedNote() {
320         return extendedNote;
321     }
322
323     @Override
324     public int getId() {
325         return matchId;
326     }
327
328 }