Skip to content

Commit e65b652

Browse files
committed
fixing typos in readme file, introducing var local type inference where possible
1 parent 3d9afba commit e65b652

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

filterer/README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tags:
1414
Filterer
1515

1616
## Intent
17-
The intent of this design pattern is to to introduce a functional interface that will add a functionality for container-like objects to easily return filtered versions of themselves.
17+
The intent of this design pattern is to introduce a functional interface that will add a functionality for container-like objects to easily return filtered versions of themselves.
1818

1919
## Explanation
2020
Real world example
@@ -59,7 +59,7 @@ The container-like object (`ThreatAwareSystem` in our case) needs to have a meth
5959
ability to covariantly specify a lower bound of contravariant `Predicate` in the subinterfaces of interfaces representing the container-like objects.
6060

6161
In our example we will be able to pass a predicate that takes `? extends Threat` object and return `? extends ThreatAwareSystem`
62-
from `Filtered::by` method. A simple implementation of `ThreadAwareSystem` :
62+
from `Filtered::by` method. A simple implementation of `ThreatAwareSystem` :
6363
```java
6464
public class SimpleThreatAwareSystem implements ThreatAwareSystem {
6565

@@ -99,7 +99,7 @@ public class SimpleThreatAwareSystem implements ThreatAwareSystem {
9999
```
100100
the `filtered` method is overridden to filter the threats list by given predicate.
101101

102-
Now if we introduce new subtype of `Thread` interface that adds probability with which given thread can appear :
102+
Now if we introduce a new subtype of `Threat` interface that adds probability with which given threat can appear :
103103
```java
104104
public interface ProbableThreat extends Threat {
105105
double probability();
@@ -116,7 +116,7 @@ public interface ProbabilisticThreatAwareSystem extends ThreatAwareSystem {
116116
}
117117
````
118118
Notice how we override the `filtered` method in `ProbabilisticThreatAwareSystem` and specify different return covariant type
119-
by specifing different generic types. Our interfaces are clean and not cluttered by default implementations. We
119+
by specifying different generic types. Our interfaces are clean and not cluttered by default implementations. We
120120
we will be able to filter `ProbabilisticThreatAwareSystem` by `ProbableThreat` properties :
121121
```java
122122
public class SimpleProbabilisticThreatAwareSystem implements ProbabilisticThreatAwareSystem {

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

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

2424
package com.iluwatar.filterer;
2525

26-
import com.iluwatar.filterer.threat.ProbabilisticThreatAwareSystem;
2726
import com.iluwatar.filterer.threat.ProbableThreat;
2827
import com.iluwatar.filterer.threat.SimpleProbabilisticThreatAwareSystem;
2928
import com.iluwatar.filterer.threat.SimpleProbableThreat;
@@ -65,24 +64,22 @@ public static void main(String[] args) {
6564
private static void filteringSimpleProbableThreats() {
6665
LOGGER.info(" ### Filtering ProbabilisticThreatAwareSystem by probability ###");
6766

68-
ProbableThreat trojanArcBomb =
69-
new SimpleProbableThreat("Trojan-ArcBomb", 1, ThreatType.TROJAN, 0.99);
70-
ProbableThreat rootkit =
71-
new SimpleProbableThreat("Rootkit-Kernel", 2, ThreatType.ROOTKIT, 0.8);
67+
var trojanArcBomb = new SimpleProbableThreat("Trojan-ArcBomb", 1, ThreatType.TROJAN, 0.99);
68+
var rootkit = new SimpleProbableThreat("Rootkit-Kernel", 2, ThreatType.ROOTKIT, 0.8);
7269

7370
List<ProbableThreat> probableThreats = List.of(trojanArcBomb, rootkit);
7471

75-
ProbabilisticThreatAwareSystem probabilisticThreatAwareSystem =
76-
new SimpleProbabilisticThreatAwareSystem("System-1", probableThreats);
72+
var probabilisticThreatAwareSystem =
73+
new SimpleProbabilisticThreatAwareSystem("Sys-1", probableThreats);
7774

7875
LOGGER.info("Filtering ProbabilisticThreatAwareSystem. Initial : "
7976
+ probabilisticThreatAwareSystem);
8077

8178
//Filtering using filterer
82-
ProbabilisticThreatAwareSystem filtered = probabilisticThreatAwareSystem.filtered()
79+
var filteredThreatAwareSystem = probabilisticThreatAwareSystem.filtered()
8380
.by(probableThreat -> Double.compare(probableThreat.probability(), 0.99) == 0);
8481

85-
LOGGER.info("Filtered by probability = 0.99 : " + filtered);
82+
LOGGER.info("Filtered by probability = 0.99 : " + filteredThreatAwareSystem);
8683
}
8784

8885
/**
@@ -93,16 +90,16 @@ private static void filteringSimpleProbableThreats() {
9390
private static void filteringSimpleThreats() {
9491
LOGGER.info("### Filtering ThreatAwareSystem by ThreatType ###");
9592

96-
Threat rootkit = new SimpleThreat(ThreatType.ROOTKIT, 1, "Simple-Rootkit");
97-
Threat trojan = new SimpleThreat(ThreatType.TROJAN, 2, "Simple-Trojan");
93+
var rootkit = new SimpleThreat(ThreatType.ROOTKIT, 1, "Simple-Rootkit");
94+
var trojan = new SimpleThreat(ThreatType.TROJAN, 2, "Simple-Trojan");
9895
List<Threat> threats = List.of(rootkit, trojan);
9996

100-
ThreatAwareSystem threatAwareSystem = new SimpleThreatAwareSystem("System-1", threats);
97+
var threatAwareSystem = new SimpleThreatAwareSystem("Sys-1", threats);
10198

10299
LOGGER.info("Filtering ThreatAwareSystem. Initial : " + threatAwareSystem);
103100

104101
//Filtering using Filterer
105-
ThreatAwareSystem rootkitThreatAwareSystem = threatAwareSystem.filtered()
102+
var rootkitThreatAwareSystem = threatAwareSystem.filtered()
106103
.by(threat -> threat.type() == ThreatType.ROOTKIT);
107104

108105
LOGGER.info("Filtered by threatType = ROOTKIT : " + rootkitThreatAwareSystem);

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleProbabilisticThreatAwareSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public boolean equals(Object o) {
9393
if (o == null || getClass() != o.getClass()) {
9494
return false;
9595
}
96-
SimpleProbabilisticThreatAwareSystem that = (SimpleProbabilisticThreatAwareSystem) o;
96+
var that = (SimpleProbabilisticThreatAwareSystem) o;
9797
return systemId.equals(that.systemId)
9898
&& threats.equals(that.threats);
9999
}

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleProbableThreat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean equals(Object o) {
6060
if (!super.equals(o)) {
6161
return false;
6262
}
63-
SimpleProbableThreat that = (SimpleProbableThreat) o;
63+
var that = (SimpleProbableThreat) o;
6464
return Double.compare(that.probability, probability) == 0;
6565
}
6666

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleThreat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public boolean equals(Object o) {
7979
if (o == null || getClass() != o.getClass()) {
8080
return false;
8181
}
82-
SimpleThreat that = (SimpleThreat) o;
82+
var that = (SimpleThreat) o;
8383
return id == that.id
8484
&& threatType == that.threatType
8585
&& Objects.equals(name, that.name);

filterer/src/main/java/com/iluwatar/filterer/threat/SimpleThreatAwareSystem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public boolean equals(Object o) {
8787
if (o == null || getClass() != o.getClass()) {
8888
return false;
8989
}
90-
SimpleThreatAwareSystem that = (SimpleThreatAwareSystem) o;
90+
var that = (SimpleThreatAwareSystem) o;
9191
return systemId.equals(that.systemId)
9292
&& issues.equals(that.issues);
9393
}

filterer/src/test/java/com/iluwatar/filterer/threat/SimpleProbabilisticThreatAwareSystemTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class SimpleProbabilisticThreatAwareSystemTest {
3333
@Test
3434
void shouldFilterByProbability() {
3535
//given
36-
ProbableThreat trojan = new SimpleProbableThreat("Troyan-ArcBomb", 1, ThreatType.TROJAN, 0.99);
37-
ProbableThreat rootkit = new SimpleProbableThreat("Rootkit-System", 2, ThreatType.ROOTKIT, 0.8);
36+
var trojan = new SimpleProbableThreat("Troyan-ArcBomb", 1, ThreatType.TROJAN, 0.99);
37+
var rootkit = new SimpleProbableThreat("Rootkit-System", 2, ThreatType.ROOTKIT, 0.8);
3838
List<ProbableThreat> probableThreats = List.of(trojan, rootkit);
3939

40-
ProbabilisticThreatAwareSystem simpleProbabilisticThreatAwareSystem =
40+
var simpleProbabilisticThreatAwareSystem =
4141
new SimpleProbabilisticThreatAwareSystem("System-1", probableThreats);
4242

4343
//when
44-
ProbabilisticThreatAwareSystem filtered = simpleProbabilisticThreatAwareSystem.filtered()
44+
var filtered = simpleProbabilisticThreatAwareSystem.filtered()
4545
.by(probableThreat -> Double.compare(probableThreat.probability(), 0.99) == 0);
4646

4747
//then

filterer/src/test/java/com/iluwatar/filterer/threat/SimpleThreatAwareSystemTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class SimpleThreatAwareSystemTest {
3333
@Test
3434
void shouldFilterByThreatType() {
3535
//given
36-
Threat rootkit = new SimpleThreat(ThreatType.ROOTKIT, 1, "Simple-Rootkit");
37-
Threat trojan = new SimpleThreat(ThreatType.TROJAN, 2, "Simple-Trojan");
36+
var rootkit = new SimpleThreat(ThreatType.ROOTKIT, 1, "Simple-Rootkit");
37+
var trojan = new SimpleThreat(ThreatType.TROJAN, 2, "Simple-Trojan");
3838
List<Threat> threats = List.of(rootkit, trojan);
3939

40-
ThreatAwareSystem threatAwareSystem = new SimpleThreatAwareSystem("System-1", threats);
40+
var threatAwareSystem = new SimpleThreatAwareSystem("System-1", threats);
4141

4242
//when
43-
ThreatAwareSystem rootkitThreatAwareSystem = threatAwareSystem.filtered()
43+
var rootkitThreatAwareSystem = threatAwareSystem.filtered()
4444
.by(threat -> threat.type() == ThreatType.ROOTKIT);
4545

4646
//then

0 commit comments

Comments
 (0)