[LIB-10] SerialVersionUID for Serializable classes
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonRanking.java
1 /*
2  * Copyright (c) 2017-2020. 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.io.Serializable;
20
21 import com.google.gson.annotations.Expose;
22 import com.google.gson.annotations.SerializedName;
23
24 import org.hedgecode.snooker.api.Player;
25 import org.hedgecode.snooker.api.Ranking;
26 import org.hedgecode.snooker.api.RankingType;
27 import org.hedgecode.snooker.api.Season;
28
29 /**
30  * Ranking Entity to JSON deserialize.
31  *
32  * @author Dmitry Samoshin aka gotty
33  */
34 public class JsonRanking extends JsonIdEntity implements Ranking, Serializable {
35
36     private static final long serialVersionUID = -8009582917499815478L;
37
38     @SerializedName("ID")
39     private int rankingId;
40     @SerializedName("Position")
41     private int position;
42     @SerializedName("PlayerID")
43     private int playerId;
44     @Expose
45     private Player player;
46     @SerializedName("Season")
47     private int seasonYear;
48     @Expose
49     private Season season;
50     @SerializedName("Sum")
51     private long sum;
52     @SerializedName("Type")
53     private String type;
54     @Expose
55     private RankingType rankingType;
56
57     JsonRanking() {
58     }
59
60     @Override
61     public int rankingId() {
62         return rankingId;
63     }
64
65     @Override
66     public int position() {
67         return position;
68     }
69
70     @Override
71     public int playerId() {
72         return playerId;
73     }
74
75     @Override
76     public Player player() {
77         return player;
78     }
79
80     public void setPlayer(Player player) {
81         if (player != null && playerId == player.playerId())
82             this.player = player;
83     }
84
85     @Override
86     public Season season() {
87         if (season == null)
88             season = Season.getSeason(seasonYear);
89         return season;
90     }
91
92     @Override
93     public long sum() {
94         return sum;
95     }
96
97     @Override
98     public RankingType rankingType() {
99         if (rankingType == null)
100             rankingType = RankingType.byName(type);
101         return rankingType;
102     }
103
104     @Override
105     public int getId() {
106         return rankingId;
107     }
108
109 }