鍍金池/ 教程/ Java/ Guava Ordering類
Guava原語(yǔ)工具
Guava集合工具
Guava Chars類
Guava Shorts類
Guava CharMatcher類
Guava BigIntegerMath類
Guava Range類
Guava Bimap接口
Guava緩存工具
Guava Longs類
Guava Multiset接口
Guava Table接口
Guava Optional類
Guava LongMath類
Guava Spiltter類
Guava Preconditions類
Guava數(shù)學(xué)工具
Guava Ints類
Guava Ordering類
Guava Throwables類
Guava字符串工具
Guava Objects類
Guava Booleans類
Guava教程
Guava Bytes類
Guava CaseFormat類
Guava環(huán)境設(shè)置
Guava Doubles類
Guava Joiner類
Guava Multimap類
Guava Floats類
Guava IntMath類

Guava Ordering類

Ordering(排序)可以被看作是一個(gè)豐富的比較具有增強(qiáng)功能的鏈接,多個(gè)實(shí)用方法,多類型排序功能等。

類聲明

以下是com.google.common.collect.Ordering<T>類的聲明:

@GwtCompatible
public abstract class Ordering<T>
   extends Object
      implements Comparator<T>

類方法

S.N. 方法及說(shuō)明
1 static Ordering<Object> allEqual()
返回一個(gè)排序,它把所有的值相等,說(shuō)明“沒有順序。”通過(guò)這個(gè)順序以任何穩(wěn)定的排序算法的結(jié)果,在改變沒有?順序元素。
2 static Ordering<Object> arbitrary()
返回一個(gè)任意順序?qū)λ袑?duì)象,其中compare(a, b) == 0 意味著a == b(身份平等)。
3 int binarySearch(List<? extends T> sortedList, T key)
搜索排序列表使用鍵的二進(jìn)制搜索算法。
4 abstract int compare(T left, T right)
比較兩個(gè)參數(shù)的順序。
5 <U extends T> Ordering<U> compound(Comparator<? super U> secondaryComparator)
返回首先使用排序這一點(diǎn),但它排序中的“tie”,然后委托給secondaryComparator事件。
6 static <T> Ordering<T> compound(Iterable<? extends Comparator<? super T>> comparators)
返回一個(gè)排序它嘗試每個(gè)給定的比較器,以便直到一個(gè)非零結(jié)果找到,返回該結(jié)果,并返回零僅當(dāng)所有比較器返回零。
7 static <T> Ordering<T> explicit(List<T> valuesInOrder)
返回根據(jù)它們出現(xiàn)的定列表中的順序比較對(duì)象進(jìn)行排序。
8 static <T> Ordering<T> explicit(T leastValue, T... remainingValuesInOrder)
返回根據(jù)它們所賦予本方法的順序進(jìn)行比較的對(duì)象進(jìn)行排序。
9 static <T> Ordering<T> from(Comparator<T> comparator)
返回基于現(xiàn)有的比較實(shí)例進(jìn)行排序。
10 <E extends T> List<E> greatestOf(Iterable<E> iterable, int k)
返回根據(jù)這個(gè)順序給出迭代,為了從最大到最小的k個(gè)最大的元素。
11 <E extends T> List<E> greatestOf(Iterator<E> iterator, int k)
返回從給定的迭代器按照這個(gè)順序,從最大到最小k個(gè)最大的元素。
12 <E extends T> ImmutableList<E> immutableSortedCopy(Iterable<E> elements)
返回包含的元素排序這種排序的不可變列表。
13 boolean isOrdered(Iterable<? extends T> iterable) 
返回true如果在迭代后的第一個(gè)的每個(gè)元素是大于或等于在它之前,根據(jù)該排序的元素。
14 boolean isStrictlyOrdered(Iterable<? extends T> iterable)
返回true如果在迭代后的第一個(gè)的每個(gè)元素是嚴(yán)格比在它之前,根據(jù)該排序的元素更大。
15 <E extends T> List<E> leastOf(Iterable<E> iterable, int k)
返回根據(jù)這個(gè)順序給出迭代,從而從低到最大的k個(gè)最低的元素。
16 <E extends T> List<E> leastOf(Iterator<E> elements, int k)
返回第k從給定的迭代器,按照這個(gè)順序從最低到最大至少元素。
   
17 <S extends T> Ordering<Iterable<S>> lexicographical()
返回一個(gè)新的排序它通過(guò)比較對(duì)應(yīng)元素兩兩直到非零結(jié)果發(fā)現(xiàn)排序迭代;規(guī)定“字典順序”。
18 <E extends T> E max(E a, E b)
返回兩個(gè)值按照這個(gè)順序的較大值。
19 <E extends T> E max(E a, E b, E c, E... rest)
返回指定的值,根據(jù)這個(gè)順序是最大的。
20 <E extends T> E max(Iterable<E> iterable)
返回指定的值,根據(jù)這個(gè)順序是最大的。
21 <E extends T> E max(Iterator<E> iterator)
返回指定的值,根據(jù)這個(gè)順序是最大的。
22 <E extends T> E min(E a, E b)
返回兩個(gè)值按照這個(gè)順序的較小者。
23 <E extends T> E min(E a, E b, E c, E... rest)
返回最少指定的值,根據(jù)這個(gè)順序。
24 <E extends T> E min(Iterable<E> iterable)
返回最少指定的值,根據(jù)這個(gè)順序。
25 <E extends T> E min(Iterator<E> iterator)
返回最少指定的值,根據(jù)這個(gè)順序。
26 static <C extends Comparable> Ordering<C> natural()
返回使用值的自然順序排序序列化。
27 <S extends T> Ordering<S> nullsFirst()
返回對(duì)待null小于所有其他值,并使用此來(lái)比較非空值排序。
28 <S extends T> Ordering<S> nullsLast()
返回對(duì)待null作為大于所有其他值,并使用這個(gè)順序來(lái)比較非空值排序。
29 <F> Ordering<F> onResultOf(Function<F,? extends T> function)
返回一個(gè)新的排序在F上,首先應(yīng)用功能給它們,然后比較使用此這些結(jié)果的順序元素。
30 <S extends T> Ordering<S> reverse()
返回相反順序; 順序相當(dāng)于Collections.reverseOrder(Comparator)。
31 <E extends T> List<E> sortedCopy(Iterable<E> elements)
返回包含的元素排序此排序可變列表;使用這個(gè)只有在結(jié)果列表可能需要進(jìn)一步修改,或可能包含null。
32 static Ordering<Object> usingToString()
返回由它們的字符串表示的自然順序,toString()比較對(duì)象進(jìn)行排序。

方法繼承

這個(gè)類從以下類繼承的方法:

  • java.lang.Object

Ordering 示例

使用所選擇的編輯器,創(chuàng)建下面的java程序比如 C:/> Guava

GuavaTester.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Ordering;

public class GuavaTester {
   public static void main(String args[]){
      List<Integer> numbers = new ArrayList<Integer>();
      numbers.add(new Integer(5));
      numbers.add(new Integer(2));
      numbers.add(new Integer(15));
      numbers.add(new Integer(51));
      numbers.add(new Integer(53));
      numbers.add(new Integer(35));
      numbers.add(new Integer(45));
      numbers.add(new Integer(32));
      numbers.add(new上一篇:Guava IntMath類下一篇:Guava Bimap接口