
nl.talsmasoftware.context.PriorityComparator Maven / Gradle / Ivy
/*
* Copyright 2016-2017 Talsma ICT
*
* 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 nl.talsmasoftware.context;
import java.util.Comparator;
import static java.lang.Math.abs;
/**
* Comparator for classes that may or may not contain a {@literal @}Priority
annotation
* on their class or superclasses.
*
* The priority is applied as follows:
*
* - First, non-negative priority is applied in natural order (e.g. {@code 0}, {@code 1}, {@code 2}, ...).
* - Next, objects without
{@literal @}Priority
annotation are applied
* by assigning a {@link #UNDEFINED_PRIORITY default priority} of {@link Integer#MAX_VALUE}.
* - Finally, negative priority is applied in reverse-natural order (e.g. {@code -1}, {@code -2}, {@code -3}, ...).
*
*
* The order of objects with equal (implicit) priority is undefined.
*
* @author Sjoerd Talsma
*/
final class PriorityComparator implements Comparator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy