@Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) { return Ordering.usingToString().compare(left.getParameters(), right.getParameters()); } };
public void testManyEqual() { assertEquals( 0, ComparisonChain.start() .compare(1, 1) .compare(1L, 1L) .compareFalseFirst(true, true) .compare(1.0, 1.0) .compare(1.0f, 1.0f) .compare("a", "a", Ordering.usingToString()) .result()); }
ApplicableFunction selectedFunction = Ordering.usingToString() .reverse() .sortedCopy(mostSpecificFunctions)
@GwtIncompatible // too slow public void testCombinationsExhaustively_startingFromUsingToString() { testExhaustively(Ordering.usingToString(), 1, 12, 2); }
public void testCreateExplicitComparators() { table = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); table.put("foo", 3, 'a'); table.put("foo", 12, 'b'); table.put("bar", 5, 'c'); table.put("cat", 8, 'd'); assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder(); assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder(); }
public void testRowMapComparator() { sortedTable = TreeBasedTable.create(); assertSame(Ordering.natural(), sortedTable.rowMap().comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); assertSame(Collections.reverseOrder(), sortedTable.rowMap().comparator()); }
public void testRowKeySetComparator() { sortedTable = TreeBasedTable.create(); assertSame(Ordering.natural(), sortedTable.rowKeySet().comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); assertSame(Collections.reverseOrder(), sortedTable.rowKeySet().comparator()); }
public void testColumnComparator() { sortedTable = TreeBasedTable.create(); sortedTable.put("", 42, 'x'); assertSame(Ordering.natural(), sortedTable.columnComparator()); assertSame( Ordering.natural(), ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next()) .comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); sortedTable.put("", 42, 'x'); assertSame(Ordering.usingToString(), sortedTable.columnComparator()); assertSame( Ordering.usingToString(), ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next()) .comparator()); }
public void testUsingToString() { Ordering<Object> ordering = Ordering.usingToString(); Helpers.testComparator(ordering, 1, 12, 124, 2); assertEquals("Ordering.usingToString()", ordering.toString()); assertSame(ordering, reserialize(ordering)); }
public void testRowComparator() { sortedTable = TreeBasedTable.create(); assertSame(Ordering.natural(), sortedTable.rowComparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); assertSame(Collections.reverseOrder(), sortedTable.rowComparator()); }
@GwtIncompatible // SerializableTester public void testSortedSerialization() { Multimap<String, Integer> multimap = new ImmutableSetMultimap.Builder<String, Integer>() .orderKeysBy(Ordering.natural().reverse()) .orderValuesBy(Ordering.usingToString()) .put("a", 2) .put("a", 10) .put("b", 1) .build(); multimap = SerializableTester.reserialize(multimap); assertThat(multimap.keySet()).containsExactly("b", "a").inOrder(); assertThat(multimap.get("a")).containsExactly(10, 2).inOrder(); assertEquals( Ordering.usingToString(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertEquals( Ordering.usingToString(), ((ImmutableSortedSet<Integer>) multimap.get("z")).comparator()); }
public void testCreateCopy() { TreeBasedTable<String, Integer, Character> original = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); original.put("foo", 3, 'a'); original.put("foo", 12, 'b'); original.put("bar", 5, 'c'); original.put("cat", 8, 'd'); table = TreeBasedTable.create(original); assertThat(table.rowKeySet()).containsExactly("foo", "cat", "bar").inOrder(); assertThat(table.row("foo").keySet()).containsExactly(12, 3).inOrder(); assertEquals(original, table); }
@GwtIncompatible // NullPointerTester public void testNullPointerExceptions() { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicStaticMethods(Ordering.class); // any Ordering<Object> instance that accepts nulls should be good enough tester.testAllPublicInstanceMethods(Ordering.usingToString().nullsFirst()); }
@Override public String toString() { @SuppressWarnings("unchecked") final Ordering<V> vertexOrdering = (Ordering) Ordering.usingToString(); @SuppressWarnings("unchecked") final Ordering<E> edgeOrdering = (Ordering) Ordering.usingToString(); return toString(vertexOrdering, edgeOrdering); }
@Nullable @Override public String apply(Function<T, String> f) { return Joiner.on(join).skipNulls().join(usingToString().nullsFirst().sortedCopy(newHashSet(transform(ts, f)))); } };
@Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) { return Ordering.usingToString().compare(left.getParameters(), right.getParameters()); } };
@Override public int compareTo(@Nonnull MethodProtoReference o) { int res = getReturnType().compareTo(o.getReturnType()); if (res != 0) return res; return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes()); }
@Override public int compareTo(@Nonnull MethodProtoReference o) { int res = getReturnType().compareTo(o.getReturnType()); if (res != 0) return res; return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes()); }
@Override public int compareTo(@Nonnull MethodReference o) { int res = getDefiningClass().compareTo(o.getDefiningClass()); if (res != 0) return res; res = getName().compareTo(o.getName()); if (res != 0) return res; res = getReturnType().compareTo(o.getReturnType()); if (res != 0) return res; return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes()); }
public void testUsingToString() { Ordering<Object> ordering = Ordering.usingToString(); Helpers.testComparator(ordering, 1, 12, 124, 2); assertEquals("Ordering.usingToString()", ordering.toString()); assertSame(ordering, reserialize(ordering)); }