[LIB-10] SerialVersionUID for Serializable classes
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / json / JsonSeedings.java
1 /*
2  * Copyright (c) 2017-2020. Developed by Hedgecode.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.hedgecode.snooker.json;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.hedgecode.snooker.api.Seeding;
24 import org.hedgecode.snooker.api.Seedings;
25 import org.hedgecode.snooker.compare.SeedingComparators;
26
27 /**
28  * Seedings Entity (set of {@link Seeding}) to JSON deserialize.
29  *
30  * @author Dmitry Samoshin aka gotty
31  */
32 public class JsonSeedings extends JsonCollectionEntity<Seeding> implements Seedings, Serializable {
33
34     private static final long serialVersionUID = 8251290277292098461L;
35
36     private static final JsonSeedings EMPTY = new JsonSeedings(new Seeding[0]);
37
38     JsonSeedings(Seeding[] entities) {
39         super(entities);
40     }
41
42     JsonSeedings(List<Seeding> entities) {
43         super(entities);
44     }
45
46     @Override
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);
53     }
54
55     @Override
56     public Seeding byPlayer(int playerId) {
57         for (Seeding seeding : this)
58             if (seeding.playerId() == playerId)
59                 return seeding;
60         return null;
61     }
62
63     @Override
64     public Seeding bySeeding(int seedingNum) {
65         for (Seeding seeding : this)
66             if (seeding.seeding() == seedingNum)
67                 return seeding;
68         return null;
69     }
70
71     @Override
72     public void sortByEvent() {
73         sort(
74                 SeedingComparators.EVENT.comparator()
75         );
76     }
77
78     @Override
79     public void sortByPlayer() {
80         sort(
81                 SeedingComparators.PLAYER.comparator()
82         );
83     }
84
85     @Override
86     public void sortBySeeding() {
87         sort(
88                 SeedingComparators.SEEDING.comparator()
89         );
90     }
91
92 }