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