@SuppressWarnings({"unchecked"}) public boolean isSameParameterList(List<? extends TypeParameterElement> l1, List<? extends TypeParameterElement> l2) { // Cast is necessary because of a flaw in the API design of "PairwiseEquivalent", // a flaw that is even acknowledged in the source. // Our casts are safe because we're not trying to add elements to the list // and therefore can't violate the constraint. return typeEq.pairwise().equivalent((List<TypeParameterElement>) l1, (List<TypeParameterElement>) l2); }
@Override @SuppressWarnings({"unchecked"}) protected boolean doEquivalent(TypeParameterElement arg0, TypeParameterElement arg1) { // Casts are necessary due to flaw in pairwise equivalence implementation. return typeMirrorEq.pairwise().equivalent((List<TypeMirror>) arg0.getBounds(), (List<TypeMirror>) arg1.getBounds()); }
@SuppressWarnings("unchecked") // varargs public void testPairwiseEquivalent() { EquivalenceTester.of(Equivalence.equals().<String>pairwise()) .addEquivalenceGroup(ImmutableList.<String>of()) .addEquivalenceGroup(ImmutableList.of("a")) .addEquivalenceGroup(ImmutableList.of("b")) .addEquivalenceGroup(ImmutableList.of("a", "b"), ImmutableList.of("a", "b")) .test(); }
public void testToImmutableEnumMap() { Collector<Entry<AnEnum, Integer>, ?, ImmutableMap<AnEnum, Integer>> collector = Maps.toImmutableEnumMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableMap<AnEnum, Integer>> equivalence = Equivalence.equals().<Entry<AnEnum, Integer>>pairwise().onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableMap.of(AnEnum.A, 1, AnEnum.C, 2, AnEnum.E, 3), mapEntry(AnEnum.A, 1), mapEntry(AnEnum.C, 2), mapEntry(AnEnum.E, 3)); }
public void testToImmutableMap() { Collector<Entry<String, Integer>, ?, ImmutableMap<String, Integer>> collector = ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableMap.of("one", 1, "two", 2, "three", 3), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3)); }
public void testToImmutableMapMerging() { Collector<Entry<AnEnum, Integer>, ?, ImmutableMap<AnEnum, Integer>> collector = Maps.toImmutableEnumMap(Entry::getKey, Entry::getValue, Integer::sum); Equivalence<ImmutableMap<AnEnum, Integer>> equivalence = Equivalence.equals().<Entry<AnEnum, Integer>>pairwise().onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableMap.of(AnEnum.A, 1, AnEnum.B, 4, AnEnum.C, 3), mapEntry(AnEnum.A, 1), mapEntry(AnEnum.B, 2), mapEntry(AnEnum.C, 3), mapEntry(AnEnum.B, 2)); } }
public void testToImmutableMapMerging() { Collector<Entry<String, Integer>, ?, ImmutableMap<String, Integer>> collector = ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue, Integer::sum); Equivalence<ImmutableMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableMap.of("one", 1, "two", 4, "three", 3), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3), mapEntry("two", 2)); } }
public void testToImmutableSortedMapMerging() { Collector<Entry<String, Integer>, ?, ImmutableSortedMap<String, Integer>> collector = ImmutableSortedMap.toImmutableSortedMap( Comparator.naturalOrder(), Entry::getKey, Entry::getValue, Integer::sum); Equivalence<ImmutableMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableSortedMap.of("one", 1, "three", 3, "two", 4), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3), mapEntry("two", 2)); } }
public void testToTableNullMerge() { Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector = Tables.toTable( Cell::getRowKey, Cell::getColumnKey, Cell::getValue, (Integer v1, Integer v2) -> null, HashBasedTable::create); Equivalence<Table<String, String, Integer>> equivalence = Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableTable.of(), Tables.immutableCell("one", "uno", 1), Tables.immutableCell("one", "uno", 2)); }
public void testToImmutableBiMap() { Collector<Entry<String, Integer>, ?, ImmutableBiMap<String, Integer>> collector = ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableBiMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableBiMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableBiMap.of("one", 1, "two", 2, "three", 3), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3)); }
public void testToTable() { Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector = Tables.toTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue, HashBasedTable::create); Equivalence<Table<String, String, Integer>> equivalence = Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet); CollectorTester.of(collector, equivalence) .expectCollects( new ImmutableTable.Builder<String, String, Integer>() .put("one", "uno", 1) .put("two", "dos", 2) .put("three", "tres", 3) .build(), Tables.immutableCell("one", "uno", 1), Tables.immutableCell("two", "dos", 2), Tables.immutableCell("three", "tres", 3)); }
public void testToImmutableTable() { Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector = ImmutableTable.toImmutableTable(Cell::getRowKey, Cell::getColumnKey, Cell::getValue); Equivalence<ImmutableTable<String, String, Integer>> equivalence = Equivalence.equals() .<Cell<String, String, Integer>>pairwise() .onResultOf(ImmutableTable::cellSet); CollectorTester.of(collector, equivalence) .expectCollects( new ImmutableTable.Builder<String, String, Integer>() .put("one", "uno", 1) .put("two", "dos", 2) .put("three", "tres", 3) .build(), Tables.immutableCell("one", "uno", 1), Tables.immutableCell("two", "dos", 2), Tables.immutableCell("three", "tres", 3)); }
public void testToImmutableTableMerging() { Collector<Cell<String, String, Integer>, ?, ImmutableTable<String, String, Integer>> collector = ImmutableTable.toImmutableTable( Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum); Equivalence<ImmutableTable<String, String, Integer>> equivalence = Equivalence.equals() .<Cell<String, String, Integer>>pairwise() .onResultOf(ImmutableTable::cellSet); CollectorTester.of(collector, equivalence) .expectCollects( new ImmutableTable.Builder<String, String, Integer>() .put("one", "uno", 1) .put("two", "dos", 6) .put("three", "tres", 3) .build(), Tables.immutableCell("one", "uno", 1), Tables.immutableCell("two", "dos", 2), Tables.immutableCell("three", "tres", 3), Tables.immutableCell("two", "dos", 4)); }
public void testToTableMerging() { Collector<Cell<String, String, Integer>, ?, Table<String, String, Integer>> collector = Tables.toTable( Cell::getRowKey, Cell::getColumnKey, Cell::getValue, Integer::sum, HashBasedTable::create); Equivalence<Table<String, String, Integer>> equivalence = Equivalence.equals().<Cell<String, String, Integer>>pairwise().onResultOf(Table::cellSet); CollectorTester.of(collector, equivalence) .expectCollects( new ImmutableTable.Builder<String, String, Integer>() .put("one", "uno", 1) .put("two", "dos", 6) .put("three", "tres", 3) .build(), Tables.immutableCell("one", "uno", 1), Tables.immutableCell("two", "dos", 2), Tables.immutableCell("three", "tres", 3), Tables.immutableCell("two", "dos", 4)); }
@Override protected int doHash(AnnotationMirror annotation) { DeclaredType type = annotation.getAnnotationType(); Iterable<AnnotationValue> annotationValues = getAnnotationValuesWithDefaults(annotation).values(); return Arrays.hashCode(new int[] {MoreTypes.equivalence().hash(type), AnnotationValues.equivalence().pairwise().hash(annotationValues)}); } };
@Override protected boolean doEquivalent(AnnotationMirror left, AnnotationMirror right) { return MoreTypes.equivalence().equivalent(left.getAnnotationType(), right.getAnnotationType()) && AnnotationValues.equivalence().pairwise().equivalent( getAnnotationValuesWithDefaults(left).values(), getAnnotationValuesWithDefaults(right).values()); } @Override
public void testToImmutableEnumMap() { Collector<Entry<AnEnum, Integer>, ?, ImmutableMap<AnEnum, Integer>> collector = Maps.toImmutableEnumMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableMap<AnEnum, Integer>> equivalence = Equivalence.equals().<Entry<AnEnum, Integer>>pairwise().onResultOf(ImmutableMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableMap.of(AnEnum.A, 1, AnEnum.C, 2, AnEnum.E, 3), mapEntry(AnEnum.A, 1), mapEntry(AnEnum.C, 2), mapEntry(AnEnum.E, 3)); }
public void testToImmutableBiMap() { Collector<Entry<String, Integer>, ?, ImmutableBiMap<String, Integer>> collector = ImmutableBiMap.toImmutableBiMap(Entry::getKey, Entry::getValue); Equivalence<ImmutableBiMap<String, Integer>> equivalence = Equivalence.equals() .<Entry<String, Integer>>pairwise() .onResultOf(ImmutableBiMap::entrySet); CollectorTester.of(collector, equivalence) .expectCollects( ImmutableBiMap.of("one", 1, "two", 2, "three", 3), mapEntry("one", 1), mapEntry("two", 2), mapEntry("three", 3)); }