/*
- * Copyright (c) 2017. Developed by Hedgecode.
+ * Copyright (c) 2017-2020. Developed by Hedgecode.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.hedgecode.snooker.json;
+import java.io.Serializable;
+import java.net.URL;
import java.util.Date;
+import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
+import org.hedgecode.snooker.SnookerURLUtils;
+import org.hedgecode.snooker.annotation.IsURL;
+import org.hedgecode.snooker.api.APIException;
import org.hedgecode.snooker.api.Player;
+import org.hedgecode.snooker.api.PlayerImage;
/**
* Player Entity to JSON deserialize.
*
* @author Dmitry Samoshin aka gotty
*/
-public class JsonPlayer extends JsonIdEntity implements Player {
+public class JsonPlayer extends JsonIdEntity implements Player, Serializable {
+
+ private static final long serialVersionUID = 5978347071162091429L;
@SerializedName("ID")
private int playerId;
private int teamSeason;
@SerializedName("ShortName")
private String shortName;
+ @Expose
+ private String fullName;
@SerializedName("Nationality")
private String nationality;
@SerializedName("Sex")
private String sex;
+ @IsURL
@SerializedName("BioPage")
private String bioPage;
@SerializedName("Born")
private String license;
@SerializedName("Club")
private String club;
+ @IsURL
@SerializedName("URL")
private String url;
+ @IsURL
@SerializedName("Photo")
private String photo;
+ @Expose
+ private PlayerImage image;
+ @IsURL
+ @SerializedName("PhotoSource")
+ private String photoSource;
+ @SerializedName("FirstSeasonAsPro")
+ private int firstSeasonAsPro;
+ @SerializedName("LastSeasonAsPro")
+ private int lastSeasonAsPro;
@SerializedName("Info")
private String info;
+ JsonPlayer() {
+ }
+
@Override
public int playerId() {
return playerId;
}
@Override
+ public String fullName() {
+ if (fullName == null) {
+ fullName = String.format(
+ "%s %s %s",
+ surnameFirst ? lastName : firstName,
+ middleName,
+ surnameFirst ? firstName : lastName
+ ).replaceAll("\\s+", " ").trim();
+ }
+ return fullName;
+ }
+
+ @Override
public String nationality() {
return nationality;
}
@Override
public Date born() {
- return born;
+ return born == null
+ ? null
+ : new Date(born.getTime());
}
@Override
return twitter;
}
+ @IsURL
+ @Override
+ public String twitterUrl() {
+ return SnookerURLUtils.twitterUrl(twitter);
+ }
+
@Override
public boolean surnameFirst() {
return surnameFirst;
}
@Override
+ public PlayerImage image() throws APIException {
+ if (image == null) {
+ URL imageUrl = SnookerURLUtils.assignUrl(photo);
+ if (imageUrl != null) {
+ image = new PlayerImage(imageUrl, false);
+ }
+ }
+ return image;
+ }
+
+ @Override
+ public String photoSource() {
+ return photoSource;
+ }
+
+ @Override
+ public int firstSeasonAsPro() {
+ return firstSeasonAsPro;
+ }
+
+ @Override
+ public int lastSeasonAsPro() {
+ return lastSeasonAsPro;
+ }
+
+ @Override
public String info() {
return info;
}