Skip to content

Commit

Permalink
Add java 11 support for #987 (o-t) (#1051)
Browse files Browse the repository at this point in the history
* Use java 11

* Use .of
- Replace Arrays.asList with List.of
- Replace HashSet<>(List.of()) with Set.of

* Formatting
  • Loading branch information
leonmak authored and iluwatar committed Oct 29, 2019
1 parent dd971d8 commit c8a481b
Show file tree
Hide file tree
Showing 37 changed files with 176 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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;

Expand Down Expand Up @@ -64,7 +63,7 @@ public void shouldConstructCar() {
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<>()));
Property.PARTS.toString(), List.of(Map.of(), Map.of()));
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,13 +23,12 @@

package com.iluwatar.collectionpipeline;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;

/**
* In imperative-style programming, it is common to use for and while loops for
* most kinds of data processing. Function composition is a simple technique
Expand Down Expand Up @@ -67,11 +66,11 @@ public static void main(String[] args) {
LOGGER.info(groupingByCategoryFunctional.toString());

Person john = new Person(cars);
List<Car> sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));

List<Car> sedansOwnedImperative = ImperativeProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
LOGGER.info(sedansOwnedImperative.toString());

List<Car> sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(Arrays.asList(john));
List<Car> sedansOwnedFunctional = FunctionalProgramming.getSedanCarsOwnedSortedByDate(List.of(john));
LOGGER.info(sedansOwnedFunctional.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

package com.iluwatar.collectionpipeline;

import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -38,7 +37,7 @@ private CarFactory() {
* @return {@link List} of {@link Car}
*/
public static List<Car> createCars() {
return Arrays.asList(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
return List.of(new Car("Jeep", "Wrangler", 2011, Category.JEEP),
new Car("Jeep", "Comanche", 1990, Category.JEEP),
new Car("Dodge", "Avenger", 2010, Category.SEDAN),
new Car("Buick", "Cascada", 2016, Category.CONVERTIBLE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class Service {
public ArrayList<Exception> exceptionsList;
private static final Random RANDOM = new Random();
private static final String ALL_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
private static final Hashtable<String, Boolean> USED_IDS = new Hashtable<String, Boolean>();
private static final Hashtable<String, Boolean> USED_IDS = new Hashtable<>();

protected Service(Database db, Exception...exc) {
this.database = db;
Expand Down
4 changes: 2 additions & 2 deletions commander/src/test/java/com/iluwatar/commander/RetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void performTest() {
Retry.HandleErrorIssue<Order> handleError = (o,e) -> {
return;
};
Retry<Order> r1 = new Retry<Order>(op, handleError, 3, 30000,
Retry<Order> r1 = new Retry<>(op, handleError, 3, 30000,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
Retry<Order> r2 = new Retry<Order>(op, handleError, 3, 30000,
Retry<Order> r2 = new Retry<>(op, handleError, 3, 30000,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
User user = new User("Jim", "ABCD");
Order order = new Order(user, "book", 10f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@

package com.iluwatar.fluentinterface.app;

import static java.lang.String.valueOf;
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.function.Predicate;

import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.lang.String.valueOf;

/**
* The Fluent Interface pattern is useful when you want to provide an easy readable, flowing API.
Expand All @@ -61,7 +60,7 @@ public class App {
public static void main(String[] args) {

List<Integer> integerList = new ArrayList<>();
integerList.addAll(Arrays.asList(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2,
integerList.addAll(List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2,
-68, 45));

prettyPrint("The initial list contains: ", integerList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Spliterator;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
* Date: 12/12/15 - 7:00 PM
Expand All @@ -58,7 +51,7 @@ public abstract class FluentIterableTest {

@Test
public void testFirst() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final Optional<Integer> first = createFluentIterable(integers).first();
assertNotNull(first);
assertTrue(first.isPresent());
Expand All @@ -75,7 +68,7 @@ public void testFirstEmptyCollection() throws Exception {

@Test
public void testFirstCount() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> first4 = createFluentIterable(integers)
.first(4)
.asList();
Expand All @@ -91,7 +84,7 @@ public void testFirstCount() throws Exception {

@Test
public void testFirstCountLessItems() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Integer> first4 = createFluentIterable(integers)
.first(4)
.asList();
Expand All @@ -106,7 +99,7 @@ public void testFirstCountLessItems() throws Exception {

@Test
public void testLast() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final Optional<Integer> last = createFluentIterable(integers).last();
assertNotNull(last);
assertTrue(last.isPresent());
Expand All @@ -123,7 +116,7 @@ public void testLastEmptyCollection() throws Exception {

@Test
public void testLastCount() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> last4 = createFluentIterable(integers)
.last(4)
.asList();
Expand All @@ -138,7 +131,7 @@ public void testLastCount() throws Exception {

@Test
public void testLastCountLessItems() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Integer> last4 = createFluentIterable(integers)
.last(4)
.asList();
Expand All @@ -153,7 +146,7 @@ public void testLastCountLessItems() throws Exception {

@Test
public void testFilter() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3, 10, 9, 8);
final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
final List<Integer> evenItems = createFluentIterable(integers)
.filter(i -> i % 2 == 0)
.asList();
Expand All @@ -167,7 +160,7 @@ public void testFilter() throws Exception {

@Test
public void testMap() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final List<Long> longs = createFluentIterable(integers)
.map(Integer::longValue)
.asList();
Expand All @@ -181,7 +174,7 @@ public void testMap() throws Exception {

@Test
public void testForEach() {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);

final Consumer<Integer> consumer = mock(Consumer.class);
createFluentIterable(integers).forEach(consumer);
Expand All @@ -195,7 +188,7 @@ public void testForEach() {

@Test
public void testSpliterator() throws Exception {
final List<Integer> integers = Arrays.asList(1, 2, 3);
final List<Integer> integers = List.of(1, 2, 3);
final Spliterator<Integer> split = createFluentIterable(integers).spliterator();
assertNotNull(split);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

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

/**
*
Expand All @@ -43,8 +38,7 @@ class LotteryNumbersTest {

@Test
void testGivenNumbers() {
LotteryNumbers numbers = LotteryNumbers.create(
Set.of(1, 2, 3, 4));
LotteryNumbers numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4));
assertEquals(numbers.getNumbers().size(), 4);
assertTrue(numbers.getNumbers().contains(1));
assertTrue(numbers.getNumbers().contains(2));
Expand All @@ -54,8 +48,7 @@ void testGivenNumbers() {

@Test
void testNumbersCantBeModified() {
LotteryNumbers numbers = LotteryNumbers.create(
Set.of(1, 2, 3, 4));
LotteryNumbers numbers = LotteryNumbers.create(Set.of(1, 2, 3, 4));
assertThrows(UnsupportedOperationException.class, () -> numbers.getNumbers().add(5));
}

Expand All @@ -67,13 +60,10 @@ void testRandomNumbers() {

@Test
void testEquals() {
LotteryNumbers numbers1 = LotteryNumbers.create(
Set.of(1, 2, 3, 4));
LotteryNumbers numbers2 = LotteryNumbers.create(
Set.of(1, 2, 3, 4));
LotteryNumbers numbers1 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
LotteryNumbers numbers2 = LotteryNumbers.create(Set.of(1, 2, 3, 4));
assertEquals(numbers1, numbers2);
LotteryNumbers numbers3 = LotteryNumbers.create(
Set.of(11, 12, 13, 14));
LotteryNumbers numbers3 = LotteryNumbers.create(Set.of(11, 12, 13, 14));
assertNotEquals(numbers1, numbers3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

import java.util.*;

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

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@

package com.iluwatar.hexagonal.test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import com.iluwatar.hexagonal.domain.LotteryNumbers;
import com.iluwatar.hexagonal.domain.LotteryTicket;
import com.iluwatar.hexagonal.domain.LotteryTicketId;
import com.iluwatar.hexagonal.domain.PlayerDetails;

import java.util.Set;

/**
*
* Utilities for lottery tests
Expand Down
12 changes: 7 additions & 5 deletions layers/src/main/java/com/iluwatar/layers/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.iluwatar.layers;

import java.util.Arrays;
import java.util.List;

/**
*
Expand Down Expand Up @@ -99,16 +99,18 @@ private static void initializeData(CakeBakingService cakeBakingService) {
cakeBakingService.saveNewTopping(new CakeToppingInfo("cherry", 350));

CakeInfo cake1 =
new CakeInfo(new CakeToppingInfo("candies", 0), Arrays.asList(new CakeLayerInfo(
"chocolate", 0), new CakeLayerInfo("banana", 0), new CakeLayerInfo("strawberry", 0)));
new CakeInfo(new CakeToppingInfo("candies", 0), List.of(
new CakeLayerInfo("chocolate", 0),
new CakeLayerInfo("banana", 0),
new CakeLayerInfo("strawberry", 0)));
try {
cakeBakingService.bakeNewCake(cake1);
} catch (CakeBakingException e) {
e.printStackTrace();
}
CakeInfo cake2 =
new CakeInfo(new CakeToppingInfo("cherry", 0), Arrays.asList(
new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo(
new CakeInfo(new CakeToppingInfo("cherry", 0), List.of(
new CakeLayerInfo("vanilla", 0), new CakeLayerInfo("lemon", 0), new CakeLayerInfo(
"strawberry", 0)));
try {
cakeBakingService.bakeNewCake(cake2);
Expand Down
Loading

0 comments on commit c8a481b

Please sign in to comment.