1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| @Test public void testOrderingDetails() { Ordering ordering = Ordering.natural(); System.out.println(ordering.min(1, 5)); System.out.println(ordering.min(5, 4, 7, 8)); Iterable iterable = Iterables.concat(Lists.newArrayList(31, 5, 8, 49, 24)); System.out.println(ordering.min(iterable));
System.out.println(ordering.max(iterable));
System.out.println(ordering.binarySearch( Lists.newArrayList(14, 18, 19, 45, 76, 78), 45));
ordering = ordering.nullsFirst().onResultOf(new Function<Worker, String>() { @Override public String apply(Worker input) { return input.name; } }); List originList = Lists.newArrayList( new Worker("zl", 4), new Worker("sl", 34), new Worker("hp", 24), new Worker(null, 15), new Worker("app", 46), new Worker("lyh", 26)); List sortedList = ordering.sortedCopy(originList); System.out.println(sortedList); }
class Worker {
String name; int age;
public Worker(String name, int age) { this.name = name; this.age = age; }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("name", name) .add("age", age) .toString(); } }
|