2 * Copyright (c) 2017-2020. 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;
19 import java.io.Serializable;
21 import java.util.Date;
23 import com.google.gson.annotations.Expose;
24 import com.google.gson.annotations.SerializedName;
26 import org.hedgecode.snooker.SnookerURLUtils;
27 import org.hedgecode.snooker.annotation.IsURL;
28 import org.hedgecode.snooker.api.APIException;
29 import org.hedgecode.snooker.api.Player;
30 import org.hedgecode.snooker.api.PlayerImage;
33 * Player Entity to JSON deserialize.
35 * @author Dmitry Samoshin aka gotty
37 public class JsonPlayer extends JsonIdEntity implements Player, Serializable {
39 private static final long serialVersionUID = 5978347071162091429L;
43 @SerializedName("Type")
45 @SerializedName("FirstName")
46 private String firstName;
47 @SerializedName("MiddleName")
48 private String middleName;
49 @SerializedName("LastName")
50 private String lastName;
51 @SerializedName("TeamName")
52 private String teamName;
53 @SerializedName("TeamNumber")
54 private int teamNumber;
55 @SerializedName("TeamSeason")
56 private int teamSeason;
57 @SerializedName("ShortName")
58 private String shortName;
60 private String fullName;
61 @SerializedName("Nationality")
62 private String nationality;
63 @SerializedName("Sex")
66 @SerializedName("BioPage")
67 private String bioPage;
68 @SerializedName("Born")
70 @SerializedName("Twitter")
71 private String twitter;
72 @SerializedName("SurnameFirst")
73 private boolean surnameFirst;
74 @SerializedName("License")
75 private String license;
76 @SerializedName("Club")
79 @SerializedName("URL")
82 @SerializedName("Photo")
85 private PlayerImage image;
87 @SerializedName("PhotoSource")
88 private String photoSource;
89 @SerializedName("FirstSeasonAsPro")
90 private int firstSeasonAsPro;
91 @SerializedName("LastSeasonAsPro")
92 private int lastSeasonAsPro;
93 @SerializedName("Info")
100 public int playerId() {
110 public String firstName() {
115 public String middleName() {
120 public String lastName() {
125 public String teamName() {
130 public int teamNumber() {
135 public int teamSeason() {
140 public String shortName() {
145 public String fullName() {
146 if (fullName == null) {
147 fullName = String.format(
149 surnameFirst ? lastName : firstName,
151 surnameFirst ? firstName : lastName
152 ).replaceAll("\\s+", " ").trim();
158 public String nationality() {
163 public String sex() {
168 public String bioPage() {
176 : new Date(born.getTime());
180 public String twitter() {
186 public String twitterUrl() {
187 return SnookerURLUtils.twitterUrl(twitter);
191 public boolean surnameFirst() {
196 public String license() {
201 public String club() {
206 public String url() {
211 public String photo() {
216 public PlayerImage image() throws APIException {
218 URL imageUrl = SnookerURLUtils.assignUrl(photo);
219 if (imageUrl != null) {
220 image = new PlayerImage(imageUrl, false);
227 public String photoSource() {
232 public int firstSeasonAsPro() {
233 return firstSeasonAsPro;
237 public int lastSeasonAsPro() {
238 return lastSeasonAsPro;
242 public String info() {