Skip to content

Commit b558643

Browse files
committed
review changes
1 parent c30b27b commit b558643

File tree

15 files changed

+104
-41
lines changed

15 files changed

+104
-41
lines changed

core-java/service-provider-interface/standard-library/pom.xml renamed to core-java/service-provider-interface/classics-library/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

12-
<artifactId>standard-library</artifactId>
12+
<artifactId>classics-library</artifactId>
1313

14-
<name>standard-library</name>
14+
<name>classics-library</name>
1515

1616
<properties>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

core-java/service-provider-interface/standard-library/src/main/java/org/library/StandardLibrary.java renamed to core-java/service-provider-interface/classics-library/src/main/java/org/library/ClassicsLibrary.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,29 @@
66
import org.library.spi.Book;
77
import org.library.spi.Library;
88

9-
public class StandardLibrary implements Library {
9+
public class ClassicsLibrary implements Library {
1010

11+
public static final String CLASSICS_LIBRARY = "CLASSICS";
1112
private final Map<String, Book> books;
1213

13-
public StandardLibrary() {
14+
public ClassicsLibrary() {
1415
books = new TreeMap<>();
1516
Book nineteenEightyFour = new Book("Nineteen Eighty-Four", "George Orwell",
1617
"It was a bright cold day in April, and the clocks were striking thirteen.");
1718
Book theLordOfTheRings = new Book("The Lord of the Rings", "J. R. R. Tolkien",
1819
"When Mr. Bilbo Baggins of Bag End announced that he would shortly be celebrating his " +
1920
"eleventy-first birthday with a party of special magnificence, there was much talk and excitement in Hobbiton.");
21+
Book cleanCode = new Book("Clean Code", "Robert C. Martin",
22+
"ClassicsEven bad code can function. But if code isn’t clean, it can bring a development organization to its knees");
2023

2124
books.put("Nineteen Eighty-Four", nineteenEightyFour);
2225
books.put("The Lord of the Rings", theLordOfTheRings);
26+
books.put("Clean Code", cleanCode);
27+
}
28+
29+
@Override
30+
public String getCategory() {
31+
return CLASSICS_LIBRARY;
2332
}
2433

2534
@Override
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.library.ClassicsLibrary

core-java/service-provider-interface/custom-library/pom.xml renamed to core-java/service-provider-interface/computer-science-library/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>org.library</groupId>
8-
<artifactId>custom-library</artifactId>
8+
<artifactId>computer-science-library</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

11-
<name>custom-library</name>
11+
<name>computer-science-library</name>
1212

1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

core-java/service-provider-interface/custom-library/src/main/java/org/library/CustomLibrary.java renamed to core-java/service-provider-interface/computer-science-library/src/main/java/org/library/ComputerScienceLibrary.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import org.library.spi.Book;
77
import org.library.spi.Library;
88

9-
public class CustomLibrary implements Library {
9+
public class ComputerScienceLibrary implements Library {
10+
11+
public static final String COMPUTER_SCIENCE_LIBRARY = "COMPUTER_SCIENCE";
1012

1113
private final Map<String, Book> books;
1214

13-
public CustomLibrary() {
15+
public ComputerScienceLibrary() {
1416
books = new TreeMap<>();
1517

1618
Book cleanCode = new Book("Clean Code", "Robert C. Martin",
@@ -22,6 +24,11 @@ public CustomLibrary() {
2224
books.put(pragmaticProgrammer.getName(), pragmaticProgrammer);
2325
}
2426

27+
@Override
28+
public String getCategory() {
29+
return COMPUTER_SCIENCE_LIBRARY;
30+
}
31+
2532
@Override
2633
public Book getBook(String name) {
2734
return books.get(name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.library.ComputerScienceLibrary

core-java/service-provider-interface/custom-library/src/main/resources/META-INF/services/org.library.spi.Library

Lines changed: 0 additions & 1 deletion
This file was deleted.

core-java/service-provider-interface/library-demo/pom.xml renamed to core-java/service-provider-interface/library-client/pom.xml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,47 @@
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

12-
<artifactId>library-demo</artifactId>
12+
<artifactId>library-client</artifactId>
1313

14-
<name>library-demo</name>
14+
<name>library-client</name>
1515

1616
<properties>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<maven.compiler.source>1.8</maven.compiler.source>
19-
<maven.compiler.target>1.8</maven.compiler.target>
18+
<maven.compiler.source>11</maven.compiler.source>
19+
<maven.compiler.target>11</maven.compiler.target>
2020
</properties>
2121

2222
<dependencies>
2323

24+
25+
<dependency>
26+
<groupId>org.library</groupId>
27+
<artifactId>computer-science-library</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
</dependency>
2430
<dependency>
2531
<groupId>org.library</groupId>
26-
<artifactId>standard-library</artifactId>
32+
<artifactId>classics-library</artifactId>
2733
<version>1.0-SNAPSHOT</version>
2834
</dependency>
2935
<dependency>
3036
<groupId>org.library</groupId>
31-
<artifactId>custom-library</artifactId>
37+
<artifactId>library-service-provider</artifactId>
3238
<version>1.0-SNAPSHOT</version>
3339
</dependency>
3440
</dependencies>
3541

42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<configuration>
48+
<source>11</source>
49+
<target>11</target>
50+
</configuration>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
3655
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.library;
2+
3+
public class LibraryClient {
4+
public static void main(String[] args) {
5+
LibraryService libraryService = LibraryService.getInstance();
6+
requestBook("Clean Code", libraryService);
7+
requestBook("The Lord of the Rings", libraryService);
8+
requestBook("The Lord of the Rings", "COMPUTER_SCIENCE", libraryService);
9+
}
10+
11+
private static void requestBook(String bookName, LibraryService library) {
12+
library.getBook(bookName)
13+
.ifPresentOrElse(book -> System.out.println("The book '" + bookName + "' was found, here are the details:" + book),
14+
() -> System.out.println("The library doesn't have the book '" + bookName + "' that you need."));
15+
}
16+
17+
private static void requestBook(String bookName,String category, LibraryService library) {
18+
library.getBook(bookName, category)
19+
.ifPresentOrElse(book -> System.out.println("The book '" + bookName + "' was found in " + category + ", here are the details:" + book),
20+
() -> System.out.println("The library " + category + " doesn't have the book '" + bookName + "' that you need."));
21+
}
22+
}

core-java/service-provider-interface/library-demo/src/main/java/org/library/LibraryDemo.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)