@Test public void testCheckDuplicatesDups() { _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Duplicate"); checkDuplicates("test", ImmutableList.of("a", "b", "a")); }
static void checkDuplicates(String objectType, List<String> list) { Map<String, Integer> counts = new HashMap<>(); list.forEach(e -> counts.put(e, counts.computeIfAbsent(e, v -> 0) + 1)); List<String> duplicates = counts.entrySet().stream() .filter(e -> e.getValue() > 1) .map(e -> e.getKey()) .collect(Collectors.toList()); checkArgument(duplicates.isEmpty(), "Duplicate %s name(s): %s", objectType, duplicates); }
ReferenceLibrary { static void checkDuplicates(String objectType, List<String> list) { Map<String, Integer> counts = new HashMap<>(); list.forEach(e -> counts.put(e, counts.computeIfAbsent(e, v -> 0) + 1)); List<String> duplicates = counts.entrySet().stream() .filter(e -> e.getValue() > 1) .map(e -> e.getKey()) .collect(Collectors.toList()); checkArgument(duplicates.isEmpty(), "Duplicate %s name(s): %s", objectType, duplicates); } }
ReferenceLibrary { static void checkDuplicates(String objectType, List<String> list) { Map<String, Integer> counts = new HashMap<>(); list.forEach(e -> counts.put(e, counts.computeIfAbsent(e, v -> 0) + 1)); List<String> duplicates = counts.entrySet().stream() .filter(e -> e.getValue() > 1) .map(e -> e.getKey()) .collect(Collectors.toList()); checkArgument(duplicates.isEmpty(), "Duplicate %s name(s): %s", objectType, duplicates); } @JsonCreator  ReferenceLibrary(@JsonProperty(PROP_BOOKS) @Nullable List<ReferenceBook> books); }
ReferenceLibrary { static void checkDuplicates(String objectType, List<String> list) { Map<String, Integer> counts = new HashMap<>(); list.forEach(e -> counts.put(e, counts.computeIfAbsent(e, v -> 0) + 1)); List<String> duplicates = counts.entrySet().stream() .filter(e -> e.getValue() > 1) .map(e -> e.getKey()) .collect(Collectors.toList()); checkArgument(duplicates.isEmpty(), "Duplicate %s name(s): %s", objectType, duplicates); } @JsonCreator  ReferenceLibrary(@JsonProperty(PROP_BOOKS) @Nullable List<ReferenceBook> books); void delAddressBook(String bookName); @Override boolean equals(@Nullable Object o); @Nonnull Optional<ReferenceBook> getReferenceBook(String bookName); @JsonProperty(PROP_BOOKS) @Nonnull SortedSet<ReferenceBook> getReferenceBooks(); @Override int hashCode(); @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks); }
ReferenceLibrary { static void checkDuplicates(String objectType, List<String> list) { Map<String, Integer> counts = new HashMap<>(); list.forEach(e -> counts.put(e, counts.computeIfAbsent(e, v -> 0) + 1)); List<String> duplicates = counts.entrySet().stream() .filter(e -> e.getValue() > 1) .map(e -> e.getKey()) .collect(Collectors.toList()); checkArgument(duplicates.isEmpty(), "Duplicate %s name(s): %s", objectType, duplicates); } @JsonCreator  ReferenceLibrary(@JsonProperty(PROP_BOOKS) @Nullable List<ReferenceBook> books); void delAddressBook(String bookName); @Override boolean equals(@Nullable Object o); @Nonnull Optional<ReferenceBook> getReferenceBook(String bookName); @JsonProperty(PROP_BOOKS) @Nonnull SortedSet<ReferenceBook> getReferenceBooks(); @Override int hashCode(); @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks);  }