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;
20 import java.util.Date;
22 import com.google.gson.annotations.Expose;
23 import com.google.gson.annotations.SerializedName;
25 import org.hedgecode.snooker.SnookerURLUtils;
26 import org.hedgecode.snooker.annotation.IsURL;
27 import org.hedgecode.snooker.api.APIException;
28 import org.hedgecode.snooker.api.Player;
29 import org.hedgecode.snooker.api.PlayerImage;
32 * Player Entity to JSON deserialize.
34 * @author Dmitry Samoshin aka gotty
36 public class JsonPlayer extends JsonIdEntity implements Player {
40 @SerializedName("Type")
42 @SerializedName("FirstName")
43 private String firstName;
44 @SerializedName("MiddleName")
45 private String middleName;
46 @SerializedName("LastName")
47 private String lastName;
48 @SerializedName("TeamName")
49 private String teamName;
50 @SerializedName("TeamNumber")
51 private int teamNumber;
52 @SerializedName("TeamSeason")
53 private int teamSeason;
54 @SerializedName("ShortName")
55 private String shortName;
57 private String fullName;
58 @SerializedName("Nationality")
59 private String nationality;
60 @SerializedName("Sex")
63 @SerializedName("BioPage")
64 private String bioPage;
65 @SerializedName("Born")
67 @SerializedName("Twitter")
68 private String twitter;
69 @SerializedName("SurnameFirst")
70 private boolean surnameFirst;
71 @SerializedName("License")
72 private String license;
73 @SerializedName("Club")
76 @SerializedName("URL")
79 @SerializedName("Photo")
82 private PlayerImage image;
84 @SerializedName("PhotoSource")
85 private String photoSource;
86 @SerializedName("FirstSeasonAsPro")
87 private int firstSeasonAsPro;
88 @SerializedName("LastSeasonAsPro")
89 private int lastSeasonAsPro;
90 @SerializedName("Info")
93 protected JsonPlayer() {
97 public int playerId() {
107 public String firstName() {
112 public String middleName() {
117 public String lastName() {
122 public String teamName() {
127 public int teamNumber() {
132 public int teamSeason() {
137 public String shortName() {
142 public String fullName() {
143 if (fullName == null) {
144 fullName = String.format(
146 surnameFirst ? lastName : firstName,
148 surnameFirst ? firstName : lastName
149 ).replaceAll("\\s+", " ").trim();
155 public String nationality() {
160 public String sex() {
165 public String bioPage() {
173 : new Date(born.getTime());
177 public String twitter() {
183 public String twitterUrl() {
184 return SnookerURLUtils.twitterUrl(twitter);
188 public boolean surnameFirst() {
193 public String license() {
198 public String club() {
203 public String url() {
208 public String photo() {
213 public PlayerImage image() throws APIException {
215 URL imageUrl = SnookerURLUtils.assignUrl(photo);
216 if (imageUrl != null) {
217 image = new PlayerImage(imageUrl, false);
224 public String photoSource() {
229 public int firstSeasonAsPro() {
230 return firstSeasonAsPro;
234 public int lastSeasonAsPro() {
235 return lastSeasonAsPro;
239 public String info() {