public void testToImmutableListMultimap() { Collector<Entry<String, Integer>, ?, ImmutableListMultimap<String, Integer>> collector = ImmutableListMultimap.toImmutableListMultimap(Entry::getKey, Entry::getValue); BiPredicate<ImmutableListMultimap<?, ?>, ImmutableListMultimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((ImmutableListMultimap<?, ?> mm) -> mm.asMap().entrySet().asList()) .and(Equivalence.equals()); CollectorTester.of(collector, equivalence) .expectCollects(ImmutableListMultimap.of()) .expectCollects( ImmutableListMultimap.of("a", 1, "b", 2, "a", 3, "c", 4), mapEntry("a", 1), mapEntry("b", 2), mapEntry("a", 3), mapEntry("c", 4)); }
private void ensureNoDuplicatedRules(List<Rule> rules) throws DuplicatedRuleException { ImmutableList<Rule.Id> duplicatedIds = rules.stream() .collect(ImmutableListMultimap.toImmutableListMultimap( Rule::getId, Function.identity())) .asMap() .entrySet() .stream() .filter(entry -> entry.getValue().size() > 1) .map(Map.Entry::getKey) .collect(ImmutableList.toImmutableList()); if (!duplicatedIds.isEmpty()) { throw new DuplicatedRuleException(duplicatedIds); } }
public void testToImmutableListMultimap() { Collector<Entry<String, Integer>, ?, ImmutableListMultimap<String, Integer>> collector = ImmutableListMultimap.toImmutableListMultimap(Entry::getKey, Entry::getValue); BiPredicate<ImmutableListMultimap<?, ?>, ImmutableListMultimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((ImmutableListMultimap<?, ?> mm) -> mm.asMap().entrySet().asList()) .and(Equivalence.equals()); CollectorTester.of(collector, equivalence) .expectCollects(ImmutableListMultimap.of()) .expectCollects( ImmutableListMultimap.of("a", 1, "b", 2, "a", 3, "c", 4), mapEntry("a", 1), mapEntry("b", 2), mapEntry("a", 3), mapEntry("c", 4)); }