2 * Copyright (c) 2017-2019. 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.util.ArrayList;
20 import java.util.List;
22 import org.hedgecode.snooker.api.Round;
23 import org.hedgecode.snooker.api.Rounds;
24 import org.hedgecode.snooker.compare.RoundComparators;
27 * Rounds Entity (set of {@link Round}) to JSON deserialize.
29 * @author Dmitry Samoshin aka gotty
31 public class JsonRounds extends JsonCollectionEntity<Round> implements Rounds {
33 private static final JsonRounds EMPTY = new JsonRounds(new Round[0]);
35 protected JsonRounds(Round[] entities) {
39 protected JsonRounds(List<Round> entities) {
44 public Round byRound(int roundId) {
45 for (Round round : this)
46 if (round.round() == roundId)
52 public Rounds byRoundName(String roundName) {
53 if (roundName == null || roundName.isEmpty())
55 List<Round> rounds = new ArrayList<>();
56 for (Round round : this)
57 if (roundName.equals(round.roundName()))
59 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
63 public Rounds byEvent(int eventId) {
64 List<Round> rounds = new ArrayList<>();
65 for (Round round : this)
66 if (round.eventId() == eventId)
68 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
72 public Rounds byMainEvent(int mainEventId) {
73 List<Round> rounds = new ArrayList<>();
74 for (Round round : this)
75 if (round.mainEventId() == mainEventId)
77 return rounds.isEmpty() ? EMPTY : new JsonRounds(rounds);
81 public void sortByRound() {
83 RoundComparators.ROUND.comparator()
88 public void sortByEvent() {
90 RoundComparators.EVENT.comparator()