[LIB-5] Collection empty objects,reporting and serializable
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonMatches.java
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