Skip to content

Commit 670c4e4

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Java 11 migrate 7 remaining f (iluwatar#1115)
* Moves facade to Java 11 * Moves factory-kit to Java 11 * Moves factory-method to Java 11 * Moves feature-toggle to Java 11 * Moves fluentinterface to Java 11 * Moves flux to Java 11 * Moves flyweight to Java 11 * Moves front-controller to Java 11 * Uses stream properly * Resolves issues with ci
1 parent f835d3d commit 670c4e4

File tree

55 files changed

+374
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+374
-426
lines changed

facade/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public abstract class DwarvenMineWorker {
7676
}
7777

7878
public void action(Action... actions) {
79-
for (Action action : actions) {
80-
action(action);
81-
}
79+
Arrays.stream(actions).forEach(this::action);
8280
}
8381

8482
public abstract void work();
@@ -165,9 +163,7 @@ public class DwarvenGoldmineFacade {
165163

166164
private static void makeActions(Collection<DwarvenMineWorker> workers,
167165
DwarvenMineWorker.Action... actions) {
168-
for (DwarvenMineWorker worker : workers) {
169-
worker.action(actions);
170-
}
166+
workers.forEach(worker -> worker.action(actions));
171167
}
172168
}
173169
```

facade/src/main/java/com/iluwatar/facade/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class App {
4242
* @param args command line args
4343
*/
4444
public static void main(String[] args) {
45-
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
45+
var facade = new DwarvenGoldmineFacade();
4646
facade.startNewDay();
4747
facade.digOutGold();
4848
facade.endDay();

facade/src/main/java/com/iluwatar/facade/DwarvenGoldmineFacade.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ private static void makeActions(
6363
Collection<DwarvenMineWorker> workers,
6464
DwarvenMineWorker.Action... actions
6565
) {
66-
for (DwarvenMineWorker worker : workers) {
67-
worker.action(actions);
68-
}
66+
workers.forEach(worker -> worker.action(actions));
6967
}
7068
}

facade/src/main/java/com/iluwatar/facade/DwarvenMineWorker.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.iluwatar.facade;
2525

26+
import java.util.Arrays;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

@@ -76,9 +77,7 @@ private void action(Action action) {
7677
* Perform actions.
7778
*/
7879
public void action(Action... actions) {
79-
for (Action action : actions) {
80-
action(action);
81-
}
80+
Arrays.stream(actions).forEach(this::action);
8281
}
8382

8483
public abstract void work();

facade/src/test/java/com/iluwatar/facade/AppTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@
2626
import org.junit.jupiter.api.Test;
2727

2828
/**
29-
*
3029
* Application test
31-
*
3230
*/
3331
public class AppTest {
3432

3533
@Test
3634
public void test() {
37-
String[] args = {};
38-
App.main(args);
35+
App.main(new String[]{});
3936
}
4037
}

facade/src/test/java/com/iluwatar/facade/DwarvenGoldmineFacadeTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@
2323

2424
package com.iluwatar.facade;
2525

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
2629
import ch.qos.logback.classic.Logger;
2730
import ch.qos.logback.classic.spi.ILoggingEvent;
2831
import ch.qos.logback.core.AppenderBase;
32+
import java.util.LinkedList;
33+
import java.util.List;
2934
import org.junit.jupiter.api.AfterEach;
3035
import org.junit.jupiter.api.BeforeEach;
3136
import org.junit.jupiter.api.Test;
3237
import org.slf4j.LoggerFactory;
3338

34-
import java.util.LinkedList;
35-
import java.util.List;
36-
37-
import static org.junit.jupiter.api.Assertions.assertEquals;
38-
import static org.junit.jupiter.api.Assertions.assertTrue;
39-
4039
/**
4140
* Date: 12/9/15 - 9:40 PM
4241
*
@@ -56,16 +55,16 @@ public void tearDown() {
5655
appender.stop();
5756
}
5857

59-
/**
58+
/**
6059
* Test a complete day cycle in the gold mine by executing all three different steps: {@link
6160
* DwarvenGoldmineFacade#startNewDay()}, {@link DwarvenGoldmineFacade#digOutGold()} and {@link
6261
* DwarvenGoldmineFacade#endDay()}.
63-
*
62+
* <p>
6463
* See if the workers are doing what's expected from them on each step.
6564
*/
6665
@Test
6766
public void testFullWorkDay() {
68-
final DwarvenGoldmineFacade goldMine = new DwarvenGoldmineFacade();
67+
final var goldMine = new DwarvenGoldmineFacade();
6968
goldMine.startNewDay();
7069

7170
// On the start of a day, all workers should wake up ...
@@ -128,7 +127,9 @@ public int getLogSize() {
128127
}
129128

130129
public boolean logContains(String message) {
131-
return log.stream().anyMatch(event -> event.getFormattedMessage().equals(message));
130+
return log.stream()
131+
.map(ILoggingEvent::getFormattedMessage)
132+
.anyMatch(message::equals);
132133
}
133134
}
134135

factory-kit/src/main/java/com/iluwatar/factorykit/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public class App {
4848
* @param args command line args
4949
*/
5050
public static void main(String[] args) {
51-
WeaponFactory factory = WeaponFactory.factory(builder -> {
51+
var factory = WeaponFactory.factory(builder -> {
5252
builder.add(WeaponType.SWORD, Sword::new);
5353
builder.add(WeaponType.AXE, Axe::new);
5454
builder.add(WeaponType.SPEAR, Spear::new);
5555
builder.add(WeaponType.BOW, Bow::new);
5656
});
57-
Weapon axe = factory.create(WeaponType.AXE);
57+
var axe = factory.create(WeaponType.AXE);
5858
LOGGER.info(axe.toString());
5959
}
6060
}

factory-kit/src/main/java/com/iluwatar/factorykit/WeaponFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
package com.iluwatar.factorykit;
2525

2626
import java.util.HashMap;
27-
import java.util.Map;
2827
import java.util.function.Consumer;
2928
import java.util.function.Supplier;
3029

@@ -52,7 +51,7 @@ public interface WeaponFactory {
5251
* @return factory with specified {@link Builder}s
5352
*/
5453
static WeaponFactory factory(Consumer<Builder> consumer) {
55-
Map<WeaponType, Supplier<Weapon>> map = new HashMap<>();
54+
var map = new HashMap<WeaponType, Supplier<Weapon>>();
5655
consumer.accept(map::put);
5756
return name -> map.get(name).get();
5857
}

factory-kit/src/test/java/com/iluwatar/factorykit/app/AppTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public class AppTest {
3333

3434
@Test
3535
public void test() {
36-
String[] args = {};
37-
App.main(args);
36+
App.main(new String[]{});
3837
}
3938
}
4039

factory-kit/src/test/java/com/iluwatar/factorykit/factorykit/FactoryKitTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
package com.iluwatar.factorykit.factorykit;
2525

26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
2628
import com.iluwatar.factorykit.Axe;
2729
import com.iluwatar.factorykit.Spear;
2830
import com.iluwatar.factorykit.Sword;
@@ -32,10 +34,8 @@
3234
import org.junit.jupiter.api.BeforeEach;
3335
import org.junit.jupiter.api.Test;
3436

35-
import static org.junit.jupiter.api.Assertions.assertTrue;
36-
37-
/**
38-
* Test Factory Kit Pattern
37+
/**
38+
* Test Factory Kit Pattern
3939
*/
4040
public class FactoryKitTest {
4141

@@ -51,30 +51,33 @@ public void init() {
5151
}
5252

5353
/**
54-
* Testing {@link WeaponFactory} to produce a SPEAR asserting that the Weapon is an instance of {@link Spear}
54+
* Testing {@link WeaponFactory} to produce a SPEAR asserting that the Weapon is an instance of
55+
* {@link Spear}
5556
*/
5657
@Test
5758
public void testSpearWeapon() {
58-
Weapon weapon = factory.create(WeaponType.SPEAR);
59+
var weapon = factory.create(WeaponType.SPEAR);
5960
verifyWeapon(weapon, Spear.class);
6061
}
6162

6263
/**
63-
* Testing {@link WeaponFactory} to produce a AXE asserting that the Weapon is an instance of {@link Axe}
64+
* Testing {@link WeaponFactory} to produce a AXE asserting that the Weapon is an instance of
65+
* {@link Axe}
6466
*/
6567
@Test
6668
public void testAxeWeapon() {
67-
Weapon weapon = factory.create(WeaponType.AXE);
69+
var weapon = factory.create(WeaponType.AXE);
6870
verifyWeapon(weapon, Axe.class);
6971
}
7072

7173

7274
/**
73-
* Testing {@link WeaponFactory} to produce a SWORD asserting that the Weapon is an instance of {@link Sword}
75+
* Testing {@link WeaponFactory} to produce a SWORD asserting that the Weapon is an instance of
76+
* {@link Sword}
7477
*/
7578
@Test
7679
public void testWeapon() {
77-
Weapon weapon = factory.create(WeaponType.SWORD);
80+
var weapon = factory.create(WeaponType.SWORD);
7881
verifyWeapon(weapon, Sword.class);
7982
}
8083

factory-method/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class OrcBlacksmith implements Blacksmith {
5555
Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured
5656

5757
```java
58-
Blacksmith blacksmith = new ElfBlacksmith();
58+
var blacksmith = new ElfBlacksmith();
5959
blacksmith.manufactureWeapon(WeaponType.SPEAR);
6060
blacksmith.manufactureWeapon(WeaponType.AXE);
6161
// Elvish weapons are created

factory-method/src/main/java/com/iluwatar/factory/method/App.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public App(Blacksmith blacksmith) {
6464
*/
6565
public static void main(String[] args) {
6666
// Lets go to war with Orc weapons
67-
App app = new App(new OrcBlacksmith());
67+
var app = new App(new OrcBlacksmith());
6868
app.manufactureWeapons();
6969

7070
// Lets go to war with Elf weapons
@@ -73,8 +73,7 @@ public static void main(String[] args) {
7373
}
7474

7575
private void manufactureWeapons() {
76-
Weapon weapon;
77-
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
76+
var weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
7877
LOGGER.info(weapon.toString());
7978
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
8079
LOGGER.info(weapon.toString());

factory-method/src/main/java/com/iluwatar/factory/method/ElfBlacksmith.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.iluwatar.factory.method;
2525

26+
import java.util.Arrays;
2627
import java.util.HashMap;
2728
import java.util.Map;
2829

@@ -35,14 +36,12 @@ public class ElfBlacksmith implements Blacksmith {
3536

3637
static {
3738
ELFARSENAL = new HashMap<>(WeaponType.values().length);
38-
for (WeaponType type : WeaponType.values()) {
39-
ELFARSENAL.put(type, new ElfWeapon(type));
40-
}
39+
Arrays.stream(WeaponType.values()).forEach(type -> ELFARSENAL.put(type, new ElfWeapon(type)));
4140
}
42-
41+
4342
@Override
4443
public Weapon manufactureWeapon(WeaponType weaponType) {
4544
return ELFARSENAL.get(weaponType);
4645
}
47-
46+
4847
}

factory-method/src/main/java/com/iluwatar/factory/method/OrcBlacksmith.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
package com.iluwatar.factory.method;
2525

26+
import java.util.Arrays;
2627
import java.util.HashMap;
2728
import java.util.Map;
2829

@@ -35,9 +36,7 @@ public class OrcBlacksmith implements Blacksmith {
3536

3637
static {
3738
ORCARSENAL = new HashMap<>(WeaponType.values().length);
38-
for (WeaponType type : WeaponType.values()) {
39-
ORCARSENAL.put(type, new OrcWeapon(type));
40-
}
39+
Arrays.stream(WeaponType.values()).forEach(type -> ORCARSENAL.put(type, new OrcWeapon(type)));
4140
}
4241

4342
@Override

factory-method/src/test/java/com/iluwatar/factory/method/AppTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@
2525

2626
import org.junit.jupiter.api.Test;
2727

28-
import java.io.IOException;
29-
3028
/**
3129
* Tests that Factory Method example runs without errors.
3230
*/
3331
public class AppTest {
3432
@Test
35-
public void test() throws IOException {
36-
String[] args = {};
37-
App.main(args);
33+
public void test() {
34+
App.main(new String[]{});
3835
}
3936
}

0 commit comments

Comments
 (0)