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.Event;
24 * Set of Comparators for {@link Event}.
25 * 1. Sorting by Date {@link DateComparator};
26 * 2. Sorting by WorldSnookerId {@link SnookerIdComparator}.
28 * @author Dmitry Samoshin aka gotty
30 public enum EventComparators {
32 DATE ( new DateComparator() ),
33 SNOOKER_ID ( new SnookerIdComparator() );
35 private Comparator<Event> comparator;
37 EventComparators(Comparator<Event> comparator) {
38 this.comparator = comparator;
41 public Comparator<Event> comparator() {
45 static class DateComparator implements Comparator<Event> {
48 public int compare(Event event1, Event event2) {
49 return event1.startDate().compareTo(event2.startDate());
54 static class SnookerIdComparator implements Comparator<Event> {
57 public int compare(Event event1, Event event2) {
58 return event1.worldSnookerId() - event2.worldSnookerId();