public class ArrayComparator<E> extends Object implements Comparator<E>, Serializable
compare(E, E)
is an array, and
it compares the n-th element, where n is passed in the constructor,
ArrayComparator(int, boolean)
(the index parameter).
It also assumes the element must implement Comparable
.Constructor and Description |
---|
ArrayComparator(int index,
boolean ascending)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compare(E o1,
E o2) |
int |
getIndex()
Returns the index of the element.
|
boolean |
isAscending()
Returns whether the sorting is ascending.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public ArrayComparator(int index, boolean ascending)
index
- which index of an array to compareascending
- whether to sort as ascending (or descending).public int compare(E o1, E o2)
compare
in interface Comparator<E>
public int getIndex()
public boolean isAscending()
Copyright © 2019. All rights reserved.