|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.collect.Ordering<T>
public abstract class Ordering<T>
A base class for Serializable comparators that
provides convenience methods for common uses.
| Constructor Summary | |
|---|---|
Ordering()
|
|
| Method Summary | ||
|---|---|---|
int |
binarySearch(java.util.List<? extends T> sortedList,
T key)
Searches
sortedList for key using the binary search algorithm. |
|
static
|
forComparator(java.util.Comparator<T> comparator)
Returns an ordering for comparator. |
|
|
max(E a,
E b)
Returns the larger of the two values according to this ordering. |
|
|
max(E a,
E b,
E c,
E... rest)
Returns the largest of the specified values according to this ordering. |
|
|
max(java.lang.Iterable<E> iterable)
Returns the largest of the specified values according to this ordering. |
|
|
min(E a,
E b)
Returns the smaller of the two values according to this ordering. |
|
|
min(E a,
E b,
E c,
E... rest)
Returns the smallest of the specified values according to this ordering. |
|
|
min(java.lang.Iterable<E> iterable)
Returns the smallest of the specified values according to this ordering. |
|
static
|
natural()
Returns an ordering that uses the natural order of the values. |
|
Ordering<T> |
nullsFirst()
Returns an ordering that treats null as less than all other values
and uses this ordering to compare non-null values. |
|
Ordering<T> |
nullsLast()
Returns an ordering that treats null as greater than all other
values and uses this ordering to compare non-null values. |
|
Ordering<T> |
reverseOrder()
Returns the ordering that is the reverse of this ordering. |
|
void |
sort(java.util.List<? extends T> list)
Sorts list according
to this ordering. |
|
|
sortedCopy(java.lang.Iterable<E> iterable)
Returns a copy of the given iterable sorted by this ordering. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Comparator |
|---|
compare, equals |
| Constructor Detail |
|---|
public Ordering()
| Method Detail |
|---|
public static <T extends java.lang.Comparable> Ordering<T> natural()
NullPointerException when passed a null parameter.
The type specification is <T extends Comparable>, instead of
the more specific <T extends Comparable<? super T>>, to support
classes defined without generics.
public static <T> Ordering<T> forComparator(java.util.Comparator<T> comparator)
comparator.
comparator - the comparator that defines the orderpublic Ordering<T> reverseOrder()
reverse of this ordering.
public int binarySearch(java.util.List<? extends T> sortedList,
T key)
Searches
sortedList for key using the binary search algorithm. The
list must be sorted using this ordering.
sortedList - the list to be searchedkey - the key to be searched forpublic void sort(java.util.List<? extends T> list)
Sorts list according
to this ordering.
list - the list to be sortedpublic <E extends T> java.util.List<E> sortedCopy(java.lang.Iterable<E> iterable)
Unlike Sets.newTreeSet(Comparator, Iterable), this method does
not collapse elements that compare as zero, and the resulting collection
does not maintain its own sort order.
iterable - the elements to be copied and sorted
public <E extends T> E max(java.lang.Iterable<E> iterable)
iterable - the iterable whose maximum element is to be determined
java.util.NoSuchElementException - if iterable is empty
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.
public <E extends T> E max(E a,
E b,
E c,
E... rest)
a - value to compare, returned if greater than or equal to the rest.b - value to comparec - value to comparerest - values to compare
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.
public <E extends T> E max(E a,
E b)
a - value to compare, returned if greater than or equal to b.b - value to compare.
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.public <E extends T> E min(java.lang.Iterable<E> iterable)
iterable - the iterable whose minimum element is to be determined
java.util.NoSuchElementException - if iterable is empty
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.
public <E extends T> E min(E a,
E b,
E c,
E... rest)
a - value to compare, returned if less than or equal to the rest.b - value to comparec - value to comparerest - values to compare
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.
public <E extends T> E min(E a,
E b)
a - value to compare, returned if less than or equal to b.b - value to compare.
java.lang.ClassCastException - if the parameters are not mutually
comparable under this ordering.public Ordering<T> nullsFirst()
null as less than all other values
and uses this ordering to compare non-null values.
public Ordering<T> nullsLast()
null as greater than all other
values and uses this ordering to compare non-null values.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||