Comparable, Comparators
| Modifier and Type | Field and Description |
|---|---|
| private final Comparator | |
| public static final NullSafeComparator | NULLS_HIGH
A shared default instance of this comparator, treating nulls higher than non-null objects. |
| public static final NullSafeComparator | NULLS_LOW
A shared default instance of this comparator, treating nulls lower than non-null objects. |
| private final boolean |
| Access | Constructor and Description |
|---|---|
| private | NullSafeComparator(boolean
whether to treat nulls lower or higher than non-null objects nullsLow)Create a NullSafeComparator that sorts |
| public | NullSafeComparator(Comparator<T>
the comparator to use when comparing two non-null objects comparator, boolean whether to treat nulls lower or higher than non-null objects nullsLow)Create a NullSafeComparator that sorts |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(T
the first object to be compared. left, T the second object to be compared. right)Implements java. |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides java. Implements java. |
| public int | |
| public String |
| nonNullComparator | back to summary |
|---|---|
| private final Comparator<T> nonNullComparator | |
| NULLS_HIGH | back to summary |
|---|---|
| public static final NullSafeComparator<T> NULLS_HIGH
Deprecated as a consequence of A shared default instance of this comparator, treating nulls higher than non-null objects.
| |
| NULLS_LOW | back to summary |
|---|---|
| public static final NullSafeComparator<T> NULLS_LOW
Deprecated as a consequence of A shared default instance of this comparator, treating nulls lower than non-null objects.
| |
| nullsLow | back to summary |
|---|---|
| private final boolean nullsLow | |
| NullSafeComparator | back to summary |
|---|---|
| private NullSafeComparator(boolean nullsLow) Create a NullSafeComparator that sorts 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 | back to summary |
|---|---|
| public NullSafeComparator(Comparator<T> comparator, boolean nullsLow) Create a NullSafeComparator that sorts 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.
| |
| compare | back to summary |
|---|---|
| public int compare(T left, T right) Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. Implements java. Doc from java. Indicates whether some other object is "equal to"
this comparator. This method must obey the general contract of
Note that it is always safe not to override
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |