Add java 11 (#1048)
This commit is contained in:
parent
b50189e283
commit
63fb8dc318
@ -23,14 +23,13 @@
|
|||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import com.iluwatar.abstractdocument.domain.Car;
|
||||||
import java.util.HashMap;
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.domain.Car;
|
import java.util.List;
|
||||||
import com.iluwatar.abstractdocument.domain.enums.Property;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Abstract Document pattern enables handling additional, non-static
|
* The Abstract Document pattern enables handling additional, non-static
|
||||||
@ -52,21 +51,20 @@ public class App {
|
|||||||
public App() {
|
public App() {
|
||||||
LOGGER.info("Constructing parts and car");
|
LOGGER.info("Constructing parts and car");
|
||||||
|
|
||||||
var carProperties = new HashMap<String, Object>();
|
var wheelProperties = Map.of(
|
||||||
carProperties.put(Property.MODEL.toString(), "300SL");
|
Property.TYPE.toString(), "wheel",
|
||||||
carProperties.put(Property.PRICE.toString(), 10000L);
|
Property.MODEL.toString(), "15C",
|
||||||
|
Property.PRICE.toString(), 100L);
|
||||||
|
|
||||||
var wheelProperties = new HashMap<String, Object>();
|
var doorProperties = Map.of(
|
||||||
wheelProperties.put(Property.TYPE.toString(), "wheel");
|
Property.TYPE.toString(), "door",
|
||||||
wheelProperties.put(Property.MODEL.toString(), "15C");
|
Property.MODEL.toString(), "Lambo",
|
||||||
wheelProperties.put(Property.PRICE.toString(), 100L);
|
Property.PRICE.toString(), 300L);
|
||||||
|
|
||||||
var doorProperties = new HashMap<String, Object>();
|
var carProperties = Map.of(
|
||||||
doorProperties.put(Property.TYPE.toString(), "door");
|
Property.MODEL.toString(), "300SL",
|
||||||
doorProperties.put(Property.MODEL.toString(), "Lambo");
|
Property.PRICE.toString(), 10000L,
|
||||||
doorProperties.put(Property.PRICE.toString(), 300L);
|
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
||||||
|
|
||||||
carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));
|
|
||||||
|
|
||||||
var car = new Car(carProperties);
|
var car = new Car(carProperties);
|
||||||
|
|
||||||
|
@ -31,9 +31,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractDocument test class
|
* AbstractDocument test class
|
||||||
@ -60,9 +58,7 @@ public class AbstractDocumentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldRetrieveChildren() {
|
public void shouldRetrieveChildren() {
|
||||||
Map<String, Object> child1 = new HashMap<>();
|
var children = List.of(Map.of(), Map.of());
|
||||||
Map<String, Object> child2 = new HashMap<>();
|
|
||||||
List<Map<String, Object>> children = Arrays.asList(child1, child2);
|
|
||||||
|
|
||||||
document.put(KEY, children);
|
document.put(KEY, children);
|
||||||
|
|
||||||
@ -80,8 +76,7 @@ public class AbstractDocumentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIncludePropsInToString() {
|
public void shouldIncludePropsInToString() {
|
||||||
Map<String, Object> props = new HashMap<>();
|
Map<String, Object> props = Map.of(KEY, VALUE);
|
||||||
props.put(KEY, VALUE);
|
|
||||||
DocumentImplementation document = new DocumentImplementation(props);
|
DocumentImplementation document = new DocumentImplementation(props);
|
||||||
assertTrue(document.toString().contains(KEY));
|
assertTrue(document.toString().contains(KEY));
|
||||||
assertTrue(document.toString().contains(VALUE));
|
assertTrue(document.toString().contains(VALUE));
|
||||||
|
@ -23,17 +23,16 @@
|
|||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.domain.Car;
|
import com.iluwatar.abstractdocument.domain.Car;
|
||||||
import com.iluwatar.abstractdocument.domain.Part;
|
import com.iluwatar.abstractdocument.domain.Part;
|
||||||
import com.iluwatar.abstractdocument.domain.enums.Property;
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for Part and Car
|
* Test for Part and Car
|
||||||
@ -49,10 +48,10 @@ public class DomainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConstructPart() {
|
public void shouldConstructPart() {
|
||||||
Map<String, Object> partProperties = new HashMap<>();
|
Map<String, Object> partProperties = Map.of(
|
||||||
partProperties.put(Property.TYPE.toString(), TEST_PART_TYPE);
|
Property.TYPE.toString(), TEST_PART_TYPE,
|
||||||
partProperties.put(Property.MODEL.toString(), TEST_PART_MODEL);
|
Property.MODEL.toString(), TEST_PART_MODEL,
|
||||||
partProperties.put(Property.PRICE.toString(), TEST_PART_PRICE);
|
Property.PRICE.toString(), TEST_PART_PRICE);
|
||||||
Part part = new Part(partProperties);
|
Part part = new Part(partProperties);
|
||||||
|
|
||||||
assertEquals(TEST_PART_TYPE, part.getType().get());
|
assertEquals(TEST_PART_TYPE, part.getType().get());
|
||||||
@ -62,10 +61,10 @@ public class DomainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConstructCar() {
|
public void shouldConstructCar() {
|
||||||
Map<String, Object> carProperties = new HashMap<>();
|
Map<String, Object> carProperties = Map.of(
|
||||||
carProperties.put(Property.MODEL.toString(), TEST_CAR_MODEL);
|
Property.MODEL.toString(), TEST_CAR_MODEL,
|
||||||
carProperties.put(Property.PRICE.toString(), TEST_CAR_PRICE);
|
Property.PRICE.toString(), TEST_CAR_PRICE,
|
||||||
carProperties.put(Property.PARTS.toString(), Arrays.asList(new HashMap<>(), new HashMap<>()));
|
Property.PARTS.toString(), List.of(new HashMap<>(), new HashMap<>()));
|
||||||
Car car = new Car(carProperties);
|
Car car = new Car(carProperties);
|
||||||
|
|
||||||
assertEquals(TEST_CAR_MODEL, car.getModel().get());
|
assertEquals(TEST_CAR_MODEL, car.getModel().get());
|
||||||
|
@ -23,17 +23,15 @@
|
|||||||
|
|
||||||
package com.iluwatar.collectionpipeline;
|
package com.iluwatar.collectionpipeline;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that Collection Pipeline methods work as expected.
|
* Tests that Collection Pipeline methods work as expected.
|
||||||
*/
|
*/
|
||||||
@ -44,27 +42,27 @@ public class AppTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetModelsAfter2000UsingFor() {
|
public void testGetModelsAfter2000UsingFor() {
|
||||||
List<String> models = ImperativeProgramming.getModelsAfter2000(cars);
|
var models = ImperativeProgramming.getModelsAfter2000(cars);
|
||||||
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetModelsAfter2000UsingPipeline() {
|
public void testGetModelsAfter2000UsingPipeline() {
|
||||||
List<String> models = FunctionalProgramming.getModelsAfter2000(cars);
|
var models = FunctionalProgramming.getModelsAfter2000(cars);
|
||||||
assertEquals(Arrays.asList("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
assertEquals(List.of("Avenger", "Wrangler", "Focus", "Cascada"), models);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupingOfCarsByCategory() {
|
public void testGetGroupingOfCarsByCategory() {
|
||||||
Map<Category, List<Car>> modelsExpected = new HashMap<>();
|
var modelsExpected = Map.of(
|
||||||
modelsExpected.put(Category.CONVERTIBLE, Arrays.asList(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
|
Category.CONVERTIBLE, List.of(new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
|
||||||
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)));
|
new Car("Chevrolet", "Geo Metro", 1992, Category.CONVERTIBLE)),
|
||||||
modelsExpected.put(Category.SEDAN, Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
Category.SEDAN, List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
||||||
new Car("Ford", "Focus", 2012, Category.SEDAN)));
|
new Car("Ford", "Focus", 2012, Category.SEDAN)),
|
||||||
modelsExpected.put(Category.JEEP, Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
|
Category.JEEP, List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
|
||||||
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
|
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
|
||||||
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
|
var modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
|
||||||
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
|
var modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
|
||||||
LOGGER.info("Category " + modelsFunctional);
|
LOGGER.info("Category " + modelsFunctional);
|
||||||
assertEquals(modelsExpected, modelsFunctional);
|
assertEquals(modelsExpected, modelsFunctional);
|
||||||
assertEquals(modelsExpected, modelsImperative);
|
assertEquals(modelsExpected, modelsImperative);
|
||||||
@ -72,11 +70,11 @@ public class AppTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSedanCarsOwnedSortedByDate() {
|
public void testGetSedanCarsOwnedSortedByDate() {
|
||||||
Person john = new Person(cars);
|
var john = new Person(cars);
|
||||||
List<Car> modelsExpected = Arrays.asList(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
var modelsExpected = List.of(new Car("Dodge", "Avenger", 2010, Category.SEDAN),
|
||||||
new Car("Ford", "Focus", 2012, Category.SEDAN));
|
new Car("Ford", "Focus", 2012, Category.SEDAN));
|
||||||
List<Car> modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
|
var modelsFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
|
||||||
List<Car> modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
|
var modelsImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
|
||||||
assertEquals(modelsExpected, modelsFunctional);
|
assertEquals(modelsExpected, modelsFunctional);
|
||||||
assertEquals(modelsExpected, modelsImperative);
|
assertEquals(modelsExpected, modelsImperative);
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,8 @@
|
|||||||
|
|
||||||
package com.iluwatar.commander;
|
package com.iluwatar.commander;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.Random;
|
|
||||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +47,7 @@ public abstract class Service {
|
|||||||
|
|
||||||
protected Service(Database db, Exception...exc) {
|
protected Service(Database db, Exception...exc) {
|
||||||
this.database = db;
|
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;
|
public abstract String receiveRequest(Object...parameters) throws DatabaseUnavailableException;
|
||||||
|
@ -23,12 +23,13 @@
|
|||||||
|
|
||||||
package com.iluwatar.commander.queue;
|
package com.iluwatar.commander.queue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import com.iluwatar.commander.Database;
|
import com.iluwatar.commander.Database;
|
||||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||||
import com.iluwatar.commander.exceptions.IsEmptyException;
|
import com.iluwatar.commander.exceptions.IsEmptyException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QueueDatabase id where the instructions to be implemented are queued.
|
* QueueDatabase id where the instructions to be implemented are queued.
|
||||||
*/
|
*/
|
||||||
@ -39,8 +40,8 @@ public class QueueDatabase extends Database<QueueTask> {
|
|||||||
public ArrayList<Exception> exceptionsList;
|
public ArrayList<Exception> exceptionsList;
|
||||||
|
|
||||||
public QueueDatabase(Exception...exc) {
|
public QueueDatabase(Exception...exc) {
|
||||||
this.data = new Queue<QueueTask>();
|
this.data = new Queue<>();
|
||||||
this.exceptionsList = new ArrayList<Exception>(Arrays.asList(exc));
|
this.exceptionsList = new ArrayList<>(List.of(exc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,18 +23,14 @@
|
|||||||
|
|
||||||
package com.iluwatar.commander;
|
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.DatabaseUnavailableException;
|
||||||
import com.iluwatar.commander.exceptions.ItemUnavailableException;
|
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 {
|
class RetryTest {
|
||||||
|
|
||||||
@ -55,15 +51,15 @@ class RetryTest {
|
|||||||
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
|
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
|
||||||
User user = new User("Jim", "ABCD");
|
User user = new User("Jim", "ABCD");
|
||||||
Order order = new Order(user, "book", 10f);
|
Order order = new Order(user, "book", 10f);
|
||||||
ArrayList<Exception> arr1 = new ArrayList<Exception>(Arrays.asList(new Exception[]
|
ArrayList<Exception> arr1 = new ArrayList<>(List.of(
|
||||||
{new ItemUnavailableException(), new DatabaseUnavailableException()}));
|
new ItemUnavailableException(), new DatabaseUnavailableException()));
|
||||||
try {
|
try {
|
||||||
r1.perform(arr1, order);
|
r1.perform(arr1, order);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
ArrayList<Exception> arr2 = new ArrayList<Exception>(Arrays.asList(new Exception[]
|
ArrayList<Exception> arr2 = new ArrayList<>(List.of(
|
||||||
{new DatabaseUnavailableException(), new ItemUnavailableException()}));
|
new DatabaseUnavailableException(), new ItemUnavailableException()));
|
||||||
try {
|
try {
|
||||||
r2.perform(arr2, order);
|
r2.perform(arr2, order);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
|
@ -94,27 +94,27 @@ Then we have a messenger to carry messages
|
|||||||
```java
|
```java
|
||||||
public class Messenger {
|
public class Messenger {
|
||||||
LetterComposite messageFromOrcs() {
|
LetterComposite messageFromOrcs() {
|
||||||
List<Word> words = new ArrayList<>();
|
List<Word> words = List.of(
|
||||||
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), new Letter('e'), new Letter('r'), new Letter('e'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(new Letter('i'), new Letter('s'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('a'))));
|
new Word(List.of(new Letter('a'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), new Letter('i'), new Letter('p'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(new Letter('i'), new Letter('s'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('a'))));
|
new Word(List.of(new Letter('a'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), new Letter('y'))));
|
new Word(List.of(new Letter('w'), new Letter('a'), new Letter('y'))));
|
||||||
return new Sentence(words);
|
return new Sentence(words);
|
||||||
}
|
}
|
||||||
|
|
||||||
LetterComposite messageFromElves() {
|
LetterComposite messageFromElves() {
|
||||||
List<Word> words = new ArrayList<>();
|
List<Word> words = List.of(
|
||||||
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(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'))));
|
new Word(List.of(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'), new Letter('h'))));
|
||||||
return new Sentence(words);
|
return new Sentence(words);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
package com.iluwatar.composite;
|
package com.iluwatar.composite;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,21 +34,20 @@ public class Messenger {
|
|||||||
|
|
||||||
LetterComposite messageFromOrcs() {
|
LetterComposite messageFromOrcs() {
|
||||||
|
|
||||||
List<Word> words = new ArrayList<>();
|
List<Word> words = List.of(
|
||||||
|
new Word(List.of(new Letter('W'), new Letter('h'), new Letter('e'), new Letter(
|
||||||
words.add(new Word(Arrays.asList(new Letter('W'), new Letter('h'), new Letter('e'), new Letter(
|
'r'), new Letter('e'))),
|
||||||
'r'), new Letter('e'))));
|
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter(
|
||||||
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter(
|
'r'), new Letter('e'))),
|
||||||
'r'), new Letter('e'))));
|
new Word(List.of(new Letter('i'), new Letter('s'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
|
new Word(List.of(new Letter('a'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('a'))));
|
new Word(List.of(new Letter('w'), new Letter('h'), new Letter('i'), new Letter(
|
||||||
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('h'), new Letter('i'), new Letter(
|
'p'))),
|
||||||
'p'))));
|
new Word(List.of(new Letter('t'), new Letter('h'), new Letter('e'), new Letter(
|
||||||
words.add(new Word(Arrays.asList(new Letter('t'), new Letter('h'), new Letter('e'), new Letter(
|
'r'), new Letter('e'))),
|
||||||
'r'), new Letter('e'))));
|
new Word(List.of(new Letter('i'), new Letter('s'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('i'), new Letter('s'))));
|
new Word(List.of(new Letter('a'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('a'))));
|
new Word(List.of(new Letter('w'), new Letter('a'), new Letter('y'))));
|
||||||
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('a'), new Letter('y'))));
|
|
||||||
|
|
||||||
return new Sentence(words);
|
return new Sentence(words);
|
||||||
|
|
||||||
@ -58,20 +55,15 @@ public class Messenger {
|
|||||||
|
|
||||||
LetterComposite messageFromElves() {
|
LetterComposite messageFromElves() {
|
||||||
|
|
||||||
List<Word> words = new ArrayList<>();
|
List<Word> words = List.of(
|
||||||
|
new Word(List.of(new Letter('M'), new Letter('u'), new Letter('c'), new Letter('h'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('M'), new Letter('u'), new Letter('c'), new Letter(
|
new Word(List.of(new Letter('w'), new Letter('i'), new Letter('n'), new Letter('d'))),
|
||||||
'h'))));
|
new Word(List.of(new Letter('p'), new Letter('o'), new Letter('u'), new Letter('r'),
|
||||||
words.add(new Word(Arrays.asList(new Letter('w'), new Letter('i'), new Letter('n'), new Letter(
|
new Letter('s'))),
|
||||||
'd'))));
|
new Word(List.of(new Letter('f'), new Letter('r'), new Letter('o'), new Letter('m'))),
|
||||||
words.add(new Word(Arrays.asList(new Letter('p'), new Letter('o'), new Letter('u'), new Letter(
|
new Word(List.of(new Letter('y'), new Letter('o'), new Letter('u'), new Letter('r'))),
|
||||||
'r'), new Letter('s'))));
|
new Word(List.of(new Letter('m'), new Letter('o'), new Letter('u'), new Letter('t'),
|
||||||
words.add(new Word(Arrays.asList(new Letter('f'), new Letter('r'), new Letter('o'), new Letter(
|
new Letter('h'))));
|
||||||
'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'))));
|
|
||||||
|
|
||||||
return new Sentence(words);
|
return new Sentence(words);
|
||||||
|
|
||||||
|
@ -24,11 +24,9 @@
|
|||||||
package com.iluwatar.converter;
|
package com.iluwatar.converter;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +36,7 @@ import java.util.List;
|
|||||||
* objects between types.
|
* objects between types.
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point
|
||||||
@ -52,7 +50,7 @@ public class App {
|
|||||||
User user = userConverter.convertFromDto(dtoUser);
|
User user = userConverter.convertFromDto(dtoUser);
|
||||||
LOGGER.info("Entity converted from DTO:" + user);
|
LOGGER.info("Entity converted from DTO:" + user);
|
||||||
|
|
||||||
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
|
var users = List.of(new User("Camile", "Tough", false, "124sad"),
|
||||||
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
|
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
|
||||||
LOGGER.info("Domain entities:");
|
LOGGER.info("Domain entities:");
|
||||||
users.stream().map(User::toString).forEach(LOGGER::info);
|
users.stream().map(User::toString).forEach(LOGGER::info);
|
||||||
|
@ -23,10 +23,8 @@
|
|||||||
|
|
||||||
package com.iluwatar.converter;
|
package com.iluwatar.converter;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -81,8 +79,9 @@ public class ConverterTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCollectionConversion() {
|
public void testCollectionConversion() {
|
||||||
ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
|
List<User> users = List.of(new User("Camile", "Tough", false, "124sad"),
|
||||||
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
|
new User("Marti", "Luther", true, "42309fd"),
|
||||||
|
new User("Kate", "Smith", true, "if0243"));
|
||||||
List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));
|
List<User> fromDtos = userConverter.createFromDtos(userConverter.createFromEntities(users));
|
||||||
assertEquals(users, fromDtos);
|
assertEquals(users, fromDtos);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user