/*
- * 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.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.annotation.WithHTMLTags;
import org.hedgecode.snooker.api.Event;
+import org.hedgecode.snooker.api.EventFormat;
+import org.hedgecode.snooker.api.Player;
import org.hedgecode.snooker.api.Season;
/**
*
* @author Dmitry Samoshin aka gotty
*/
-public class JsonEvent extends JsonIdEntity implements Event {
+public class JsonEvent extends JsonIdEntity implements Event, Serializable {
+
+ private static final long serialVersionUID = 3074418501643772690L;
@SerializedName("ID")
private int eventId;
private String sex;
@SerializedName("AgeGroup")
private String ageGroup;
+ @IsURL
@SerializedName("Url")
private String url;
@SerializedName("Related")
private boolean team;
@SerializedName("Format")
private int format;
+ @Expose
+ private EventFormat formatType;
@SerializedName("Twitter")
private String twitter;
@SerializedName("HashTag")
private float conversionRate;
@SerializedName("AllRoundsAdded")
private boolean allRoundsAdded;
+ @IsURL
@SerializedName("PhotoURLs")
private String photoUrls;
@SerializedName("NumCompetitors")
private int numActive;
@SerializedName("NumResults")
private int numResults;
+ @WithHTMLTags
@SerializedName("Note")
private String note;
+ @WithHTMLTags
@SerializedName("CommonNote")
private String commonNote;
@SerializedName("DefendingChampion")
- private int defendingChampion;
+ private int defendingChampionId;
+ @Expose
+ private Player defendingChampion;
@SerializedName("PreviousEdition")
- private int previousEdition;
+ private int previousEditionId;
+ @Expose
+ private Event previousEdition;
+
+ JsonEvent() {
+ }
@Override
public int eventId() {
@Override
public Date startDate() {
- return startDate;
+ return startDate == null
+ ? null
+ : new Date(startDate.getTime());
}
@Override
public Date endDate() {
- return endDate;
+ return endDate == null
+ ? null
+ : new Date(endDate.getTime());
}
@Override
@Override
public Event mainEvent() {
- if (mainEvent == null && mainEventId == eventId)
+ if (mainEvent == null && mainEventId == eventId) {
mainEvent = this;
+ }
return mainEvent;
}
public void setMainEvent(Event event) {
- if (event != null && eventId == event.eventId())
+ if (event != null && eventId == event.eventId()) {
mainEvent = event;
+ }
}
@Override
}
@Override
+ public EventFormat formatType() {
+ if (formatType == null)
+ formatType = EventFormat.byNumber(format);
+ return formatType;
+ }
+
+ @Override
public String twitter() {
return twitter;
}
+ @IsURL
+ @Override
+ public String twitterUrl() {
+ return SnookerURLUtils.twitterUrl(twitter);
+ }
+
@Override
public String hashTag() {
return hashTag;
}
+ @IsURL
+ @Override
+ public String hashTagUrl() {
+ return SnookerURLUtils.hashtagUrl(hashTag);
+ }
+
@Override
public float conversionRate() {
return conversionRate;
}
@Override
- public int defendingChampion() {
+ public int defendingChampionId() {
+ return defendingChampionId;
+ }
+
+ @Override
+ public Player defendingChampion() {
return defendingChampion;
}
+ public void setDefendingChampion(Player champion) {
+ if (champion != null && defendingChampionId == champion.playerId()) {
+ defendingChampion = champion;
+ }
+ }
+
+ @Override
+ public int previousEditionId() {
+ return previousEditionId;
+ }
+
@Override
- public int previousEdition() {
+ public Event previousEdition() {
return previousEdition;
}
+ public void setPreviousEdition(Event event) {
+ if (event != null && previousEditionId == event.eventId()) {
+ previousEdition = event;
+ }
+ }
+
@Override
public int getId() {
return eventId;