/* * Copyright (c) 2017-2020. 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.util.Comparator; import org.hedgecode.snooker.api.Seeding; /** * Set of Comparators for {@link Seeding}. * 1. Sorting by Event {@link EventComparator}; * 2. Sorting by Player {@link PlayerComparator}; * 3. Sorting by Seeding Number {@link SeedingComparator}. * * @author Dmitry Samoshin aka gotty */ public enum SeedingComparators { EVENT ( new EventComparator() ), PLAYER ( new PlayerComparator() ), SEEDING ( new SeedingComparator() ); private Comparator comparator; SeedingComparators(Comparator comparator) { this.comparator = comparator; } public Comparator comparator() { return comparator; } static class EventComparator implements Comparator { @Override public int compare(Seeding seeding1, Seeding seeding2) { return seeding1.eventId() - seeding2.eventId(); } } static class PlayerComparator implements Comparator { @Override public int compare(Seeding seeding1, Seeding seeding2) { return seeding1.playerId() - seeding2.playerId(); } } static class SeedingComparator implements Comparator { @Override public int compare(Seeding seeding1, Seeding seeding2) { return seeding1.seeding() - seeding2.seeding(); } } }