Skip to content

Commit 417f21e

Browse files
authored
Code cleanup (iluwatar#1461)
* Code cleanup * Fix flux tests * Fix checkstyle errors * Fix compile error
1 parent 5381387 commit 417f21e

File tree

243 files changed

+1154
-1162
lines changed

Some content is hidden

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

243 files changed

+1154
-1162
lines changed

abstract-document/src/test/java/com/iluwatar/abstractdocument/AbstractDocumentTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private class DocumentImplementation extends AbstractDocument {
4747
}
4848
}
4949

50-
private DocumentImplementation document = new DocumentImplementation(new HashMap<>());
50+
private final DocumentImplementation document = new DocumentImplementation(new HashMap<>());
5151

5252
@Test
5353
public void shouldPutAndGetValue() {

abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public class AbstractFactoryTest {
3838

39-
private App app = new App();
39+
private final App app = new App();
4040
private KingdomFactory elfFactory;
4141
private KingdomFactory orcFactory;
4242

acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class ConfigureForDosVisitorTest {
3939

40-
private TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
40+
private final TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
4141

4242
@Test
4343
public void testVisitForZoom() {

adapter/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ And captain expects an implementation of `RowingBoat` interface to be able to mo
5656
```java
5757
public class Captain {
5858

59-
private RowingBoat rowingBoat;
59+
private final RowingBoat rowingBoat;
6060
// default constructor and setter for rowingBoat
6161
public Captain(RowingBoat rowingBoat) {
6262
this.rowingBoat = rowingBoat;
@@ -75,7 +75,7 @@ public class FishingBoatAdapter implements RowingBoat {
7575

7676
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
7777

78-
private FishingBoat boat;
78+
private final FishingBoat boat;
7979

8080
public FishingBoatAdapter() {
8181
boat = new FishingBoat();

adapter/src/main/java/com/iluwatar/adapter/FishingBoatAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public class FishingBoatAdapter implements RowingBoat {
3131

32-
private FishingBoat boat;
32+
private final FishingBoat boat;
3333

3434
public FishingBoatAdapter() {
3535
boat = new FishingBoat();

ambassador/src/test/java/com/iluwatar/ambassador/RemoteServiceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void testSuccessfulCall() {
4848
}
4949

5050
private static class StaticRandomProvider implements RandomProvider {
51-
private double value;
51+
private final double value;
5252

5353
StaticRandomProvider(double value) {
5454
this.value = value;

async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static class CompletableResult<T> implements AsyncResult<T> {
100100
void setValue(T value) {
101101
this.value = value;
102102
this.state = COMPLETED;
103-
this.callback.ifPresent(ac -> ac.onComplete(value, Optional.<Exception>empty()));
103+
this.callback.ifPresent(ac -> ac.onComplete(value, Optional.empty()));
104104
synchronized (lock) {
105105
lock.notifyAll();
106106
}

business-delegate/src/main/java/com/iluwatar/business/delegate/Client.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class Client {
3030

31-
private BusinessDelegate businessDelegate;
31+
private final BusinessDelegate businessDelegate;
3232

3333
public Client(BusinessDelegate businessDelegate) {
3434
this.businessDelegate = businessDelegate;

business-delegate/src/main/java/com/iluwatar/business/delegate/ServiceType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
*/
2929
public enum ServiceType {
3030

31-
EJB, JMS;
31+
EJB, JMS
3232
}

bytecode/src/main/java/com/iluwatar/bytecode/VirtualMachine.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
*/
3131
public class VirtualMachine {
3232

33-
private Stack<Integer> stack = new Stack<>();
33+
private final Stack<Integer> stack = new Stack<>();
3434

35-
private Wizard[] wizards = new Wizard[2];
35+
private final Wizard[] wizards = new Wizard[2];
3636

3737
/**
3838
* Constructor.

bytecode/src/test/java/com/iluwatar/bytecode/VirtualMachineTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void testGetHealth() {
104104
bytecode[2] = LITERAL.getIntValue();
105105
bytecode[3] = 50; // health amount
106106
bytecode[4] = SET_HEALTH.getIntValue();
107-
bytecode[5] = LITERAL.getIntValue();;
107+
bytecode[5] = LITERAL.getIntValue();
108108
bytecode[6] = wizardNumber;
109109
bytecode[7] = GET_HEALTH.getIntValue();
110110

caching/src/main/java/com/iluwatar/caching/CachingPolicy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public enum CachingPolicy {
3030
THROUGH("through"), AROUND("around"), BEHIND("behind"), ASIDE("aside");
3131

32-
private String policy;
32+
private final String policy;
3333

3434
CachingPolicy(String policy) {
3535
this.policy = policy;

chain/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Then the request handler hierarchy
6565
```java
6666
public abstract class RequestHandler {
6767
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
68-
private RequestHandler next;
68+
private final RequestHandler next;
6969

7070
public RequestHandler(RequestHandler next) {
7171
this.next = next;

chain/src/main/java/com/iluwatar/chain/RequestHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class RequestHandler {
3333

3434
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
3535

36-
private RequestHandler next;
36+
private final RequestHandler next;
3737

3838
public RequestHandler(RequestHandler next) {
3939
this.next = next;

collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Car.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ public boolean equals(Object obj) {
8787
} else if (!model.equals(other.model)) {
8888
return false;
8989
}
90-
if (year != other.year) {
91-
return false;
92-
}
93-
return true;
90+
return year == other.year;
9491
}
9592

9693
public String getMake() {

collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/Person.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* A Person class that has the list of cars that the person owns and use.
3030
*/
3131
public class Person {
32-
private List<Car> cars;
32+
private final List<Car> cars;
3333

3434
/**
3535
* Constructor to create an instance of person.

collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public class AppTest {
3838
private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class);
3939

40-
private List<Car> cars = CarFactory.createCars();
40+
private final List<Car> cars = CarFactory.createCars();
4141

4242
@Test
4343
public void testGetModelsAfter2000UsingFor() {

command/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class Wizard {
3636

3737
private static final Logger LOGGER = LoggerFactory.getLogger(Wizard.class);
3838

39-
private Deque<Command> undoStack = new LinkedList<>();
40-
private Deque<Command> redoStack = new LinkedList<>();
39+
private final Deque<Command> undoStack = new LinkedList<>();
40+
private final Deque<Command> redoStack = new LinkedList<>();
4141

4242
public Wizard() {}
4343

Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
/*
2-
* The MIT License
3-
* Copyright © 2014-2019 Ilkka Seppälä
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in
13-
* all copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
* THE SOFTWARE.
22-
*/
23-
24-
package com.iluwatar.command;
25-
26-
/**
27-
* Enumeration for target size.
28-
*/
29-
public enum Size {
30-
31-
SMALL("small"), NORMAL("normal");
32-
33-
private String title;
34-
35-
Size(String title) {
36-
this.title = title;
37-
}
38-
39-
@Override
40-
public String toString() {
41-
return title;
42-
}
43-
}
1+
/*
2+
* The MIT License
3+
* Copyright © 2014-2019 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
package com.iluwatar.command;
25+
26+
/**
27+
* Enumeration for target size.
28+
*/
29+
public enum Size {
30+
31+
SMALL("small"), NORMAL("normal");
32+
33+
private final String title;
34+
35+
Size(String title) {
36+
this.title = title;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return title;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
/*
2-
* The MIT License
3-
* Copyright © 2014-2019 Ilkka Seppälä
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in
13-
* all copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
* THE SOFTWARE.
22-
*/
23-
24-
package com.iluwatar.command;
25-
26-
/**
27-
* Enumeration for target visibility.
28-
*/
29-
public enum Visibility {
30-
31-
VISIBLE("visible"), INVISIBLE("invisible");
32-
33-
private String title;
34-
35-
Visibility(String title) {
36-
this.title = title;
37-
}
38-
39-
@Override
40-
public String toString() {
41-
return title;
42-
}
43-
}
1+
/*
2+
* The MIT License
3+
* Copyright © 2014-2019 Ilkka Seppälä
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
package com.iluwatar.command;
25+
26+
/**
27+
* Enumeration for target visibility.
28+
*/
29+
public enum Visibility {
30+
31+
VISIBLE("visible"), INVISIBLE("invisible");
32+
33+
private final String title;
34+
35+
Visibility(String title) {
36+
this.title = title;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return title;
42+
}
43+
}

command/src/main/java/com/iluwatar/command/Wizard.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public class Wizard {
3535

3636
private static final Logger LOGGER = LoggerFactory.getLogger(Wizard.class);
3737

38-
private Deque<Command> undoStack = new LinkedList<>();
39-
private Deque<Command> redoStack = new LinkedList<>();
38+
private final Deque<Command> undoStack = new LinkedList<>();
39+
private final Deque<Command> redoStack = new LinkedList<>();
4040

4141
public Wizard() {
4242
// comment to ignore sonar issue: LEVEL critical

commander/src/main/java/com/iluwatar/commander/employeehandle/EmployeeDatabase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434

3535
public class EmployeeDatabase extends Database<Order> {
36-
private Hashtable<String, Order> data;
36+
private final Hashtable<String, Order> data;
3737

3838
public EmployeeDatabase() {
3939
this.data = new Hashtable<>();

commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingDatabase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434

3535
public class MessagingDatabase extends Database<MessageRequest> {
36-
private Hashtable<String, MessageRequest> data;
36+
private final Hashtable<String, MessageRequest> data;
3737

3838
public MessagingDatabase() {
3939
this.data = new Hashtable<>();

commander/src/main/java/com/iluwatar/commander/paymentservice/PaymentDatabase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
public class PaymentDatabase extends Database<PaymentRequest> {
3636

37-
private Hashtable<String, PaymentRequest> data;
37+
private final Hashtable<String, PaymentRequest> data;
3838

3939
public PaymentDatabase() {
4040
this.data = new Hashtable<>();

commander/src/main/java/com/iluwatar/commander/queue/QueueDatabase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
public class QueueDatabase extends Database<QueueTask> {
3737

38-
private Queue<QueueTask> data;
38+
private final Queue<QueueTask> data;
3939
public List<Exception> exceptionsList;
4040

4141
public QueueDatabase(Exception... exc) {

0 commit comments

Comments
 (0)