Skip to content

Commit

Permalink
Add java 11 (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmak authored and iluwatar committed Oct 27, 2019
1 parent b50189e commit 63fb8dc
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@

package com.iluwatar.abstractdocument;

import java.util.Arrays;
import java.util.HashMap;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.enums.Property;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.List;
import java.util.Map;

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

var carProperties = new HashMap<String, Object>();
carProperties.put(Property.MODEL.toString(), "300SL");
carProperties.put(Property.PRICE.toString(), 10000L);

var wheelProperties = new HashMap<String, Object>();
wheelProperties.put(Property.TYPE.toString(), "wheel");
wheelProperties.put(Property.MODEL.toString(), "15C");
wheelProperties.put(Property.PRICE.toString(), 100L);
var wheelProperties = Map.of(
Property.TYPE.toString(), "wheel",
Property.MODEL.toString(), "15C",
Property.PRICE.toString(), 100L);

var doorProperties = new HashMap<String, Object>();
doorProperties.put(Property.TYPE.toString(), "door");
doorProperties.put(Property.MODEL.toString(), "Lambo");
doorProperties.put(Property.PRICE.toString(), 300L);
var doorProperties = Map.of(
Property.TYPE.toString(), "door",
Property.MODEL.toString(), "Lambo",
Property.PRICE.toString(), 300L);

carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));
var carProperties = Map.of(
Property.MODEL.toString(), "300SL",
Property.PRICE.toString(), 10000L,
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));

var car = new Car(carProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
import java.util.Map;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* AbstractDocument test class
Expand All @@ -60,9 +58,7 @@ public void shouldPutAndGetValue() {

@Test
public void shouldRetrieveChildren() {
Map<String, Object> child1 = new HashMap<>();
Map<String, Object> child2 = new HashMap<>();
List<Map<String, Object>> children = Arrays.asList(child1, child2);
var children = List.of(Map.of(), Map.of());

document.put(KEY, children);

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

@Test
public void shouldIncludePropsInToString() {
Map<String, Object> props = new HashMap<>();
props.put(KEY, VALUE);
Map<String, Object> props = Map.of(KEY, VALUE);
DocumentImplementation document = new DocumentImplementation(props);
assertTrue(document.toString().contains(KEY));
assertTrue(document.toString().contains(VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@

package com.iluwatar.abstractdocument;

import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.Part;
import com.iluwatar.abstractdocument.domain.enums.Property;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.Part;
import com.iluwatar.abstractdocument.domain.enums.Property;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test for Part and Car
Expand All @@ -49,10 +48,10 @@ public class DomainTest {

@Test
public void shouldConstructPart() {
Map<String, Object> partProperties = new HashMap<>();
partProperties.put(Property.TYPE.toString(), TEST_PART_TYPE);
partProperties.put(Property.MODEL.toString(), TEST_PART_MODEL);
partProperties.put(Property.PRICE.toString(), TEST_PART_PRICE);
Map<String, Object> partProperties = Map.of(
Property.TYPE.toString(), TEST_PART_TYPE,
Property.MODEL.toString(), TEST_PART_MODEL,
Property.PRICE.toString(), TEST_PART_PRICE);
Part part = new Part(partProperties);

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

@Test
public void shouldConstructCar() {
Map<String, Object> carProperties = new HashMap<>();
carProperties.put(Property.MODEL.toString(), TEST_CAR_MODEL);
carProperties.put(Property.PRICE.toString(), TEST_CAR_PRICE);
carProperties.put(Property.PARTS.toString(), Arrays.asList(new HashMap<>(), new HashMap<>()));
Map<String, Object> carProperties = Map.of(
Property.MODEL.toString(), TEST_CAR_MODEL,
Property.PRICE.toString(), TEST_CAR_PRICE,
Property.PARTS.toString(), List.of(new HashMap<>(), new HashMap<>()));
Car car = new Car(carProperties);

assertEquals(TEST_CAR_MODEL, car.getModel().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@

package com.iluwatar.collectionpipeline;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;

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

@Test
public void testGetModelsAfter2000UsingFor() {
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
var models = ImperativeProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}

@Test
public void testGetModelsAfter2000UsingPipeline() {
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
var models = FunctionalProgramming.getModelsAfter2000(cars);
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
}

@Test
public void testGetGroupingOfCarsByCategory() {
Map<Category, List<Car>> modelsExpected = new HashMap<>();
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN)));
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
var modelsExpected = Map.of(
Category.CONVERTIBLE, List.of(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)),
Category.SEDAN, List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN)),
Category.JEEP, List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
var modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
var modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
LOGGER.info("Category " + modelsFunctional);
assertEquals(modelsExpected, modelsFunctional);
assertEquals(modelsExpected, modelsImperative);
}

@Test
public void testGetSedanCarsOwnedSortedByDate() {
Person john = new Person(cars);
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
var john = new Person(cars);
var modelsExpected = List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Ford", "Focus", 2012, Category.SEDAN));
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
var modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
var modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
assertEquals(modelsExpected, modelsFunctional);
assertEquals(modelsExpected, modelsImperative);
}
Expand Down
8 changes: 3 additions & 5 deletions commander/src/main/java/com/iluwatar/commander/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@

package com.iluwatar.commander;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Random;
import java.util.*;

import com.iluwatar.commander.exceptions.DatabaseUnavailableException;

/**
Expand All @@ -49,7 +47,7 @@ public abstract class Service {

protected Service(Database db, Exception...exc) {
this.database = db;
this.exceptionsList = new ArrayList<Exception>(Arrays.asList(exc));
this.exceptionsList = new ArrayList<>(List.of(exc));
}

public abstract String receiveRequest(Object...parameters) throws DatabaseUnavailableException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

package com.iluwatar.commander.queue;

import java.util.ArrayList;
import java.util.Arrays;
import com.iluwatar.commander.Database;
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
import com.iluwatar.commander.exceptions.IsEmptyException;

import java.util.ArrayList;
import java.util.List;

/**
* QueueDatabase id where the instructions to be implemented are queued.
*/
Expand All @@ -39,8 +40,8 @@ public class QueueDatabase extends Database<QueueTask> {
public ArrayList<Exception> exceptionsList;

public QueueDatabase(Exception...exc) {
this.data = new Queue<QueueTask>();
this.exceptionsList = new ArrayList<Exception>(Arrays.asList(exc));
this.data = new Queue<>();
this.exceptionsList = new ArrayList<>(List.of(exc));
}

@Override
Expand Down
24 changes: 10 additions & 14 deletions commander/src/test/java/com/iluwatar/commander/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@

package com.iluwatar.commander;

import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.Arrays;
import org.junit.jupiter.api.Test;

import com.iluwatar.commander.Order;
import com.iluwatar.commander.Retry;
import com.iluwatar.commander.User;
import com.iluwatar.commander.Retry.HandleErrorIssue;
import com.iluwatar.commander.Retry.Operation;
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
import com.iluwatar.commander.exceptions.ItemUnavailableException;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertTrue;

class RetryTest {

Expand All @@ -55,15 +51,15 @@ void performTest() {
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
User user = new User("Jim", "ABCD");
Order order = new Order(user, "book", 10f);
ArrayList<Exception> arr1 = new ArrayList<Exception>(Arrays.asList(new Exception[]
{new ItemUnavailableException(), new DatabaseUnavailableException()}));
ArrayList<Exception> arr1 = new ArrayList<>(List.of(
new ItemUnavailableException(), new DatabaseUnavailableException()));
try {
r1.perform(arr1, order);
} catch (Exception e1) {
e1.printStackTrace();
}
ArrayList<Exception> arr2 = new ArrayList<Exception>(Arrays.asList(new Exception[]
{new DatabaseUnavailableException(), new ItemUnavailableException()}));
ArrayList<Exception> arr2 = new ArrayList<>(List.of(
new DatabaseUnavailableException(), new ItemUnavailableException()));
try {
r2.perform(arr2, order);
} catch (Exception e1) {
Expand Down
34 changes: 17 additions & 17 deletions composite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,27 @@ Then we have a messenger to carry messages
```java
public class Messenger {
LetterComposite messageFromOrcs() {
List<Word> words = new ArrayList<>();
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('a'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))));
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('a'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), new Letter('y'))));
List<Word> words = List.of(
new Word(List.of(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
new Word(List.of(new Letter('i'), new Letter('s'))),
new Word(List.of(new Letter('a'))),
new Word(List.of(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))),
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))),
new Word(List.of(new Letter('i'), new Letter('s'))),
new Word(List.of(new Letter('a'))),
new Word(List.of(new Letter('w'), new Letter('a'), new Letter('y'))));
return new Sentence(words);
}

LetterComposite messageFromElves() {
List<Word> words = new ArrayList<>();
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))));
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))));
words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'), new Letter('s'))));
words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))));
words.add(new Word(Arrays.asList(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))));
words.add(new Word(Arrays.asList(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
List<Word> words = List.of(
new Word(List.of(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))),
new Word(List.of(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))),
new Word(List.of(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'), new Letter('s'))),
new Word(List.of(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))),
new Word(List.of(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))),
new Word(List.of(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
return new Sentence(words);
}
}
Expand Down

0 comments on commit 63fb8dc

Please sign in to comment.