/* * Copyright (c) 2017. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hedgecode.snooker.compare; import java.io.Serializable; import java.util.Comparator; import org.hedgecode.snooker.api.Match; /** * Set of Comparators for {@link Match}. * 1. Sorting by Round and Number of Match {@link RoundNumberComparator}; * 2. Sorting by Event {@link EventComparator}. * * @author Dmitry Samoshin aka gotty */ public enum MatchComparators { ROUND_NUMBER ( new RoundNumberComparator() ), EVENT ( new EventComparator() ); private Comparator comparator; MatchComparators(Comparator comparator) { this.comparator = comparator; } public Comparator comparator() { return comparator; } static class RoundNumberComparator implements Comparator, Serializable { @Override public int compare(Match match1, Match match2) { return match1.round() == match2.round() ? match1.number() - match2.round() : match2.round() - match1.round(); } } static class EventComparator implements Comparator, Serializable { @Override public int compare(Match match1, Match match2) { return match1.eventId() - match2.eventId(); } } }