Skip to content

Commit 63fb8dc

Browse files
leonmakiluwatar
authored andcommitted
Add java 11 (iluwatar#1048)
1 parent b50189e commit 63fb8dc

File tree

11 files changed

+117
-143
lines changed

11 files changed

+117
-143
lines changed

abstract-document/src/main/java/com/iluwatar/abstractdocument/App.java

+16-18
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323

2424
package com.iluwatar.abstractdocument;
2525

26-
import java.util.Arrays;
27-
import java.util.HashMap;
28-
26+
import com.iluwatar.abstractdocument.domain.Car;
27+
import com.iluwatar.abstractdocument.domain.enums.Property;
2928
import org.slf4j.Logger;
3029
import org.slf4j.LoggerFactory;
3130

32-
import com.iluwatar.abstractdocument.domain.Car;
33-
import com.iluwatar.abstractdocument.domain.enums.Property;
31+
import java.util.List;
32+
import java.util.Map;
3433

3534
/**
3635
* The Abstract Document pattern enables handling additional, non-static
@@ -52,21 +51,20 @@ public class App {
5251
public App() {
5352
LOGGER.info("Constructing parts and car");
5453

55-
var carProperties = new HashMap<String, Object>();
56-
carProperties.put(Property.MODEL.toString(), "300SL");
57-
carProperties.put(Property.PRICE.toString(), 10000L);
58-
59-
var wheelProperties = new HashMap<String, Object>();
60-
wheelProperties.put(Property.TYPE.toString(), "wheel");
61-
wheelProperties.put(Property.MODEL.toString(), "15C");
62-
wheelProperties.put(Property.PRICE.toString(), 100L);
54+
var wheelProperties = Map.of(
55+
Property.TYPE.toString(), "wheel",
56+
Property.MODEL.toString(), "15C",
57+
Property.PRICE.toString(), 100L);
6358

64-
var doorProperties = new HashMap<String, Object>();
65-
doorProperties.put(Property.TYPE.toString(), "door");
66-
doorProperties.put(Property.MODEL.toString(), "Lambo");
67-
doorProperties.put(Property.PRICE.toString(), 300L);
59+
var doorProperties = Map.of(
60+
Property.TYPE.toString(), "door",
61+
Property.MODEL.toString(), "Lambo",
62+
Property.PRICE.toString(), 300L);
6863

69-
carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));
64+
var carProperties = Map.of(
65+
Property.MODEL.toString(), "300SL",
66+
Property.PRICE.toString(), 10000L,
67+
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
7068

7169
var car = new Car(carProperties);
7270

abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java

+3-8
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
import java.util.Map;
3232
import java.util.stream.Stream;
3333

34-
import static org.junit.jupiter.api.Assertions.assertEquals;
35-
import static org.junit.jupiter.api.Assertions.assertNotNull;
36-
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.junit.jupiter.api.Assertions.*;
3735

3836
/**
3937
* AbstractDocument test class
@@ -60,9 +58,7 @@ public void shouldPutAndGetValue() {
6058

6159
@Test
6260
public void shouldRetrieveChildren() {
63-
Map<String, Object> child1 = new HashMap<>();
64-
Map<String, Object> child2 = new HashMap<>();
65-
List<Map<String, Object>> children = Arrays.asList(child1, child2);
61+
var children = List.of(Map.of(), Map.of());
6662

6763
document.put(KEY, children);
6864

@@ -80,8 +76,7 @@ public void shouldRetrieveEmptyStreamForNonExistingChildren() {
8076

8177
@Test
8278
public void shouldIncludePropsInToString() {
83-
Map<String, Object> props = new HashMap<>();
84-
props.put(KEY, VALUE);
79+
Map<String, Object> props = Map.of(KEY, VALUE);
8580
DocumentImplementation document = new DocumentImplementation(props);
8681
assertTrue(document.toString().contains(KEY));
8782
assertTrue(document.toString().contains(VALUE));

abstract-document/src/test/java/com/iluwatar/abstractdocument/DomainTest.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323

2424
package com.iluwatar.abstractdocument;
2525

26-
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import com.iluwatar.abstractdocument.domain.Car;
27+
import com.iluwatar.abstractdocument.domain.Part;
28+
import com.iluwatar.abstractdocument.domain.enums.Property;
29+
import org.junit.jupiter.api.Test;
2730

28-
import java.util.Arrays;
2931
import java.util.HashMap;
32+
import java.util.List;
3033
import java.util.Map;
3134

32-
import org.junit.jupiter.api.Test;
33-
34-
import com.iluwatar.abstractdocument.domain.Car;
35-
import com.iluwatar.abstractdocument.domain.Part;
36-
import com.iluwatar.abstractdocument.domain.enums.Property;
35+
import static org.junit.jupiter.api.Assertions.assertEquals;
3736

3837
/**
3938
* Test for Part and Car
@@ -49,10 +48,10 @@ public class DomainTest {
4948

5049
@Test
5150
public void shouldConstructPart() {
52-
Map<String, Object> partProperties = new HashMap<>();
53-
partProperties.put(Property.TYPE.toString(), TEST_PART_TYPE);
54-
partProperties.put(Property.MODEL.toString(), TEST_PART_MODEL);
55-
partProperties.put(Property.PRICE.toString(), TEST_PART_PRICE);
51+
Map<String, Object> partProperties = Map.of(
52+
Property.TYPE.toString(), TEST_PART_TYPE,
53+
Property.MODEL.toString(), TEST_PART_MODEL,
54+
Property.PRICE.toString(), TEST_PART_PRICE);
5655
Part part = new Part(partProperties);
5756

5857
assertEquals(TEST_PART_TYPE, part.getType().get());
@@ -62,10 +61,10 @@ public void shouldConstructPart() {
6261

6362
@Test
6463
public void shouldConstructCar() {
65-
Map<String, Object> carProperties = new HashMap<>();
66-
carProperties.put(Property.MODEL.toString(), TEST_CAR_MODEL);
67-
carProperties.put(Property.PRICE.toString(), TEST_CAR_PRICE);
68-
carProperties.put(Property.PARTS.toString(), Arrays.asList(new HashMap<>(), new HashMap<>()));
64+
Map<String, Object> carProperties = Map.of(
65+
Property.MODEL.toString(), TEST_CAR_MODEL,
66+
Property.PRICE.toString(), TEST_CAR_PRICE,
67+
Property.PARTS.toString(), List.of(new HashMap<>(), new HashMap<>()));
6968
Car car = new Car(carProperties);
7069

7170
assertEquals(TEST_CAR_MODEL, car.getModel().get());

collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java

+21-23
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323

2424
package com.iluwatar.collectionpipeline;
2525

26-
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import org.junit.jupiter.api.Test;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2729

28-
import java.util.Arrays;
29-
import java.util.HashMap;
3030
import java.util.List;
3131
import java.util.Map;
3232

33-
import org.junit.jupiter.api.Test;
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
3634

3735
/**
3836
* Tests that Collection Pipeline methods work as expected.
@@ -44,39 +42,39 @@ public class AppTest {
4442

4543
@Test
4644
public void testGetModelsAfter2000UsingFor() {
47-
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
48-
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
45+
var models = ImperativeProgramming.getModelsAfter2000(cars);
46+
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
4947
}
5048

5149
@Test
5250
public void testGetModelsAfter2000UsingPipeline() {
53-
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
54-
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
51+
var models = FunctionalProgramming.getModelsAfter2000(cars);
52+
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
5553
}
5654

5755
@Test
5856
public void testGetGroupingOfCarsByCategory() {
59-
Map<Category, List<Car>> modelsExpected = new HashMap<>();
60-
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
61-
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
62-
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
63-
new Car("Ford", "Focus", 2012, Category.SEDAN)));
64-
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
65-
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
66-
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
67-
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
57+
var modelsExpected = Map.of(
58+
Category.CONVERTIBLE, List.of(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
59+
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)),
60+
Category.SEDAN, List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
61+
new Car("Ford", "Focus", 2012, Category.SEDAN)),
62+
Category.JEEP, List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
63+
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
64+
var modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
65+
var modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
6866
LOGGER.info("Category " + modelsFunctional);
6967
assertEquals(modelsExpected, modelsFunctional);
7068
assertEquals(modelsExpected, modelsImperative);
7169
}
7270

7371
@Test
7472
public void testGetSedanCarsOwnedSortedByDate() {
75-
Person john = new Person(cars);
76-
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
73+
var john = new Person(cars);
74+
var modelsExpected = List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
7775
new Car("Ford", "Focus", 2012, Category.SEDAN));
78-
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
79-
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
76+
var modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
77+
var modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
8078
assertEquals(modelsExpected, modelsFunctional);
8179
assertEquals(modelsExpected, modelsImperative);
8280
}

commander/src/main/java/com/iluwatar/commander/Service.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323

2424
package com.iluwatar.commander;
2525

26-
import java.util.ArrayList;
27-
import java.util.Arrays;
28-
import java.util.Hashtable;
29-
import java.util.Random;
26+
import java.util.*;
27+
3028
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
3129

3230
/**
@@ -49,7 +47,7 @@ public abstract class Service {
4947

5048
protected Service(Database db, Exception...exc) {
5149
this.database = db;
52-
this.exceptionsList = new ArrayList<Exception>(Arrays.asList(exc));
50+
this.exceptionsList = new ArrayList<>(List.of(exc));
5351
}
5452

5553
public abstract String receiveRequest(Object...parameters) throws DatabaseUnavailableException;

commander/src/main/java/com/iluwatar/commander/queue/QueueDatabase.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323

2424
package com.iluwatar.commander.queue;
2525

26-
import java.util.ArrayList;
27-
import java.util.Arrays;
2826
import com.iluwatar.commander.Database;
2927
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
3028
import com.iluwatar.commander.exceptions.IsEmptyException;
3129

30+
import java.util.ArrayList;
31+
import java.util.List;
32+
3233
/**
3334
* QueueDatabase id where the instructions to be implemented are queued.
3435
*/
@@ -39,8 +40,8 @@ public class QueueDatabase extends Database<QueueTask> {
3940
public ArrayList<Exception> exceptionsList;
4041

4142
public QueueDatabase(Exception...exc) {
42-
this.data = new Queue<QueueTask>();
43-
this.exceptionsList = new ArrayList<Exception>(Arrays.asList(exc));
43+
this.data = new Queue<>();
44+
this.exceptionsList = new ArrayList<>(List.of(exc));
4445
}
4546

4647
@Override

commander/src/test/java/com/iluwatar/commander/RetryTest.java

+10-14
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@
2323

2424
package com.iluwatar.commander;
2525

26-
import static org.junit.jupiter.api.Assertions.*;
27-
import java.util.ArrayList;
28-
import java.util.Arrays;
29-
import org.junit.jupiter.api.Test;
30-
31-
import com.iluwatar.commander.Order;
32-
import com.iluwatar.commander.Retry;
33-
import com.iluwatar.commander.User;
34-
import com.iluwatar.commander.Retry.HandleErrorIssue;
35-
import com.iluwatar.commander.Retry.Operation;
3626
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
3727
import com.iluwatar.commander.exceptions.ItemUnavailableException;
28+
import org.junit.jupiter.api.Test;
29+
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3834

3935
class RetryTest {
4036

@@ -55,15 +51,15 @@ void performTest() {
5551
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
5652
User user = new User("Jim", "ABCD");
5753
Order order = new Order(user, "book", 10f);
58-
ArrayList<Exception> arr1 = new ArrayList<Exception>(Arrays.asList(new Exception[]
59-
{new ItemUnavailableException(), new DatabaseUnavailableException()}));
54+
ArrayList<Exception> arr1 = new ArrayList<>(List.of(
55+
new ItemUnavailableException(), new DatabaseUnavailableException()));
6056
try {
6157
r1.perform(arr1, order);
6258
} catch (Exception e1) {
6359
e1.printStackTrace();
6460
}
65-
ArrayList<Exception> arr2 = new ArrayList<Exception>(Arrays.asList(new Exception[]
66-
{new DatabaseUnavailableException(), new ItemUnavailableException()}));
61+
ArrayList<Exception> arr2 = new ArrayList<>(List.of(
62+
new DatabaseUnavailableException(), new ItemUnavailableException()));
6763
try {
6864
r2.perform(arr2, order);
6965
} catch (Exception e1) {

composite/README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,27 @@ Then we have a messenger to carry messages
9494
```java
9595
public class Messenger {
9696
LetterComposite messageFromOrcs() {
97-
List<Word> words = new ArrayList<>();
98-
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
99-
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
100-
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
101-
words.add(new Word(Arrays.asList(new Letter('a'))));
102-
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))));
103-
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
104-
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
105-
words.add(new Word(Arrays.asList(new Letter('a'))));
106-
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), new Letter('y'))));
97+
List<Word> words = List.of(
98+
new Word(List.of(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
99+
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
100+
new Word(List.of(new Letter('i'), new Letter('s'))),
101+
new Word(List.of(new Letter('a'))),
102+
new Word(List.of(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))),
103+
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
104+
new Word(List.of(new Letter('i'), new Letter('s'))),
105+
new Word(List.of(new Letter('a'))),
106+
new Word(List.of(new Letter('w'), new Letter('a'), new Letter('y'))));
107107
return new Sentence(words);
108108
}
109109

110110
LetterComposite messageFromElves() {
111-
List<Word> words = new ArrayList<>();
112-
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))));
113-
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))));
114-
words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'), new Letter('s'))));
115-
words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))));
116-
words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))));
117-
words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
111+
List<Word> words = List.of(
112+
new Word(List.of(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))),
113+
new Word(List.of(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))),
114+
new Word(List.of(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'), new Letter('s'))),
115+
new Word(List.of(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))),
116+
new Word(List.of(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))),
117+
new Word(List.of(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
118118
return new Sentence(words);
119119
}
120120
}

0 commit comments

Comments
 (0)