-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
package io.github.devopsws.demo.model; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public record Book (String id, String name, int pageCount, String authorId) { | ||
|
||
private static List<Book> books = Arrays.asList( | ||
private static List<Book> books = new ArrayList<Book>(Arrays.asList( | ||
new Book("book-1", "Effective Java", 416, "author-1"), | ||
new Book("book-2", "Hitchhiker's Guide to the Galaxy", 208, "author-2"), | ||
new Book("book-3", "Down Under", 436, "author-3") | ||
); | ||
)); | ||
|
||
public static Book getById(String id) { | ||
return books.stream() | ||
.filter(book -> book.id().equals(id)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
public static Book[] allBooks() { | ||
return books.toArray(new Book[]{}); | ||
} | ||
|
||
public static int addBook(Book b) { | ||
books.add(new Book(books.size()+"", b.name, b.pageCount, b.authorId)); | ||
return books.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters