@Override public int compare(Method left, Method right) { return ComparisonChain.start() .compare(left.getName(), right.getName()) .compare(left.getReturnType(), right.getReturnType(), CLASS_ORDERING) .compare( Arrays.asList(left.getParameterTypes()), Arrays.asList(right.getParameterTypes()), CLASS_ORDERING.lexicographical()) .result(); } };
@SuppressWarnings("unchecked") // dang varargs @Override <T> Scenario<?> mutate(Scenario<T> scenario) { List<Iterable<T>> words = Lists.newArrayList(); words.add(Collections.<T>emptyList()); for (T t : scenario.strictlyOrderedList) { words.add(Arrays.asList(t)); for (T s : scenario.strictlyOrderedList) { words.add(Arrays.asList(t, s)); } } return new Scenario<Iterable<T>>( scenario.ordering.lexicographical(), words, new Iterable[0]); } },
@SuppressWarnings("unchecked") // dang varargs public void testLexicographical() { Ordering<String> ordering = Ordering.natural(); Ordering<Iterable<String>> lexy = ordering.lexicographical(); ImmutableList<String> empty = ImmutableList.of(); ImmutableList<String> a = ImmutableList.of("a"); ImmutableList<String> aa = ImmutableList.of("a", "a"); ImmutableList<String> ab = ImmutableList.of("a", "b"); ImmutableList<String> b = ImmutableList.of("b"); Helpers.testComparator(lexy, empty, a, aa, ab, b); new EqualsTester() .addEqualityGroup(lexy, ordering.lexicographical()) .addEqualityGroup(numberOrdering.lexicographical()) .addEqualityGroup(Ordering.natural()) .testEquals(); }
public void testComplicatedOrderingExample() { Integer nullInt = (Integer) null; Ordering<Iterable<Integer>> example = Ordering.<Integer>natural().nullsFirst().reverse().lexicographical().reverse().nullsLast(); List<Integer> list1 = Lists.newArrayList(); List<Integer> list2 = Lists.newArrayList(1); List<Integer> list3 = Lists.newArrayList(1, 1); List<Integer> list4 = Lists.newArrayList(1, 2); List<Integer> list5 = Lists.newArrayList(1, null, 2); List<Integer> list6 = Lists.newArrayList(2); List<Integer> list7 = Lists.newArrayList(nullInt); List<Integer> list8 = Lists.newArrayList(nullInt, nullInt); List<List<Integer>> list = Lists.newArrayList(list1, list2, list3, list4, list5, list6, list7, list8, null); List<List<Integer>> sorted = example.sortedCopy(list); // [[null, null], [null], [1, null, 2], [1, 1], [1, 2], [1], [2], [], null] assertThat(sorted) .containsExactly( Lists.newArrayList(nullInt, nullInt), Lists.newArrayList(nullInt), Lists.newArrayList(1, null, 2), Lists.newArrayList(1, 1), Lists.newArrayList(1, 2), Lists.newArrayList(1), Lists.newArrayList(2), Lists.newArrayList(), null) .inOrder(); }
public void testCreation_arrayOfArray() { Comparator<String[]> comparator = Ordering.natural() .lexicographical() .onResultOf( new Function<String[], Iterable<Comparable>>() { @Override public Iterable<Comparable> apply(String[] input) { return Arrays.<Comparable>asList(input); } }); String[] array = new String[] {"a"}; Multiset<String[]> multiset = ImmutableSortedMultiset.orderedBy(comparator).add(array).build(); Multiset<String[]> expected = HashMultiset.create(); expected.add(array); assertEquals(expected, multiset); }
@Override public int compareTo(QualifiedName o) { return ComparisonChain.start() .compare(packageName, o.packageName) .compare(simpleNames, o.simpleNames, Ordering.natural().lexicographical()) .result(); }
@Override public int compareTo(Key o) { return ComparisonChain.start() .compare(values, o.values, Ordering.<Value>natural().lexicographical()) .result(); } }
@Override public int compare(Method left, Method right) { return ComparisonChain.start() .compare(left.getName(), right.getName()) .compare(left.getReturnType(), right.getReturnType(), CLASS_ORDERING) .compare( Arrays.asList(left.getParameterTypes()), Arrays.asList(right.getParameterTypes()), CLASS_ORDERING.lexicographical()) .result(); } };
@Override public int compare(Method left, Method right) { return ComparisonChain.start() .compare(left.getName(), right.getName()) .compare(left.getReturnType(), right.getReturnType(), CLASS_ORDERING) .compare( Arrays.asList(left.getParameterTypes()), Arrays.asList(right.getParameterTypes()), CLASS_ORDERING.lexicographical()) .result(); } };
@Override public int compareTo(AnnotationType other) { return ComparisonChain.start() .compare(this.name, other.getName()) .compare(this.packageName, other.getPackageName()) //FIXME: what is natural ordering for AnnotationType? .compare(this.annotations, other.getAnnotations(), Ordering.<AnnotationType>natural().lexicographical()) .compare(this.paramNames, other.getParameterNames(), Ordering.<String>natural().lexicographical()) .result(); }
private static boolean isBeforeCassandra12(CassandraThriftFacade cassandra) { // Cassandra 1.1.12 reports thrift version 19.33.0, Cassandra 1.2.0 (beta) reports 19.34.0. String thriftVersion = cassandra.describeVersion(); return Ordering.<Integer>natural().lexicographical().compare( Iterables.transform(Splitter.on('.').split(thriftVersion), new Function<String, Integer>() { @Override public Integer apply(String field) { return Integer.parseInt(field); } }), ImmutableList.of(19, 34) ) < 0; }
public int compareTo(SearchResult o) { int matchesDiff = Ordering.<SearchResultMatch>natural().lexicographical().compare(this.matches, o.matches); if(matchesDiff != 0) { return matchesDiff; } return searchMetadata.compareTo(o.searchMetadata); }
public int compareTo(SearchResult o) { int matchesDiff = Ordering.<SearchResultMatch>natural().lexicographical().compare(this.matches, o.matches); if(matchesDiff != 0) { return matchesDiff; } return searchMetadata.compareTo(o.searchMetadata); }
@Override public int compareTo(ContextMatch o) { return Ordering.from(MatchElement.Order.PRIORITY_ONLY) .lexicographical() .compound(Ordering.from(MatchElement.Order.PRIORITY_AND_DISTANCE) .lexicographical()) .compare(matchElements.reverse(), o.matchElements.reverse()); }
@Override public int compareTo(NameWithVersion o) { return Ordering.natural().lexicographical().compare(this.split(), o.split()); }
@Override public int compareTo(NameWithVersion o) { return Ordering.natural().lexicographical().compare(this.split(), o.split()); }
public int compare(MutableNode o1, MutableNode o2) { int c = Ordering.<String>natural().lexicographical().compare( o1.table.t.getQualifiedName(), o2.table.t.getQualifiedName()); if (c == 0) { // The nodes have the same table. Now compare them based on the // columns they use as foreign key. c = Ordering.<Integer>natural().lexicographical().compare( IntPair.left(o1.step.keys), IntPair.left(o2.step.keys)); } return c; } });
@SuppressWarnings("unchecked") // dang varargs @Override <T> Scenario<?> mutate(Scenario<T> scenario) { List<Iterable<T>> words = Lists.newArrayList(); words.add(Collections.<T>emptyList()); for (T t : scenario.strictlyOrderedList) { words.add(Arrays.asList(t)); for (T s : scenario.strictlyOrderedList) { words.add(Arrays.asList(t, s)); } } return new Scenario<Iterable<T>>( scenario.ordering.lexicographical(), words, new Iterable[0]); } },
@SuppressWarnings("unchecked") // dang varargs public void testLexicographical() { Ordering<String> ordering = Ordering.natural(); Ordering<Iterable<String>> lexy = ordering.lexicographical(); ImmutableList<String> empty = ImmutableList.of(); ImmutableList<String> a = ImmutableList.of("a"); ImmutableList<String> aa = ImmutableList.of("a", "a"); ImmutableList<String> ab = ImmutableList.of("a", "b"); ImmutableList<String> b = ImmutableList.of("b"); Helpers.testComparator(lexy, empty, a, aa, ab, b); new EqualsTester() .addEqualityGroup(lexy, ordering.lexicographical()) .addEqualityGroup(numberOrdering.lexicographical()) .addEqualityGroup(Ordering.natural()) .testEquals(); }
public void testCreation_arrayOfArray() { Comparator<String[]> comparator = Ordering.natural().lexicographical() .onResultOf(new Function<String[], Iterable<Comparable>>() { @Override public Iterable<Comparable> apply(String[] input) { return Arrays.<Comparable>asList(input); } }); String[] array = new String[] {"a"}; Multiset<String[]> multiset = ImmutableSortedMultiset.orderedBy(comparator).add(array).build(); Multiset<String[]> expected = HashMultiset.create(); expected.add(array); assertEquals(expected, multiset); }