
cn.taketoday.core.OrderComparator Maven / Gradle / Ivy
/*
* Original Author -> Harry Yang ([email protected]) https://taketoday.cn
* Copyright © TODAY & 2017 - 2021 All Rights Reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [http://www.gnu.org/licenses/]
*/
package cn.taketoday.core;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import cn.taketoday.lang.Nullable;
import cn.taketoday.util.ObjectUtils;
/**
* {@link Comparator} implementation for {@link Ordered} objects, sorting
* by order value ascending, respectively by priority descending.
*
* {@code PriorityOrdered} Objects
* {@link PriorityOrdered} objects will be sorted with higher priority than
* plain {@code Ordered} objects.
*
*
Same Order Objects
* Objects that have the same order value will be sorted with arbitrary
* ordering with respect to other objects with the same order value.
*
*
Non-ordered Objects
* Any object that does not provide its own order value is implicitly
* assigned a value of {@link Ordered#LOWEST_PRECEDENCE}, thus ending up
* at the end of a sorted collection in arbitrary order with respect to
* other objects with the same order value.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @author TODAY 2021/9/12 11:32
* @see Ordered
* @see PriorityOrdered
* @see java.util.List#sort(java.util.Comparator)
* @see java.util.Arrays#sort(Object[], java.util.Comparator)
* @since 4.0
*/
public class OrderComparator implements Comparator