类 NullSafeComparator<T>

java.lang.Object
cn.taketoday.util.comparator.NullSafeComparator<T>
类型参数:
T - the type of objects that may be compared by this comparator
所有已实现的接口:
Comparator<T>

public class NullSafeComparator<T> extends Object implements Comparator<T>
A Comparator that will safely compare nulls to be lower or higher than other objects. Can decorate a given Comparator or work on Comparables.
从以下版本开始:
4.0
作者:
Keith Donald, Juergen Hoeller, Harry Yang
另请参阅:
  • 字段详细资料

    • NULLS_LOW

      public static final NullSafeComparator NULLS_LOW
      A shared default instance of this comparator, treating nulls lower than non-null objects.
      另请参阅:
    • NULLS_HIGH

      public static final NullSafeComparator NULLS_HIGH
      A shared default instance of this comparator, treating nulls higher than non-null objects.
      另请参阅:
    • nonNullComparator

      private final Comparator<T> nonNullComparator
    • nullsLow

      private final boolean nullsLow
  • 构造器详细资料

    • NullSafeComparator

      private NullSafeComparator(boolean nullsLow)
      Create a NullSafeComparator that sorts null based on the provided flag, working on Comparables.

      When comparing two non-null objects, their Comparable implementation will be used: this means that non-null elements (that this Comparator will be applied to) need to implement Comparable.

      As a convenience, you can use the default shared instances: NullSafeComparator.NULLS_LOW and NullSafeComparator.NULLS_HIGH.

      参数:
      nullsLow - whether to treat nulls lower or higher than non-null objects
      另请参阅:
    • NullSafeComparator

      public NullSafeComparator(Comparator<T> comparator, boolean nullsLow)
      Create a NullSafeComparator that sorts null based on the provided flag, decorating the given Comparator.

      When comparing two non-null objects, the specified Comparator will be used. The given underlying Comparator must be able to handle the elements that this Comparator will be applied to.

      参数:
      comparator - the comparator to use when comparing two non-null objects
      nullsLow - whether to treat nulls lower or higher than non-null objects
  • 方法详细资料