Skip to content

Commit f625ac7

Browse files
author
github-actions
committed
Google Java Format
1 parent 31f0445 commit f625ac7

File tree

5 files changed

+32
-40
lines changed

5 files changed

+32
-40
lines changed

Author.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
public record Author(String Name) {
2-
3-
}
1+
public record Author(String Name) {}

Book.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
public record Book(String title) {
2-
3-
4-
}
1+
public record Book(String title) {}

BookCollection.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@
66

77
public record BookCollection(HashMap<Author, List<Book>> collection) {
88

9-
public void addAuthor(Author author) throws DuplicateKeyException {
10-
if (collection.containsKey(author)) {
11-
throw new DuplicateKeyException();
12-
}
13-
14-
collection.put(author, new ArrayList<>());
9+
public void addAuthor(Author author) throws DuplicateKeyException {
10+
if (collection.containsKey(author)) {
11+
throw new DuplicateKeyException();
1512
}
1613

17-
public void addBook(Author author, Book book) {
18-
collection.get(author).add(book);
19-
}
14+
collection.put(author, new ArrayList<>());
15+
}
2016

21-
public Optional<Book> getBookByTitle(String title) {
22-
for (List<Book> books : collection.values()) {
23-
for (Book b : books) {
24-
if (b.title().equals(title)) {
25-
return Optional.of(b);
26-
}
27-
}
17+
public void addBook(Author author, Book book) {
18+
collection.get(author).add(book);
19+
}
20+
21+
public Optional<Book> getBookByTitle(String title) {
22+
for (List<Book> books : collection.values()) {
23+
for (Book b : books) {
24+
if (b.title().equals(title)) {
25+
return Optional.of(b);
2826
}
29-
return Optional.empty();
27+
}
3028
}
29+
return Optional.empty();
30+
}
3131

32-
public Optional<Author> getMostDiligentAuthor() {
33-
Author mostDiligentAuthor = null;
34-
int mostBooks = 0;
35-
for (Entry<Author, List<Book>> entry : collection.entrySet()) {
36-
if (entry.getValue().size() > mostBooks) {
37-
mostDiligentAuthor = entry.getKey();
38-
mostBooks = entry.getValue().size();
39-
}
40-
}
41-
return Optional.ofNullable(mostDiligentAuthor);
32+
public Optional<Author> getMostDiligentAuthor() {
33+
Author mostDiligentAuthor = null;
34+
int mostBooks = 0;
35+
for (Entry<Author, List<Book>> entry : collection.entrySet()) {
36+
if (entry.getValue().size() > mostBooks) {
37+
mostDiligentAuthor = entry.getKey();
38+
mostBooks = entry.getValue().size();
39+
}
4240
}
43-
}
41+
return Optional.ofNullable(mostDiligentAuthor);
42+
}
43+
}

DuplicateKeyException.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
public class DuplicateKeyException extends Exception {
22

3-
private static final long serialVersionUID = 1L;
4-
5-
}
3+
private static final long serialVersionUID = 1L;
4+
}

Exercise.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,5 @@ public static void main(String[] args) {
2323

2424
System.out.println(collection.getBookByTitle("Das Lied von Eis und Feuer 5"));
2525
System.out.println(collection.getMostDiligentAuthor());
26-
2726
}
28-
2927
}

0 commit comments

Comments
 (0)