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.compare;
19 import java.io.Serializable;
20 import java.util.Comparator;
22 import org.hedgecode.snooker.api.Seeding;
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}.
30 * @author Dmitry Samoshin aka gotty
32 public enum SeedingComparators {
34 EVENT ( new EventComparator() ),
35 PLAYER ( new PlayerComparator() ),
36 SEEDING ( new SeedingComparator() );
38 private Comparator<Seeding> comparator;
40 SeedingComparators(Comparator<Seeding> comparator) {
41 this.comparator = comparator;
44 public Comparator<Seeding> comparator() {
48 static class EventComparator implements Comparator<Seeding>, Serializable {
51 public int compare(Seeding seeding1, Seeding seeding2) {
52 return seeding1.eventId() - seeding2.eventId();
57 static class PlayerComparator implements Comparator<Seeding>, Serializable {
60 public int compare(Seeding seeding1, Seeding seeding2) {
61 return seeding1.playerId() - seeding2.playerId();
66 static class SeedingComparator implements Comparator<Seeding>, Serializable {
69 public int compare(Seeding seeding1, Seeding seeding2) {
70 return seeding1.seeding() - seeding2.seeding();