[LIB-8] Add Event Rounds and Seedings functional
[snooker-score-api.git] / src / main / java / org / hedgecode / snooker / compare / SeedingComparators.java
1 /*
2  * Copyright (c) 2017-2019. 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.compare;
18
19 import java.io.Serializable;
20 import java.util.Comparator;
21
22 import org.hedgecode.snooker.api.Seeding;
23
24 /**
25  * Set of Comparators for {@link Seeding}.
26  * 1. Sorting by Event {@link EventComparator};
27  * 2. Sorting by Player {@link PlayerComparator};
28  * 3. Sorting by Seeding Number {@link SeedingComparator}.
29  *
30  * @author Dmitry Samoshin aka gotty
31  */
32 public enum SeedingComparators {
33
34     EVENT   ( new EventComparator() ),
35     PLAYER  ( new PlayerComparator() ),
36     SEEDING ( new SeedingComparator() );
37
38     private Comparator<Seeding> comparator;
39
40     SeedingComparators(Comparator<Seeding> comparator) {
41         this.comparator = comparator;
42     }
43
44     public Comparator<Seeding> comparator() {
45         return comparator;
46     }
47
48     static class EventComparator implements Comparator<Seeding>, Serializable {
49
50         @Override
51         public int compare(Seeding seeding1, Seeding seeding2) {
52             return seeding1.eventId() - seeding2.eventId();
53         }
54
55     }
56
57     static class PlayerComparator implements Comparator<Seeding>, Serializable {
58
59         @Override
60         public int compare(Seeding seeding1, Seeding seeding2) {
61             return seeding1.playerId() - seeding2.playerId();
62         }
63
64     }
65
66     static class SeedingComparator implements Comparator<Seeding>, Serializable {
67
68         @Override
69         public int compare(Seeding seeding1, Seeding seeding2) {
70             return seeding1.seeding() - seeding2.seeding();
71         }
72
73     }
74
75 }