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.compare;
19 import java.util.Comparator;
21 import org.hedgecode.snooker.api.Seeding;
24 * Set of Comparators for {@link Seeding}.
25 * 1. Sorting by Event {@link EventComparator};
26 * 2. Sorting by Player {@link PlayerComparator};
27 * 3. Sorting by Seeding Number {@link SeedingComparator}.
29 * @author Dmitry Samoshin aka gotty
31 public enum SeedingComparators {
33 EVENT ( new EventComparator() ),
34 PLAYER ( new PlayerComparator() ),
35 SEEDING ( new SeedingComparator() );
37 private Comparator<Seeding> comparator;
39 SeedingComparators(Comparator<Seeding> comparator) {
40 this.comparator = comparator;
43 public Comparator<Seeding> comparator() {
47 static class EventComparator implements Comparator<Seeding> {
50 public int compare(Seeding seeding1, Seeding seeding2) {
51 return seeding1.eventId() - seeding2.eventId();
56 static class PlayerComparator implements Comparator<Seeding> {
59 public int compare(Seeding seeding1, Seeding seeding2) {
60 return seeding1.playerId() - seeding2.playerId();
65 static class SeedingComparator implements Comparator<Seeding> {
68 public int compare(Seeding seeding1, Seeding seeding2) {
69 return seeding1.seeding() - seeding2.seeding();