@Test public void testMergeReferenceBooks() throws IOException { ReferenceLibrary library = new ReferenceLibrary( ImmutableList.of( ReferenceBook.builder("book1").build(), ReferenceBook.builder("book2").build())); SortedSet<ReferenceBook> newBooks = ImmutableSortedSet.of( ReferenceBook.builder("book1") .setAddressGroups( ImmutableList.of(new AddressGroup(ImmutableSortedSet.of(), "add1"))) .build(), ReferenceBook.builder("book3").build()); ReferenceLibrary merged = library.mergeReferenceBooks(newBooks); assertThat( merged.getReferenceBooks(), equalTo( ImmutableSortedSet.of( ReferenceBook.builder("book1") .setAddressGroups( ImmutableList.of(new AddressGroup(ImmutableSortedSet.of(), "add1"))) .build(), ReferenceBook.builder("book2").build(), ReferenceBook.builder("book3").build()))); }
public @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks) { List<ReferenceBook> booksToKeep = _books.stream() .filter( originalBook -> !newBooks.stream() .anyMatch(newBook -> newBook.getName().equals(originalBook.getName()))) .collect(Collectors.toList()); booksToKeep.addAll(newBooks); return new ReferenceLibrary(booksToKeep); }
ReferenceLibrary { public @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks) { List<ReferenceBook> booksToKeep = _books.stream() .filter( originalBook -> !newBooks.stream() .anyMatch(newBook -> newBook.getName().equals(originalBook.getName()))) .collect(Collectors.toList()); booksToKeep.addAll(newBooks); return new ReferenceLibrary(booksToKeep); } }
ReferenceLibrary { public @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks) { List<ReferenceBook> booksToKeep = _books.stream() .filter( originalBook -> !newBooks.stream() .anyMatch(newBook -> newBook.getName().equals(originalBook.getName()))) .collect(Collectors.toList()); booksToKeep.addAll(newBooks); return new ReferenceLibrary(booksToKeep); } @JsonCreator  ReferenceLibrary(@JsonProperty(PROP_BOOKS) @Nullable List<ReferenceBook> books); }
ReferenceLibrary { public @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks) { List<ReferenceBook> booksToKeep = _books.stream() .filter( originalBook -> !newBooks.stream() .anyMatch(newBook -> newBook.getName().equals(originalBook.getName()))) .collect(Collectors.toList()); booksToKeep.addAll(newBooks); return new ReferenceLibrary(booksToKeep); } @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 { public @Nonnull ReferenceLibrary mergeReferenceBooks(Collection<ReferenceBook> newBooks) { List<ReferenceBook> booksToKeep = _books.stream() .filter( originalBook -> !newBooks.stream() .anyMatch(newBook -> newBook.getName().equals(originalBook.getName()))) .collect(Collectors.toList()); booksToKeep.addAll(newBooks); return new ReferenceLibrary(booksToKeep); } @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);  }