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.Seeding;
24 import org.hedgecode.snooker.api.Seedings;
25 import org.hedgecode.snooker.compare.SeedingComparators;
28 * Seedings Entity (set of {@link Seeding}) to JSON deserialize.
30 * @author Dmitry Samoshin aka gotty
32 public class JsonSeedings extends JsonCollectionEntity<Seeding> implements Seedings, Serializable {
34 private static final long serialVersionUID = 8251290277292098461L;
36 private static final JsonSeedings EMPTY = new JsonSeedings(new Seeding[0]);
38 JsonSeedings(Seeding[] entities) {
42 JsonSeedings(List<Seeding> entities) {
47 public Seedings byEvent(int eventId) {
48 List<Seeding> seedings = new ArrayList<>();
49 for (Seeding seeding : this)
50 if (seeding.eventId() == eventId)
51 seedings.add(seeding);
52 return seedings.isEmpty() ? EMPTY : new JsonSeedings(seedings);
56 public Seeding byPlayer(int playerId) {
57 for (Seeding seeding : this)
58 if (seeding.playerId() == playerId)
64 public Seeding bySeeding(int seedingNum) {
65 for (Seeding seeding : this)
66 if (seeding.seeding() == seedingNum)
72 public void sortByEvent() {
74 SeedingComparators.EVENT.comparator()
79 public void sortByPlayer() {
81 SeedingComparators.PLAYER.comparator()
86 public void sortBySeeding() {
88 SeedingComparators.SEEDING.comparator()