Пример #1
0
  public static Long save(Book book) {

    long id = book.getId() == null ? ++LAST_ADDED_ID : book.getId();

    book.setId(id);
    book.increaseVersion();

    int indexOf = STORE.indexOf(book);
    if (indexOf == -1) {
      STORE.add(book);
    } else {
      STORE.set(indexOf, book);
    }

    return id;
  }
Пример #2
0
 public static Book findBook(Long id) {
   for (Book b : STORE) {
     if (b.getId().equals(id)) {
       return b;
     }
   }
   return null;
 }