[LIB-5] Collection empty objects,reporting and serializable
authorgotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Tue, 24 Jan 2017 23:19:57 +0000 (23:19 +0000)
committergotty <gotty@fb0bcced-7025-49ed-a12f-f98bce993226>
Tue, 24 Jan 2017 23:19:57 +0000 (23:19 +0000)
git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@102 fb0bcced-7025-49ed-a12f-f98bce993226

21 files changed:
pom.xml
src/main/java/org/hedgecode/snooker/SnookerScoreApp.java
src/main/java/org/hedgecode/snooker/api/Season.java
src/main/java/org/hedgecode/snooker/compare/EventComparators.java
src/main/java/org/hedgecode/snooker/compare/MatchComparators.java
src/main/java/org/hedgecode/snooker/compare/PlayerComparators.java
src/main/java/org/hedgecode/snooker/compare/RankingComparators.java
src/main/java/org/hedgecode/snooker/json/JsonCollectionEntity.java
src/main/java/org/hedgecode/snooker/json/JsonEvent.java
src/main/java/org/hedgecode/snooker/json/JsonEvents.java
src/main/java/org/hedgecode/snooker/json/JsonIdEntity.java
src/main/java/org/hedgecode/snooker/json/JsonMatch.java
src/main/java/org/hedgecode/snooker/json/JsonMatches.java
src/main/java/org/hedgecode/snooker/json/JsonOngoingMatch.java
src/main/java/org/hedgecode/snooker/json/JsonPlayer.java
src/main/java/org/hedgecode/snooker/json/JsonPlayers.java
src/main/java/org/hedgecode/snooker/json/JsonRanking.java
src/main/java/org/hedgecode/snooker/json/JsonRankings.java
src/main/java/org/hedgecode/snooker/json/JsonSerializable.java [deleted file]
src/main/java/org/hedgecode/snooker/request/AbstractRequester.java
src/main/java/org/hedgecode/snooker/request/RequestParams.java

diff --git a/pom.xml b/pom.xml
index 59baa73..71b33dd 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <mavenAssemblyPluginVersion>2.4.1</mavenAssemblyPluginVersion>
         <mavenReleasePluginVersion>2.5.3</mavenReleasePluginVersion>
         <mavenPluginToolsVersion>3.4</mavenPluginToolsVersion>
+        <mavenReportsPluginVersion>2.8.1</mavenReportsPluginVersion>
+        <mavenFindBugsPluginVersion>3.0.4</mavenFindBugsPluginVersion>
         <wagonWebDavVersion>2.7</wagonWebDavVersion>
         <issueComponentId>10012</issueComponentId>
         <issueKey>LIB</issueKey>
-        <issueNumber>2</issueNumber>
+        <issueNumber>5</issueNumber>
     </properties>
 
     <dependencies>
         </plugins>
     </build>
 
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-project-info-reports-plugin</artifactId>
+                <version>${mavenReportsPluginVersion}</version>
+                <configuration>
+                    <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
+                </configuration>
+                <reportSets>
+                    <reportSet>
+                        <reports>
+                            <report>index</report>
+                            <report>summary</report>
+                            <report>dependency-info</report>
+                            <report>project-team</report>
+                            <report>scm</report>
+                            <report>dependency-management</report>
+                            <report>dependencies</report>
+                            <report>plugin-management</report>
+                            <report>plugins</report>
+                            <report>distribution-management</report>
+                        </reports>
+                    </reportSet>
+                </reportSets>
+            </plugin>
+        </plugins>
+    </reporting>
+
     <profiles>
         <profile>
             <id>jar-with-dependencies</id>
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>reporting</id>
+            <reporting>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-project-info-reports-plugin</artifactId>
+                        <version>${mavenReportsPluginVersion}</version>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-javadoc-plugin</artifactId>
+                        <configuration>
+                            <notimestamp>true</notimestamp>
+                            <quiet>true</quiet>
+                            <sourceFileExcludes>
+                                <exclude>org//hedgecode/snooker/cache/assign/*.java</exclude>
+                                <exclude>org//hedgecode/snooker/compare/*.java</exclude>
+                                <exclude>org//hedgecode/snooker/gson/*.java</exclude>
+                                <exclude>org//hedgecode/snooker/json/*.java</exclude>
+                                <exclude>org//hedgecode/snooker/request/*.java</exclude>
+                            </sourceFileExcludes>
+                        </configuration>
+                        <reportSets>
+                            <reportSet>
+                                <id>default</id>
+                                <reports>
+                                    <report>javadoc</report>
+                                </reports>
+                            </reportSet>
+                        </reportSets>
+                    </plugin>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>findbugs-maven-plugin</artifactId>
+                        <version>${mavenFindBugsPluginVersion}</version>
+                    </plugin>
+                </plugins>
+            </reporting>
+        </profile>
     </profiles>
 
 </project>
index e81bc6e..286c966 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker;
 
+import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 
 import org.hedgecode.snooker.api.APIException;
@@ -45,7 +46,7 @@ public final class SnookerScoreApp {
     private static final String UPCOMING_EVENTS = "  Upcoming Snooker Events:  ";
     private static final String INDENT = "     ";
 
-    private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
+    private static final String DATE_FORMAT = "dd.MM.yyyy";
 
     private static final int UPCOMING_COUNT = 5;
 
@@ -86,10 +87,11 @@ public final class SnookerScoreApp {
     }
 
     private static void printEvent(Event event) {
+        final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
         System.out.println(
                 INDENT  + event.name()
-                        + " [" + DATE_FORMAT.format(event.startDate())
-                        + " - " + DATE_FORMAT.format(event.endDate()) + "]"
+                        + " [" + dateFormat.format(event.startDate())
+                        + " - " + dateFormat.format(event.endDate()) + "]"
                         + " (" + event.country() + ", " + event.city() + ")"
         );
     }
index 73ee53a..f4b1cf5 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.api;
 
+import java.io.Serializable;
 import java.util.Calendar;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -25,7 +26,7 @@ import java.util.Map;
  *
  * @author Dmitry Samoshin aka gotty
  */
-public class Season {
+public class Season implements Serializable {
 
     private static final Calendar CURRENT_CALENDAR = Calendar.getInstance();
 
@@ -35,12 +36,12 @@ public class Season {
                     ? CURRENT_CALENDAR.get(Calendar.YEAR)
                     : CURRENT_CALENDAR.get(Calendar.YEAR) - 1;
 
-    private static final int ALL_SEASONS = -1;
+    public static final int ALL_SEASONS = -1;
 
     public static final Season ALL = new Season(ALL_SEASONS);
     public static final Season CURRENT_SEASON = new Season(CURRENT_YEAR);
 
-    public static Map<Integer, Season> SEASONS = new LinkedHashMap<>();
+    private static final Map<Integer, Season> SEASONS = new LinkedHashMap<>();
 
     static {
         for (int year = BEGIN_YEAR; year < CURRENT_YEAR; ++year) {
index 481435d..860c61d 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.compare;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.hedgecode.snooker.api.Event;
@@ -42,7 +43,7 @@ public enum EventComparators {
         return comparator;
     }
 
-    static class DateComparator implements Comparator<Event> {
+    static class DateComparator implements Comparator<Event>, Serializable {
 
         @Override
         public int compare(Event event1, Event event2) {
@@ -51,7 +52,7 @@ public enum EventComparators {
 
     }
 
-    static class SnookerIdComparator implements Comparator<Event> {
+    static class SnookerIdComparator implements Comparator<Event>, Serializable {
 
         @Override
         public int compare(Event event1, Event event2) {
index 939b1bc..03c52f1 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.compare;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.hedgecode.snooker.api.Match;
@@ -42,7 +43,7 @@ public enum MatchComparators {
         return comparator;
     }
 
-    static class RoundNumberComparator implements Comparator<Match> {
+    static class RoundNumberComparator implements Comparator<Match>, Serializable {
 
         @Override
         public int compare(Match match1, Match match2) {
@@ -53,7 +54,7 @@ public enum MatchComparators {
 
     }
 
-    static class EventComparator implements Comparator<Match> {
+    static class EventComparator implements Comparator<Match>, Serializable {
 
         @Override
         public int compare(Match match1, Match match2) {
index 834f2e7..77e7c0b 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.compare;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.hedgecode.snooker.api.Player;
@@ -42,7 +43,7 @@ public enum PlayerComparators {
         return comparator;
     }
 
-    static class NameComparator implements Comparator<Player> {
+    static class NameComparator implements Comparator<Player>, Serializable {
 
         @Override
         public int compare(Player player1, Player player2) {
@@ -51,7 +52,7 @@ public enum PlayerComparators {
 
     }
 
-    static class AgeComparator implements Comparator<Player> {
+    static class AgeComparator implements Comparator<Player>, Serializable {
 
         @Override
         public int compare(Player player1, Player player2) {
index f7551e0..54aa099 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.compare;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.hedgecode.snooker.api.Ranking;
@@ -42,7 +43,7 @@ public enum RankingComparators {
         return comparator;
     }
 
-    static class PositionComparator implements Comparator<Ranking> {
+    static class PositionComparator implements Comparator<Ranking>, Serializable {
 
         @Override
         public int compare(Ranking ranking1, Ranking ranking2) {
@@ -51,7 +52,7 @@ public enum RankingComparators {
 
     }
 
-    static class SumComparator implements Comparator<Ranking> {
+    static class SumComparator implements Comparator<Ranking>, Serializable {
 
         @Override
         public int compare(Ranking ranking1, Ranking ranking2) {
index 3223323..ef67ff6 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.hedgecode.snooker.json;
 
+import java.io.Serializable;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -33,20 +34,24 @@ import org.hedgecode.snooker.api.IdEntity;
  * @author Dmitry Samoshin aka gotty
  */
 public abstract class JsonCollectionEntity<E extends IdEntity>
-        implements CollectionEntity<E>, JsonSerializable
+        implements CollectionEntity<E>, Serializable
 {
     private final Map<Integer, E> entities = new LinkedHashMap<>();
 
     protected JsonCollectionEntity(E[] entities) {
         for (E entity : entities) {
             if (entity != null)
-                this.entities.put(entity.getId(), entity);
+                this.entities.put(
+                        entity.getId(), entity
+                );
         }
     }
 
     protected JsonCollectionEntity(List<E> entities) {
         for (E entity : entities) {
-            this.entities.put(entity.getId(), entity);
+            this.entities.put(
+                    entity.getId(), entity
+            );
         }
     }
 
index 2f47ee4..348d1a5 100644 (file)
@@ -112,6 +112,9 @@ public class JsonEvent extends JsonIdEntity implements Event {
     @SerializedName("PreviousEdition")
     private int previousEdition;
 
+    protected JsonEvent() {
+    }
+
     @Override
     public int eventId() {
         return eventId;
@@ -124,12 +127,16 @@ public class JsonEvent extends JsonIdEntity implements Event {
 
     @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
index 78474de..664dcd8 100644 (file)
@@ -17,6 +17,9 @@
 package org.hedgecode.snooker.json;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 import org.hedgecode.snooker.api.Event;
@@ -31,6 +34,8 @@ import org.hedgecode.snooker.compare.EventComparators;
  */
 public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
 
+    private static final JsonEvents EMPTY = new JsonEvents(new Event[0]);
+
     protected JsonEvents(Event[] entities) {
         super(entities);
     }
@@ -45,7 +50,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.season().equals(season))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -54,7 +59,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.type().equals(type))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -63,7 +68,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.city().equals(city))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -72,7 +77,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.country().equals(country))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -81,7 +86,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.sex().equals(sex))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -90,7 +95,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.stage().equals(stage))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -99,7 +104,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.valueType().equals(valueType))
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -108,7 +113,7 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         for (Event event : this)
             if (event.worldSnookerId() == worldSnookerId)
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -116,9 +121,9 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         List<Event> events = new ArrayList<>();
         long currentTime = System.currentTimeMillis();
         for (Event event : this)
-            if (event.endDate().getTime() < currentTime)
+            if (currentTime > nextDate(event.endDate()).getTime())
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -126,10 +131,10 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         List<Event> events = new ArrayList<>();
         long currentTime = System.currentTimeMillis();
         for (Event event : this)
-            if (event.startDate().getTime() < currentTime
-                    && event.endDate().getTime() > currentTime)
+            if (currentTime > event.startDate().getTime()
+                    && currentTime < nextDate(event.endDate()).getTime())
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -137,9 +142,9 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         List<Event> events = new ArrayList<>();
         long currentTime = System.currentTimeMillis();
         for (Event event : this)
-            if (event.startDate().getTime() > currentTime)
+            if (currentTime < event.startDate().getTime())
                 events.add(event);
-        return events.isEmpty() ? null : new JsonEvents(events);
+        return events.isEmpty() ? EMPTY : new JsonEvents(events);
     }
 
     @Override
@@ -156,4 +161,11 @@ public class JsonEvents extends JsonCollectionEntity<Event> implements Events {
         );
     }
 
+    private Date nextDate(Date date) {
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        c.add(Calendar.DATE, 1);
+        return c.getTime();
+    }
+
 }
index 6b6c213..25207b4 100644 (file)
@@ -16,6 +16,8 @@
 
 package org.hedgecode.snooker.json;
 
+import java.io.Serializable;
+
 import org.hedgecode.snooker.api.IdEntity;
 
 /**
@@ -23,7 +25,7 @@ import org.hedgecode.snooker.api.IdEntity;
  *
  * @author Dmitry Samoshin aka gotty
  */
-public abstract class JsonIdEntity implements IdEntity, JsonSerializable {
+public abstract class JsonIdEntity implements IdEntity, Serializable {
 
     @Override
     public boolean equals(Object obj) {
index 2731565..22248dd 100644 (file)
@@ -103,6 +103,9 @@ public class JsonMatch extends JsonIdEntity implements Match {
     @SerializedName("ExtendedNote")
     private String  extendedNote;
 
+    protected JsonMatch() {
+    }
+
     @Override
     public int matchId() {
         return matchId;
@@ -255,27 +258,37 @@ public class JsonMatch extends JsonIdEntity implements Match {
 
     @Override
     public Date initDate() {
-        return initDate;
+        return initDate == null
+                ? null
+                : new Date(initDate.getTime());
     }
 
     @Override
     public Date modDate() {
-        return modDate;
+        return modDate == null
+                ? null
+                : new Date(modDate.getTime());
     }
 
     @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
     public Date scheduledDate() {
-        return scheduledDate;
+        return scheduledDate == null
+                ? null
+                : new Date(scheduledDate.getTime());
     }
 
     @Override
index 0d4dd02..83a0285 100644 (file)
@@ -30,6 +30,8 @@ import org.hedgecode.snooker.compare.MatchComparators;
  */
 public class JsonMatches extends JsonCollectionEntity<Match> implements Matches {
 
+    private static final JsonMatches EMPTY = new JsonMatches(new Match[0]);
+
     protected JsonMatches(Match[] entities) {
         super(entities);
     }
@@ -44,7 +46,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.eventId() == eventId)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
@@ -53,7 +55,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.eventId() == eventId && match.round() == round)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
@@ -62,7 +64,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.player1Id() == playerId || match.player2Id() == playerId)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
@@ -71,7 +73,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.endDate() != null)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
@@ -80,7 +82,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.startDate() != null && match.endDate() == null)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
@@ -89,7 +91,7 @@ public class JsonMatches extends JsonCollectionEntity<Match> implements Matches
         for (Match match : this)
             if (match.startDate() == null)
                 matches.add(match);
-        return matches.isEmpty() ? null : new JsonMatches(matches);
+        return matches.isEmpty() ? EMPTY : new JsonMatches(matches);
     }
 
     @Override
index 6e5cb1d..6fa9efe 100644 (file)
@@ -25,4 +25,7 @@ import org.hedgecode.snooker.api.OngoingMatch;
  */
 public class JsonOngoingMatch extends JsonMatch implements OngoingMatch {
 
+    protected JsonOngoingMatch() {
+    }
+
 }
index 6db13d1..04ac5da 100644 (file)
@@ -70,6 +70,9 @@ public class JsonPlayer extends JsonIdEntity implements Player {
     @SerializedName("Info")
     private String info;
 
+    protected JsonPlayer() {
+    }
+
     @Override
     public int playerId() {
         return playerId;
@@ -132,7 +135,9 @@ public class JsonPlayer extends JsonIdEntity implements Player {
 
     @Override
     public Date born() {
-        return born;
+        return born == null
+                ? null
+                : new Date(born.getTime());
     }
 
     @Override
index 26c68e2..2ba59d3 100644 (file)
@@ -30,6 +30,8 @@ import org.hedgecode.snooker.compare.PlayerComparators;
  */
 public class JsonPlayers extends JsonCollectionEntity<Player> implements Players {
 
+    private static final JsonPlayers EMPTY = new JsonPlayers(new Player[0]);
+
     protected JsonPlayers(Player[] entities) {
         super(entities);
     }
@@ -44,7 +46,7 @@ public class JsonPlayers extends JsonCollectionEntity<Player> implements Players
         for (Player player : this)
             if (player.type() == type)
                 players.add(player);
-        return players.isEmpty() ? null : new JsonPlayers(players);
+        return players.isEmpty() ? EMPTY : new JsonPlayers(players);
     }
 
     @Override
@@ -53,7 +55,7 @@ public class JsonPlayers extends JsonCollectionEntity<Player> implements Players
         for (Player player : this)
             if (player.shortName().contains(name))
                 players.add(player);
-        return players.isEmpty() ? null : new JsonPlayers(players);
+        return players.isEmpty() ? EMPTY : new JsonPlayers(players);
     }
 
     @Override
@@ -62,7 +64,7 @@ public class JsonPlayers extends JsonCollectionEntity<Player> implements Players
         for (Player player : this)
             if (player.nationality().equals(nationality))
                 players.add(player);
-        return players.isEmpty() ? null : new JsonPlayers(players);
+        return players.isEmpty() ? EMPTY : new JsonPlayers(players);
     }
 
     @Override
@@ -71,7 +73,7 @@ public class JsonPlayers extends JsonCollectionEntity<Player> implements Players
         for (Player player : this)
             if (player.nationality().equals(sex))
                 players.add(player);
-        return players.isEmpty() ? null : new JsonPlayers(players);
+        return players.isEmpty() ? EMPTY : new JsonPlayers(players);
     }
 
     @Override
index 02e08f5..2648591 100644 (file)
@@ -50,6 +50,9 @@ public class JsonRanking extends JsonIdEntity implements Ranking {
     @Expose
     private RankingType rankingType;
 
+    protected JsonRanking() {
+    }
+
     @Override
     public int rankingId() {
         return rankingId;
index 75a3358..ac0a1ae 100644 (file)
@@ -30,6 +30,8 @@ import org.hedgecode.snooker.compare.RankingComparators;
  */
 public class JsonRankings extends JsonCollectionEntity<Ranking> implements Rankings {
 
+    private static final JsonRankings EMPTY = new JsonRankings(new Ranking[0]);
+
     protected JsonRankings(Ranking[] entities) {
         super(entities);
     }
@@ -52,7 +54,7 @@ public class JsonRankings extends JsonCollectionEntity<Ranking> implements Ranki
         for (Ranking ranking : this)
             if (ranking.sum() >= minSum && ranking.sum() <= maxSum)
                 rankings.add(ranking);
-        return rankings.isEmpty() ? null : new JsonRankings(rankings);
+        return rankings.isEmpty() ? EMPTY : new JsonRankings(rankings);
     }
 
     @Override
@@ -68,4 +70,5 @@ public class JsonRankings extends JsonCollectionEntity<Ranking> implements Ranki
                 RankingComparators.SUM.comparator()
         );
     }
+
 }
diff --git a/src/main/java/org/hedgecode/snooker/json/JsonSerializable.java b/src/main/java/org/hedgecode/snooker/json/JsonSerializable.java
deleted file mode 100644 (file)
index 8d7db08..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2017. 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.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.hedgecode.snooker.json;
-
-import java.io.Serializable;
-
-/**
- * Dummy Interface to Serializable Objects.
- *
- * @author Dmitry Samoshin aka gotty
- */
-public interface JsonSerializable extends Serializable {
-
-}
index a127bb5..db8e5eb 100644 (file)
@@ -21,6 +21,8 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 
 /**
  * Abstract Data Requester from the portal api.snooker.org.
@@ -30,6 +32,7 @@ import java.net.URLConnection;
 public abstract class AbstractRequester implements Requester {
 
     protected static final String API_SNOOKER_URL = "http://api.snooker.org/";
+    protected static final Charset API_SNOOKER_CHARSET = StandardCharsets.UTF_8;
 
     protected abstract String getRequestUrl(int id) throws RequestException;
 
@@ -56,7 +59,7 @@ public abstract class AbstractRequester implements Requester {
             URLConnection urlConnection = url.openConnection();
             BufferedReader br = new BufferedReader(
                     new InputStreamReader(
-                            urlConnection.getInputStream()
+                            urlConnection.getInputStream(), API_SNOOKER_CHARSET
                     )
             );
             String inputLine;
index a11da9b..cb325dd 100644 (file)
@@ -52,6 +52,7 @@ public class RequestParams {
             case SEASON_EVENTS:
                 this.season = season;
                 break;
+            default:
         }
     }