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;
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.hedgecode.snooker.api.Round;
24 import org.hedgecode.snooker.api.Rounds;
25 import org.hedgecode.snooker.compare.RoundComparators;
28 * Rounds Entity (set of {@link Round}) to JSON deserialize.
30 * @author Dmitry Samoshin aka gotty
32 public class JsonRounds extends JsonCollectionEntity<Round> implements Rounds, Serializable {
34 private static final long serialVersionUID = -292582814222405882L;
36 private static final JsonRounds EMPTY = new JsonRounds(new Round[0]);
38 JsonRounds(Round[] entities) {
42 JsonRounds(List<Round> entities) {
47 public Round byRound(int roundId) {
48 for (Round round : this)
49 if (round.round() == roundId)
55 public Rounds byRoundName(String roundName) {
56 if (roundName == null || roundName.isEmpty())
58 List<Round> rounds = new ArrayList<>();
59 for (Round round : this)
60 if (roundName.equals(round.roundName()))
62 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
66 public Rounds byEvent(int eventId) {
67 List<Round> rounds = new ArrayList<>();
68 for (Round round : this)
69 if (round.eventId() == eventId)
71 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
75 public Rounds byMainEvent(int mainEventId) {
76 List<Round> rounds = new ArrayList<>();
77 for (Round round : this)
78 if (round.mainEventId() == mainEventId)
80 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
84 public void sortByRound() {
86 RoundComparators.ROUND.comparator()
91 public void sortByEvent() {
93 RoundComparators.EVENT.comparator()