Java 11 migration: patterns (t-v) (#1085)
* Moves visitor pattern to java 11 * Moves value-object pattern to java 11 * Moves unit-of-work pattern to java 11 * Moves typeobjectpattern pattern to java 11 * Moves twin pattern to java 11 * Moves trampoline pattern to java 11 * Moves tolerant-reader pattern to java 11 * Moves tls pattern to java 11 * Moves throttling pattern to java 11 * Moves thread-pool pattern to java 11 * Moves template-method pattern to java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
160b737dcc
commit
50467c9e76
@ -28,22 +28,22 @@ package com.iluwatar.visitor;
|
||||
* can be added without altering the node interface.</p>
|
||||
*
|
||||
* <p>In this example there is a unit hierarchy beginning from {@link Commander}. This hierarchy is
|
||||
* traversed by visitors. {@link SoldierVisitor} applies its operation on {@link Soldier}s,
|
||||
* {@link SergeantVisitor} on {@link Sergeant}s and so on.</p>
|
||||
*
|
||||
* traversed by visitors. {@link SoldierVisitor} applies its operation on {@link Soldier}s, {@link
|
||||
* SergeantVisitor} on {@link Sergeant}s and so on.</p>
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
var commander =
|
||||
new Commander(new Sergeant(new Soldier(), new Soldier(), new Soldier()), new Sergeant(
|
||||
new Soldier(), new Soldier(), new Soldier()));
|
||||
var commander = new Commander(
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier()),
|
||||
new Sergeant(new Soldier(), new Soldier(), new Soldier())
|
||||
);
|
||||
commander.accept(new SoldierVisitor());
|
||||
commander.accept(new SergeantVisitor());
|
||||
commander.accept(new CommanderVisitor());
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
package com.iluwatar.visitor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Interface for the nodes in hierarchy.
|
||||
*/
|
||||
@ -38,8 +40,6 @@ public abstract class Unit {
|
||||
* Accept visitor.
|
||||
*/
|
||||
public void accept(UnitVisitor visitor) {
|
||||
for (var child : children) {
|
||||
child.accept(visitor);
|
||||
}
|
||||
Arrays.stream(children).forEach(child -> child.accept(visitor));
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
App.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Date: 12/30/15 - 18:59 PM.
|
||||
* Test related to Units
|
||||
* Date: 12/30/15 - 18:59 PM. Test related to Units
|
||||
*
|
||||
* @param <U> Type of Unit
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@ -65,9 +64,7 @@ public abstract class UnitTest<U extends Unit> {
|
||||
unit.accept(visitor);
|
||||
verifyVisit(unit, visitor);
|
||||
|
||||
for (final var child : children) {
|
||||
verify(child).accept(eq(visitor));
|
||||
}
|
||||
Arrays.stream(children).forEach(child -> verify(child).accept(eq(visitor)));
|
||||
|
||||
verifyNoMoreInteractions(children);
|
||||
verifyNoMoreInteractions(visitor);
|
||||
|
@ -31,15 +31,14 @@ import ch.qos.logback.core.AppenderBase;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Date: 12/30/15 - 18:59 PM.
|
||||
* Test case for Visitor Pattern
|
||||
* Date: 12/30/15 - 18:59 PM. Test case for Visitor Pattern
|
||||
*
|
||||
* @param <V> Type of UnitVisitor
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
@ -84,11 +83,12 @@ public abstract class VisitorTest<V extends UnitVisitor> {
|
||||
* @param sergeantResponse The optional expected response when being visited by a sergeant
|
||||
* @param soldierResponse The optional expected response when being visited by a soldier
|
||||
*/
|
||||
public VisitorTest(final V visitor,
|
||||
final Optional<String> commanderResponse,
|
||||
final Optional<String> sergeantResponse,
|
||||
final Optional<String> soldierResponse) {
|
||||
|
||||
public VisitorTest(
|
||||
final V visitor,
|
||||
final Optional<String> commanderResponse,
|
||||
final Optional<String> sergeantResponse,
|
||||
final Optional<String> soldierResponse
|
||||
) {
|
||||
this.visitor = visitor;
|
||||
this.commanderResponse = commanderResponse;
|
||||
this.sergeantResponse = sergeantResponse;
|
||||
|
Reference in New Issue
Block a user