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.Seeding;
23 import org.hedgecode.snooker.api.Seedings;
24 import org.hedgecode.snooker.compare.SeedingComparators;
27 * Seedings Entity (set of {@link Seeding}) to JSON deserialize.
29 * @author Dmitry Samoshin aka gotty
31 public class JsonSeedings extends JsonCollectionEntity<Seeding> implements Seedings {
33 private static final JsonSeedings EMPTY = new JsonSeedings(new Seeding[0]);
35 protected JsonSeedings(Seeding[] entities) {
39 protected JsonSeedings(List<Seeding> entities) {
44 public Seedings byEvent(int eventId) {
45 List<Seeding> seedings = new ArrayList<>();
46 for (Seeding seeding : this)
47 if (seeding.eventId() == eventId)
48 seedings.add(seeding);
49 return seedings.isEmpty() ? EMPTY : new JsonSeedings(seedings);
53 public Seeding byPlayer(int playerId) {
54 for (Seeding seeding : this)
55 if (seeding.playerId() == playerId)
61 public Seeding bySeeding(int seedingNum) {
62 for (Seeding seeding : this)
63 if (seeding.seeding() == seedingNum)
69 public void sortByEvent() {
71 SeedingComparators.EVENT.comparator()
76 public void sortByPlayer() {
78 SeedingComparators.PLAYER.comparator()
83 public void sortBySeeding() {
85 SeedingComparators.SEEDING.comparator()