org.springframework.util.comparator

## 类 NullSafeComparator<T>

- java.lang.Object
- - org.springframework.util.comparator.NullSafeComparator<T>

- 所有已实现的接口:
    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.
  从以下版本开始:
    1.2.2
  作者:
    Keith Donald, Juergen Hoeller
  另请参阅:
    `Comparable`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static NullSafeComparator` | `NULLS_HIGH` A shared default instance of this comparator, treating nulls higher than non-null objects.
    `static NullSafeComparator` | `NULLS_LOW` A shared default instance of this comparator, treating nulls lower than non-null objects.

  - ### 构造器概要

    构造器
    构造器和说明
    `NullSafeComparator(Comparator<T> comparator, boolean nullsLow)` Create a NullSafeComparator that sorts `null` based on the provided flag, decorating the given Comparator.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `int` | `compare(T o1, T o2)`
    `boolean` | `equals(Object other)`
    `int` | `hashCode()`
    `String` | `toString()`

    - ### 从类继承的方法 java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### 从接口继承的方法 java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### 字段详细资料

    - #### NULLS_LOW

          public static final NullSafeComparator NULLS_LOW

      A shared default instance of this comparator, treating nulls lower than non-null objects.
      另请参阅:
        `Comparators.nullsLow()`

    - #### NULLS_HIGH

          public static final NullSafeComparator NULLS_HIGH

      A shared default instance of this comparator, treating nulls higher than non-null objects.
      另请参阅:
        `Comparators.nullsHigh()`

  - ### 构造器详细资料

    - #### 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

  - ### 方法详细资料

    - #### compare

          public int compare(@Nullable
                             T o1,
                             @Nullable
                             T o2)

      指定者:
        `compare` 在接口中 `Comparator<T>`

    - #### equals

          public boolean equals(Object other)

      指定者:
        `equals` 在接口中 `Comparator<T>`
      覆盖:
        `equals` 在类中 `Object`

    - #### hashCode

          public int hashCode()

      覆盖:
        `hashCode` 在类中 `Object`

    - #### toString

          public String toString()

      覆盖:
        `toString` 在类中 `Object`