mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 05:25:45 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -47,57 +47,46 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
/** Program entry point. */
|
||||
public static void main(String[] args) {
|
||||
|
||||
var integerList = List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2, -68);
|
||||
|
||||
prettyPrint("The initial list contains: ", integerList);
|
||||
|
||||
var firstFiveNegatives = SimpleFluentIterable
|
||||
.fromCopyOf(integerList)
|
||||
.filter(negatives())
|
||||
.first(3)
|
||||
.asList();
|
||||
var firstFiveNegatives =
|
||||
SimpleFluentIterable.fromCopyOf(integerList).filter(negatives()).first(3).asList();
|
||||
prettyPrint("The first three negative values are: ", firstFiveNegatives);
|
||||
|
||||
|
||||
var lastTwoPositives = SimpleFluentIterable
|
||||
.fromCopyOf(integerList)
|
||||
.filter(positives())
|
||||
.last(2)
|
||||
.asList();
|
||||
var lastTwoPositives =
|
||||
SimpleFluentIterable.fromCopyOf(integerList).filter(positives()).last(2).asList();
|
||||
prettyPrint("The last two positive values are: ", lastTwoPositives);
|
||||
|
||||
SimpleFluentIterable
|
||||
.fromCopyOf(integerList)
|
||||
SimpleFluentIterable.fromCopyOf(integerList)
|
||||
.filter(number -> number % 2 == 0)
|
||||
.first()
|
||||
.ifPresent(evenNumber -> LOGGER.info("The first even number is: {}", evenNumber));
|
||||
|
||||
|
||||
var transformedList = SimpleFluentIterable
|
||||
.fromCopyOf(integerList)
|
||||
.filter(negatives())
|
||||
.map(transformToString())
|
||||
.asList();
|
||||
var transformedList =
|
||||
SimpleFluentIterable.fromCopyOf(integerList)
|
||||
.filter(negatives())
|
||||
.map(transformToString())
|
||||
.asList();
|
||||
prettyPrint("A string-mapped list of negative numbers contains: ", transformedList);
|
||||
|
||||
var lastTwoOfFirstFourStringMapped =
|
||||
LazyFluentIterable.from(integerList)
|
||||
.filter(positives())
|
||||
.first(4)
|
||||
.last(2)
|
||||
.map(number -> "String[" + number + "]")
|
||||
.asList();
|
||||
prettyPrint(
|
||||
"The lazy list contains the last two of the first four positive numbers "
|
||||
+ "mapped to Strings: ",
|
||||
lastTwoOfFirstFourStringMapped);
|
||||
|
||||
var lastTwoOfFirstFourStringMapped = LazyFluentIterable
|
||||
.from(integerList)
|
||||
.filter(positives())
|
||||
.first(4)
|
||||
.last(2)
|
||||
.map(number -> "String[" + number + "]")
|
||||
.asList();
|
||||
prettyPrint("The lazy list contains the last two of the first four positive numbers "
|
||||
+ "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
|
||||
|
||||
LazyFluentIterable
|
||||
.from(integerList)
|
||||
LazyFluentIterable.from(integerList)
|
||||
.filter(negatives())
|
||||
.first(2)
|
||||
.last()
|
||||
@@ -120,10 +109,7 @@ public class App {
|
||||
prettyPrint(", ", prefix, iterable);
|
||||
}
|
||||
|
||||
private static <E> void prettyPrint(
|
||||
String delimiter, String prefix,
|
||||
Iterable<E> iterable
|
||||
) {
|
||||
private static <E> void prettyPrint(String delimiter, String prefix, Iterable<E> iterable) {
|
||||
var joiner = new StringJoiner(delimiter, prefix, ".");
|
||||
iterable.forEach(e -> joiner.add(e.toString()));
|
||||
LOGGER.info(joiner.toString());
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ public interface FluentIterable<E> extends Iterable<E> {
|
||||
* the predicate.
|
||||
*
|
||||
* @param predicate the condition to test with for the filtering. If the test is negative, the
|
||||
* tested object is removed by the iterator.
|
||||
* tested object is removed by the iterator.
|
||||
* @return a filtered FluentIterable
|
||||
*/
|
||||
FluentIterable<E> filter(Predicate<? super E> predicate);
|
||||
@@ -82,7 +82,7 @@ public interface FluentIterable<E> extends Iterable<E> {
|
||||
* Transforms this FluentIterable into a new one containing objects of the type T.
|
||||
*
|
||||
* @param function a function that transforms an instance of E into an instance of T
|
||||
* @param <T> the target type of the transformation
|
||||
* @param <T> the target type of the transformation
|
||||
* @return a new FluentIterable of the new type
|
||||
*/
|
||||
<T> FluentIterable<T> map(Function<? super E, T> function);
|
||||
@@ -98,7 +98,7 @@ public interface FluentIterable<E> extends Iterable<E> {
|
||||
* Utility method that iterates over iterable and adds the contents to a list.
|
||||
*
|
||||
* @param iterable the iterable to collect
|
||||
* @param <E> the type of the objects to iterate
|
||||
* @param <E> the type of the objects to iterate
|
||||
* @return a list with all objects of the given iterator
|
||||
*/
|
||||
static <E> List<E> copyToList(Iterable<E> iterable) {
|
||||
|
||||
+1
-3
@@ -38,9 +38,7 @@ public abstract class DecoratingIterator<E> implements Iterator<E> {
|
||||
|
||||
private E next;
|
||||
|
||||
/**
|
||||
* Creates an iterator that decorates the given iterator.
|
||||
*/
|
||||
/** Creates an iterator that decorates the given iterator. */
|
||||
public DecoratingIterator(Iterator<E> fromIterator) {
|
||||
this.fromIterator = fromIterator;
|
||||
}
|
||||
|
||||
+3
-6
@@ -44,9 +44,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
|
||||
|
||||
private final Iterable<E> iterable;
|
||||
|
||||
/**
|
||||
* This constructor can be used to implement anonymous subclasses of the LazyFluentIterable.
|
||||
*/
|
||||
/** This constructor can be used to implement anonymous subclasses of the LazyFluentIterable. */
|
||||
protected LazyFluentIterable() {
|
||||
iterable = this;
|
||||
}
|
||||
@@ -56,7 +54,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
|
||||
* the predicate.
|
||||
*
|
||||
* @param predicate the condition to test with for the filtering. If the test is negative, the
|
||||
* tested object is removed by the iterator.
|
||||
* tested object is removed by the iterator.
|
||||
* @return a new FluentIterable object that decorates the source iterable
|
||||
*/
|
||||
@Override
|
||||
@@ -183,7 +181,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
|
||||
* Transforms this FluentIterable into a new one containing objects of the type T.
|
||||
*
|
||||
* @param function a function that transforms an instance of E into an instance of T
|
||||
* @param <T> the target type of the transformation
|
||||
* @param <T> the target type of the transformation
|
||||
* @return a new FluentIterable of the new type
|
||||
*/
|
||||
@Override
|
||||
@@ -236,5 +234,4 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
|
||||
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
|
||||
return new LazyFluentIterable<>(iterable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-3
@@ -51,7 +51,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
|
||||
* the predicate.
|
||||
*
|
||||
* @param predicate the condition to test with for the filtering. If the test is negative, the
|
||||
* tested object is removed by the iterator.
|
||||
* tested object is removed by the iterator.
|
||||
* @return the same FluentIterable with a filtered collection
|
||||
*/
|
||||
@Override
|
||||
@@ -139,7 +139,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
|
||||
* Transforms this FluentIterable into a new one containing objects of the type T.
|
||||
*
|
||||
* @param function a function that transforms an instance of E into an instance of T
|
||||
* @param <T> the target type of the transformation
|
||||
* @param <T> the target type of the transformation
|
||||
* @return a new FluentIterable of the new type
|
||||
*/
|
||||
@Override
|
||||
@@ -183,7 +183,6 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
|
||||
iterable.forEach(action);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Spliterator<E> spliterator() {
|
||||
return iterable.spliterator();
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.fluentinterface.app;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Application Test Entry
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Application Test Entry */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
+8
-25
@@ -38,10 +38,7 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* FluentIterableTest
|
||||
*
|
||||
*/
|
||||
/** FluentIterableTest */
|
||||
public abstract class FluentIterableTest {
|
||||
|
||||
/**
|
||||
@@ -72,9 +69,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testFirstCount() {
|
||||
final var integers = List.of(1, 2, 3, 10, 9, 8);
|
||||
final var first4 = createFluentIterable(integers)
|
||||
.first(4)
|
||||
.asList();
|
||||
final var first4 = createFluentIterable(integers).first(4).asList();
|
||||
|
||||
assertNotNull(first4);
|
||||
assertEquals(4, first4.size());
|
||||
@@ -88,9 +83,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testFirstCountLessItems() {
|
||||
final var integers = List.of(1, 2, 3);
|
||||
final var first4 = createFluentIterable(integers)
|
||||
.first(4)
|
||||
.asList();
|
||||
final var first4 = createFluentIterable(integers).first(4).asList();
|
||||
|
||||
assertNotNull(first4);
|
||||
assertEquals(3, first4.size());
|
||||
@@ -120,9 +113,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testLastCount() {
|
||||
final var integers = List.of(1, 2, 3, 10, 9, 8);
|
||||
final var last4 = createFluentIterable(integers)
|
||||
.last(4)
|
||||
.asList();
|
||||
final var last4 = createFluentIterable(integers).last(4).asList();
|
||||
|
||||
assertNotNull(last4);
|
||||
assertEquals(4, last4.size());
|
||||
@@ -135,9 +126,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testLastCountLessItems() {
|
||||
final var integers = List.of(1, 2, 3);
|
||||
final var last4 = createFluentIterable(integers)
|
||||
.last(4)
|
||||
.asList();
|
||||
final var last4 = createFluentIterable(integers).last(4).asList();
|
||||
|
||||
assertNotNull(last4);
|
||||
assertEquals(3, last4.size());
|
||||
@@ -150,9 +139,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testFilter() {
|
||||
final var integers = List.of(1, 2, 3, 10, 9, 8);
|
||||
final var evenItems = createFluentIterable(integers)
|
||||
.filter(i -> i % 2 == 0)
|
||||
.asList();
|
||||
final var evenItems = createFluentIterable(integers).filter(i -> i % 2 == 0).asList();
|
||||
|
||||
assertNotNull(evenItems);
|
||||
assertEquals(3, evenItems.size());
|
||||
@@ -164,9 +151,7 @@ public abstract class FluentIterableTest {
|
||||
@Test
|
||||
void testMap() {
|
||||
final var integers = List.of(1, 2, 3);
|
||||
final var longs = createFluentIterable(integers)
|
||||
.map(Integer::longValue)
|
||||
.asList();
|
||||
final var longs = createFluentIterable(integers).map(Integer::longValue).asList();
|
||||
|
||||
assertNotNull(longs);
|
||||
assertEquals(integers.size(), longs.size());
|
||||
@@ -186,7 +171,6 @@ public abstract class FluentIterableTest {
|
||||
verify(consumer, times(1)).accept(2);
|
||||
verify(consumer, times(1)).accept(3);
|
||||
verifyNoMoreInteractions(consumer);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,5 +179,4 @@ public abstract class FluentIterableTest {
|
||||
final var split = createFluentIterable(integers).spliterator();
|
||||
assertNotNull(split);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -27,15 +27,11 @@ package com.iluwatar.fluentinterface.fluentiterable.lazy;
|
||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
|
||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterableTest;
|
||||
|
||||
/**
|
||||
* LazyFluentIterableTest
|
||||
*
|
||||
*/
|
||||
/** LazyFluentIterableTest */
|
||||
class LazyFluentIterableTest extends FluentIterableTest {
|
||||
|
||||
@Override
|
||||
protected FluentIterable<Integer> createFluentIterable(Iterable<Integer> integers) {
|
||||
return LazyFluentIterable.from(integers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-5
@@ -27,15 +27,11 @@ package com.iluwatar.fluentinterface.fluentiterable.simple;
|
||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
|
||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterableTest;
|
||||
|
||||
/**
|
||||
* SimpleFluentIterableTest
|
||||
*
|
||||
*/
|
||||
/** SimpleFluentIterableTest */
|
||||
class SimpleFluentIterableTest extends FluentIterableTest {
|
||||
|
||||
@Override
|
||||
protected FluentIterable<Integer> createFluentIterable(Iterable<Integer> integers) {
|
||||
return SimpleFluentIterable.fromCopyOf(integers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user