Code cleanup (#1461)
* Code cleanup * Fix flux tests * Fix checkstyle errors * Fix compile error
This commit is contained in:
parent
5381387026
commit
417f21ed3d
@ -47,7 +47,7 @@ public class AbstractDocumentTest {
|
||||
}
|
||||
}
|
||||
|
||||
private DocumentImplementation document = new DocumentImplementation(new HashMap<>());
|
||||
private final DocumentImplementation document = new DocumentImplementation(new HashMap<>());
|
||||
|
||||
@Test
|
||||
public void shouldPutAndGetValue() {
|
||||
|
@ -36,7 +36,7 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public class AbstractFactoryTest {
|
||||
|
||||
private App app = new App();
|
||||
private final App app = new App();
|
||||
private KingdomFactory elfFactory;
|
||||
private KingdomFactory orcFactory;
|
||||
|
||||
|
@ -37,7 +37,7 @@ import uk.org.lidalia.slf4jtest.TestLoggerFactory;
|
||||
*/
|
||||
public class ConfigureForDosVisitorTest {
|
||||
|
||||
private TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
|
||||
private final TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
|
||||
|
||||
@Test
|
||||
public void testVisitForZoom() {
|
||||
|
@ -56,7 +56,7 @@ And captain expects an implementation of `RowingBoat` interface to be able to mo
|
||||
```java
|
||||
public class Captain {
|
||||
|
||||
private RowingBoat rowingBoat;
|
||||
private final RowingBoat rowingBoat;
|
||||
// default constructor and setter for rowingBoat
|
||||
public Captain(RowingBoat rowingBoat) {
|
||||
this.rowingBoat = rowingBoat;
|
||||
@ -75,7 +75,7 @@ public class FishingBoatAdapter implements RowingBoat {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
|
||||
|
||||
private FishingBoat boat;
|
||||
private final FishingBoat boat;
|
||||
|
||||
public FishingBoatAdapter() {
|
||||
boat = new FishingBoat();
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.adapter;
|
||||
*/
|
||||
public class FishingBoatAdapter implements RowingBoat {
|
||||
|
||||
private FishingBoat boat;
|
||||
private final FishingBoat boat;
|
||||
|
||||
public FishingBoatAdapter() {
|
||||
boat = new FishingBoat();
|
||||
|
@ -48,7 +48,7 @@ class RemoteServiceTest {
|
||||
}
|
||||
|
||||
private static class StaticRandomProvider implements RandomProvider {
|
||||
private double value;
|
||||
private final double value;
|
||||
|
||||
StaticRandomProvider(double value) {
|
||||
this.value = value;
|
||||
|
@ -100,7 +100,7 @@ public class ThreadAsyncExecutor implements AsyncExecutor {
|
||||
void setValue(T value) {
|
||||
this.value = value;
|
||||
this.state = COMPLETED;
|
||||
this.callback.ifPresent(ac -> ac.onComplete(value, Optional.<Exception>empty()));
|
||||
this.callback.ifPresent(ac -> ac.onComplete(value, Optional.empty()));
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public class Client {
|
||||
|
||||
private BusinessDelegate businessDelegate;
|
||||
private final BusinessDelegate businessDelegate;
|
||||
|
||||
public Client(BusinessDelegate businessDelegate) {
|
||||
this.businessDelegate = businessDelegate;
|
||||
|
@ -28,5 +28,5 @@ package com.iluwatar.business.delegate;
|
||||
*/
|
||||
public enum ServiceType {
|
||||
|
||||
EJB, JMS;
|
||||
EJB, JMS
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ import java.util.Stack;
|
||||
*/
|
||||
public class VirtualMachine {
|
||||
|
||||
private Stack<Integer> stack = new Stack<>();
|
||||
private final Stack<Integer> stack = new Stack<>();
|
||||
|
||||
private Wizard[] wizards = new Wizard[2];
|
||||
private final Wizard[] wizards = new Wizard[2];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -104,7 +104,7 @@ public class VirtualMachineTest {
|
||||
bytecode[2] = LITERAL.getIntValue();
|
||||
bytecode[3] = 50; // health amount
|
||||
bytecode[4] = SET_HEALTH.getIntValue();
|
||||
bytecode[5] = LITERAL.getIntValue();;
|
||||
bytecode[5] = LITERAL.getIntValue();
|
||||
bytecode[6] = wizardNumber;
|
||||
bytecode[7] = GET_HEALTH.getIntValue();
|
||||
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.caching;
|
||||
public enum CachingPolicy {
|
||||
THROUGH("through"), AROUND("around"), BEHIND("behind"), ASIDE("aside");
|
||||
|
||||
private String policy;
|
||||
private final String policy;
|
||||
|
||||
CachingPolicy(String policy) {
|
||||
this.policy = policy;
|
||||
|
@ -65,7 +65,7 @@ Then the request handler hierarchy
|
||||
```java
|
||||
public abstract class RequestHandler {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
|
||||
private RequestHandler next;
|
||||
private final RequestHandler next;
|
||||
|
||||
public RequestHandler(RequestHandler next) {
|
||||
this.next = next;
|
||||
|
@ -33,7 +33,7 @@ public abstract class RequestHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
|
||||
|
||||
private RequestHandler next;
|
||||
private final RequestHandler next;
|
||||
|
||||
public RequestHandler(RequestHandler next) {
|
||||
this.next = next;
|
||||
|
@ -87,10 +87,7 @@ public class Car {
|
||||
} else if (!model.equals(other.model)) {
|
||||
return false;
|
||||
}
|
||||
if (year != other.year) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return year == other.year;
|
||||
}
|
||||
|
||||
public String getMake() {
|
||||
|
@ -29,7 +29,7 @@ import java.util.List;
|
||||
* A Person class that has the list of cars that the person owns and use.
|
||||
*/
|
||||
public class Person {
|
||||
private List<Car> cars;
|
||||
private final List<Car> cars;
|
||||
|
||||
/**
|
||||
* Constructor to create an instance of person.
|
||||
|
@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class AppTest {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class);
|
||||
|
||||
private List<Car> cars = CarFactory.createCars();
|
||||
private final List<Car> cars = CarFactory.createCars();
|
||||
|
||||
@Test
|
||||
public void testGetModelsAfter2000UsingFor() {
|
||||
|
@ -36,8 +36,8 @@ public class Wizard {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Wizard.class);
|
||||
|
||||
private Deque<Command> undoStack = new LinkedList<>();
|
||||
private Deque<Command> redoStack = new LinkedList<>();
|
||||
private final Deque<Command> undoStack = new LinkedList<>();
|
||||
private final Deque<Command> redoStack = new LinkedList<>();
|
||||
|
||||
public Wizard() {}
|
||||
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.command;
|
||||
|
||||
/**
|
||||
* Enumeration for target size.
|
||||
*/
|
||||
public enum Size {
|
||||
|
||||
SMALL("small"), NORMAL("normal");
|
||||
|
||||
private String title;
|
||||
|
||||
Size(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.command;
|
||||
|
||||
/**
|
||||
* Enumeration for target size.
|
||||
*/
|
||||
public enum Size {
|
||||
|
||||
SMALL("small"), NORMAL("normal");
|
||||
|
||||
private final String title;
|
||||
|
||||
Size(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.command;
|
||||
|
||||
/**
|
||||
* Enumeration for target visibility.
|
||||
*/
|
||||
public enum Visibility {
|
||||
|
||||
VISIBLE("visible"), INVISIBLE("invisible");
|
||||
|
||||
private String title;
|
||||
|
||||
Visibility(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.command;
|
||||
|
||||
/**
|
||||
* Enumeration for target visibility.
|
||||
*/
|
||||
public enum Visibility {
|
||||
|
||||
VISIBLE("visible"), INVISIBLE("invisible");
|
||||
|
||||
private final String title;
|
||||
|
||||
Visibility(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class Wizard {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Wizard.class);
|
||||
|
||||
private Deque<Command> undoStack = new LinkedList<>();
|
||||
private Deque<Command> redoStack = new LinkedList<>();
|
||||
private final Deque<Command> undoStack = new LinkedList<>();
|
||||
private final Deque<Command> redoStack = new LinkedList<>();
|
||||
|
||||
public Wizard() {
|
||||
// comment to ignore sonar issue: LEVEL critical
|
||||
|
@ -33,7 +33,7 @@ import java.util.Hashtable;
|
||||
*/
|
||||
|
||||
public class EmployeeDatabase extends Database<Order> {
|
||||
private Hashtable<String, Order> data;
|
||||
private final Hashtable<String, Order> data;
|
||||
|
||||
public EmployeeDatabase() {
|
||||
this.data = new Hashtable<>();
|
||||
|
@ -33,7 +33,7 @@ import java.util.Hashtable;
|
||||
*/
|
||||
|
||||
public class MessagingDatabase extends Database<MessageRequest> {
|
||||
private Hashtable<String, MessageRequest> data;
|
||||
private final Hashtable<String, MessageRequest> data;
|
||||
|
||||
public MessagingDatabase() {
|
||||
this.data = new Hashtable<>();
|
||||
|
@ -34,7 +34,7 @@ import java.util.Hashtable;
|
||||
|
||||
public class PaymentDatabase extends Database<PaymentRequest> {
|
||||
|
||||
private Hashtable<String, PaymentRequest> data;
|
||||
private final Hashtable<String, PaymentRequest> data;
|
||||
|
||||
public PaymentDatabase() {
|
||||
this.data = new Hashtable<>();
|
||||
|
@ -35,7 +35,7 @@ import java.util.List;
|
||||
|
||||
public class QueueDatabase extends Database<QueueTask> {
|
||||
|
||||
private Queue<QueueTask> data;
|
||||
private final Queue<QueueTask> data;
|
||||
public List<Exception> exceptionsList;
|
||||
|
||||
public QueueDatabase(Exception... exc) {
|
||||
|
@ -34,7 +34,7 @@ import java.util.Hashtable;
|
||||
|
||||
public class ShippingDatabase extends Database<ShippingRequest> {
|
||||
|
||||
private Hashtable<String, ShippingRequest> data;
|
||||
private final Hashtable<String, ShippingRequest> data;
|
||||
|
||||
public ShippingDatabase() {
|
||||
this.data = new Hashtable<>();
|
||||
|
@ -34,7 +34,7 @@ Taking our sentence example from above. Here we have the base class and differen
|
||||
```java
|
||||
public abstract class LetterComposite {
|
||||
|
||||
private List<LetterComposite> children = new ArrayList<>();
|
||||
private final List<LetterComposite> children = new ArrayList<>();
|
||||
|
||||
public void add(LetterComposite letter) {
|
||||
children.add(letter);
|
||||
@ -59,7 +59,7 @@ public abstract class LetterComposite {
|
||||
|
||||
public class Letter extends LetterComposite {
|
||||
|
||||
private char character;
|
||||
private final char character;
|
||||
|
||||
public Letter(char c) {
|
||||
this.character = c;
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.composite;
|
||||
*/
|
||||
public class Letter extends LetterComposite {
|
||||
|
||||
private char character;
|
||||
private final char character;
|
||||
|
||||
public Letter(char c) {
|
||||
this.character = c;
|
||||
|
@ -1,58 +1,58 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.composite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Composite interface.
|
||||
*/
|
||||
public abstract class LetterComposite {
|
||||
|
||||
private List<LetterComposite> children = new ArrayList<>();
|
||||
|
||||
public void add(LetterComposite letter) {
|
||||
children.add(letter);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return children.size();
|
||||
}
|
||||
|
||||
protected void printThisBefore() {
|
||||
}
|
||||
|
||||
protected void printThisAfter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print.
|
||||
*/
|
||||
public void print() {
|
||||
printThisBefore();
|
||||
children.forEach(LetterComposite::print);
|
||||
printThisAfter();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.composite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Composite interface.
|
||||
*/
|
||||
public abstract class LetterComposite {
|
||||
|
||||
private final List<LetterComposite> children = new ArrayList<>();
|
||||
|
||||
public void add(LetterComposite letter) {
|
||||
children.add(letter);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return children.size();
|
||||
}
|
||||
|
||||
protected void printThisBefore() {
|
||||
}
|
||||
|
||||
protected void printThisAfter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print.
|
||||
*/
|
||||
public void print() {
|
||||
printThisBefore();
|
||||
children.forEach(LetterComposite::print);
|
||||
printThisAfter();
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ import java.util.Objects;
|
||||
* User class.
|
||||
*/
|
||||
public class User {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private boolean isActive;
|
||||
private String userId;
|
||||
private final String firstName;
|
||||
private final String lastName;
|
||||
private final boolean isActive;
|
||||
private final String userId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -30,10 +30,10 @@ import java.util.Objects;
|
||||
*/
|
||||
public class UserDto {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private boolean isActive;
|
||||
private String email;
|
||||
private final String firstName;
|
||||
private final String lastName;
|
||||
private final boolean isActive;
|
||||
private final String email;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public class ConverterTest {
|
||||
|
||||
private UserConverter userConverter = new UserConverter();
|
||||
private final UserConverter userConverter = new UserConverter();
|
||||
|
||||
/**
|
||||
* Tests whether a converter created of opposite functions holds equality as a bijection.
|
||||
|
@ -34,7 +34,7 @@ import org.hibernate.SessionFactory;
|
||||
*/
|
||||
public class CommandServiceImpl implements ICommandService {
|
||||
|
||||
private SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
|
||||
private Author getAuthorByUsername(String username) {
|
||||
Author author;
|
||||
|
@ -38,7 +38,7 @@ import org.hibernate.transform.Transformers;
|
||||
*/
|
||||
public class QueryServiceImpl implements IQueryService {
|
||||
|
||||
private SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
private final SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
|
||||
|
||||
@Override
|
||||
public Author getAuthorByUsername(String username) {
|
||||
|
@ -112,7 +112,7 @@ public interface CustomerDao {
|
||||
|
||||
public class InMemoryCustomerDao implements CustomerDao {
|
||||
|
||||
private Map<Integer, Customer> idToCustomer = new HashMap<>();
|
||||
private final Map<Integer, Customer> idToCustomer = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Stream<Customer> getAll() {
|
||||
|
@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class App {
|
||||
private static final String DB_URL = "jdbc:h2:~/dao";
|
||||
private static Logger log = LoggerFactory.getLogger(App.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(App.class);
|
||||
private static final String ALL_CUSTOMERS = "customerDao.getAllCustomers(): ";
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
public class InMemoryCustomerDao implements CustomerDao {
|
||||
|
||||
private Map<Integer, Customer> idToCustomer = new HashMap<>();
|
||||
private final Map<Integer, Customer> idToCustomer = new HashMap<>();
|
||||
|
||||
/**
|
||||
* An eagerly evaluated stream of customers stored in memory.
|
||||
|
@ -50,7 +50,7 @@ public class DbCustomerDaoTest {
|
||||
|
||||
private static final String DB_URL = "jdbc:h2:~/dao";
|
||||
private DbCustomerDao dao;
|
||||
private Customer existingCustomer = new Customer(1, "Freddy", "Krueger");
|
||||
private final Customer existingCustomer = new Customer(1, "Freddy", "Krueger");
|
||||
|
||||
/**
|
||||
* Creates customers schema.
|
||||
|
@ -41,7 +41,7 @@ public class MessageCollectorMember implements Member {
|
||||
|
||||
private final String name;
|
||||
|
||||
private List<String> messages = new ArrayList<>();
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
public MessageCollectorMember(String name) {
|
||||
this.name = name;
|
||||
|
@ -1,83 +1,83 @@
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.datamapper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
|
||||
* database. Its responsibility is to transfer data between the two and also to isolate them from
|
||||
* each other. With Data Mapper the in-memory objects needn't know even that there's a database
|
||||
* present; they need no SQL interface code, and certainly no knowledge of the database schema. (The
|
||||
* database schema is always ignorant of the objects that use it.) Since it's a form of Mapper ,
|
||||
* Data Mapper itself is even unknown to the domain layer.
|
||||
*
|
||||
* <p>The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
|
||||
*/
|
||||
public final class App {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(App.class);
|
||||
private static final String STUDENT_STRING = "App.main(), student : ";
|
||||
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args.
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
|
||||
/* Create new data mapper for type 'first' */
|
||||
final var mapper = new StudentDataMapperImpl();
|
||||
|
||||
/* Create new student */
|
||||
var student = new Student(1, "Adam", 'A');
|
||||
|
||||
/* Add student in respectibe store */
|
||||
mapper.insert(student);
|
||||
|
||||
log.debug(STUDENT_STRING + student + ", is inserted");
|
||||
|
||||
/* Find this student */
|
||||
final var studentToBeFound = mapper.find(student.getStudentId());
|
||||
|
||||
log.debug(STUDENT_STRING + studentToBeFound + ", is searched");
|
||||
|
||||
/* Update existing student object */
|
||||
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
|
||||
|
||||
/* Update student in respectibe db */
|
||||
mapper.update(student);
|
||||
|
||||
log.debug(STUDENT_STRING + student + ", is updated");
|
||||
log.debug(STUDENT_STRING + student + ", is going to be deleted");
|
||||
|
||||
/* Delete student in db */
|
||||
mapper.delete(student);
|
||||
}
|
||||
|
||||
private App() {
|
||||
}
|
||||
}
|
||||
/*
|
||||
* The MIT License
|
||||
* Copyright © 2014-2019 Ilkka Seppälä
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.iluwatar.datamapper;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Data Mapper (DM) is a layer of software that separates the in-memory objects from the
|
||||
* database. Its responsibility is to transfer data between the two and also to isolate them from
|
||||
* each other. With Data Mapper the in-memory objects needn't know even that there's a database
|
||||
* present; they need no SQL interface code, and certainly no knowledge of the database schema. (The
|
||||
* database schema is always ignorant of the objects that use it.) Since it's a form of Mapper ,
|
||||
* Data Mapper itself is even unknown to the domain layer.
|
||||
*
|
||||
* <p>The below example demonstrates basic CRUD operations: Create, Read, Update, and Delete.
|
||||
*/
|
||||
public final class App {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(App.class);
|
||||
private static final String STUDENT_STRING = "App.main(), student : ";
|
||||
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args.
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
|
||||
/* Create new data mapper for type 'first' */
|
||||
final var mapper = new StudentDataMapperImpl();
|
||||
|
||||
/* Create new student */
|
||||
var student = new Student(1, "Adam", 'A');
|
||||
|
||||
/* Add student in respectibe store */
|
||||
mapper.insert(student);
|
||||
|
||||
log.debug(STUDENT_STRING + student + ", is inserted");
|
||||
|
||||
/* Find this student */
|
||||
final var studentToBeFound = mapper.find(student.getStudentId());
|
||||
|
||||
log.debug(STUDENT_STRING + studentToBeFound + ", is searched");
|
||||
|
||||
/* Update existing student object */
|
||||
student = new Student(student.getStudentId(), "AdamUpdated", 'A');
|
||||
|
||||
/* Update student in respectibe db */
|
||||
mapper.update(student);
|
||||
|
||||
log.debug(STUDENT_STRING + student + ", is updated");
|
||||
log.debug(STUDENT_STRING + student + ", is going to be deleted");
|
||||
|
||||
/* Delete student in db */
|
||||
mapper.delete(student);
|
||||
}
|
||||
|
||||
private App() {
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import java.util.Optional;
|
||||
public final class StudentDataMapperImpl implements StudentDataMapper {
|
||||
|
||||
/* Note: Normally this would be in the form of an actual database */
|
||||
private List<Student> students = new ArrayList<>();
|
||||
private final List<Student> students = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Optional<Student> find(int studentId) {
|
||||
|
@ -64,7 +64,7 @@ Customer resource class acts as the server for customer information.
|
||||
|
||||
```java
|
||||
public class CustomerResource {
|
||||
private List<CustomerDto> customers;
|
||||
private final List<CustomerDto> customers;
|
||||
|
||||
public CustomerResource(List<CustomerDto> customers) {
|
||||
this.customers = customers;
|
||||
|
@ -30,7 +30,7 @@ import java.util.List;
|
||||
* has all customer details.
|
||||
*/
|
||||
public class CustomerResource {
|
||||
private List<CustomerDto> customers;
|
||||
private final List<CustomerDto> customers;
|
||||
|
||||
/**
|
||||
* Initialise resource with existing customers.
|
||||
|
@ -70,7 +70,7 @@ public class ClubbedTroll implements Troll {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClubbedTroll.class);
|
||||
|
||||
private Troll decorated;
|
||||
private final Troll decorated;
|
||||
|
||||
public ClubbedTroll(Troll decorated) {
|
||||
this.decorated = decorated;
|
||||
|
@ -33,7 +33,7 @@ public class ClubbedTroll implements Troll {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClubbedTroll.class);
|
||||
|
||||
private Troll decorated;
|
||||
private final Troll decorated;
|
||||
|
||||
public ClubbedTroll(Troll decorated) {
|
||||
this.decorated = decorated;
|
||||
|
@ -68,7 +68,7 @@ public class SimpleTrollTest {
|
||||
|
||||
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender(Class clazz) {
|
||||
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
|
||||
|
@ -86,7 +86,7 @@ public class DelegateTest {
|
||||
*/
|
||||
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender() {
|
||||
((Logger) LoggerFactory.getLogger("root")).addAppender(this);
|
||||
|
@ -62,7 +62,7 @@ public interface Wizard {
|
||||
|
||||
public class AdvancedWizard implements Wizard {
|
||||
|
||||
private Tobacco tobacco;
|
||||
private final Tobacco tobacco;
|
||||
|
||||
public AdvancedWizard(Tobacco tobacco) {
|
||||
this.tobacco = tobacco;
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.dependency.injection;
|
||||
*/
|
||||
public class AdvancedWizard implements Wizard {
|
||||
|
||||
private Tobacco tobacco;
|
||||
private final Tobacco tobacco;
|
||||
|
||||
public AdvancedWizard(Tobacco tobacco) {
|
||||
this.tobacco = tobacco;
|
||||
|
@ -31,7 +31,7 @@ import javax.inject.Inject;
|
||||
*/
|
||||
public class GuiceWizard implements Wizard {
|
||||
|
||||
private Tobacco tobacco;
|
||||
private final Tobacco tobacco;
|
||||
|
||||
@Inject
|
||||
public GuiceWizard(Tobacco tobacco) {
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.dependency.injection;
|
||||
*/
|
||||
public class SimpleWizard implements Wizard {
|
||||
|
||||
private OldTobyTobacco tobacco = new OldTobyTobacco();
|
||||
private final OldTobyTobacco tobacco = new OldTobyTobacco();
|
||||
|
||||
public void smoke() {
|
||||
tobacco.smoke(this);
|
||||
|
@ -37,7 +37,7 @@ import java.util.List;
|
||||
*/
|
||||
public class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender(Class clazz) {
|
||||
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
|
||||
|
@ -34,7 +34,7 @@ import java.util.List;
|
||||
public class World {
|
||||
|
||||
private List<String> countries;
|
||||
private DataFetcher df;
|
||||
private final DataFetcher df;
|
||||
|
||||
public World() {
|
||||
this.countries = new ArrayList<String>();
|
||||
|
@ -33,7 +33,7 @@ public class FrameBuffer implements Buffer {
|
||||
public static final int WIDTH = 10;
|
||||
public static final int HEIGHT = 8;
|
||||
|
||||
private Pixel[] pixels = new Pixel[WIDTH * HEIGHT];
|
||||
private final Pixel[] pixels = new Pixel[WIDTH * HEIGHT];
|
||||
|
||||
public FrameBuffer() {
|
||||
clearAll();
|
||||
|
@ -31,7 +31,7 @@ public enum Pixel {
|
||||
WHITE(0),
|
||||
BLACK(1);
|
||||
|
||||
private int color;
|
||||
private final int color;
|
||||
|
||||
Pixel(int color) {
|
||||
this.color = color;
|
||||
|
@ -35,7 +35,7 @@ public class Scene {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Scene.class);
|
||||
|
||||
private Buffer[] frameBuffers;
|
||||
private final Buffer[] frameBuffers;
|
||||
|
||||
private int current;
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class InventoryTest {
|
||||
|
||||
|
||||
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender(Class clazz) {
|
||||
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
|
||||
|
@ -28,10 +28,10 @@ package com.iluwatar.doubledispatch;
|
||||
*/
|
||||
public class Rectangle {
|
||||
|
||||
private int left;
|
||||
private int top;
|
||||
private int right;
|
||||
private int bottom;
|
||||
private final int left;
|
||||
private final int top;
|
||||
private final int right;
|
||||
private final int bottom;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -31,7 +31,7 @@ public enum Event {
|
||||
STARK_SIGHTED("Stark sighted"), WARSHIPS_APPROACHING("Warships approaching"), TRAITOR_DETECTED(
|
||||
"Traitor detected");
|
||||
|
||||
private String description;
|
||||
private final String description;
|
||||
|
||||
Event(String description) {
|
||||
this.description = description;
|
||||
|
@ -31,7 +31,7 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class EventEmitter {
|
||||
|
||||
private List<EventObserver> observers;
|
||||
private final List<EventObserver> observers;
|
||||
|
||||
public EventEmitter() {
|
||||
observers = new LinkedList<>();
|
||||
|
@ -36,7 +36,7 @@ public enum Weekday {
|
||||
SATURDAY("Saturday"),
|
||||
SUNDAY("Sunday");
|
||||
|
||||
private String description;
|
||||
private final String description;
|
||||
|
||||
Weekday(String description) {
|
||||
this.description = description;
|
||||
|
@ -74,7 +74,7 @@ public class KingJoffreyTest {
|
||||
}
|
||||
|
||||
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender(Class<?> clazz) {
|
||||
((Logger) LoggerFactory.getLogger(clazz)).addAppender(this);
|
||||
|
@ -33,9 +33,9 @@ public class Event implements IEvent, Runnable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Event.class);
|
||||
|
||||
private int eventId;
|
||||
private int eventTime;
|
||||
private boolean isSynchronous;
|
||||
private final int eventId;
|
||||
private final int eventTime;
|
||||
private final boolean isSynchronous;
|
||||
private Thread thread;
|
||||
private boolean isComplete = false;
|
||||
private ThreadCompleteListener eventListener;
|
||||
|
@ -43,8 +43,8 @@ public class EventManager implements ThreadCompleteListener {
|
||||
public static final int MAX_ID = MAX_RUNNING_EVENTS;
|
||||
public static final int MAX_EVENT_TIME = 1800; // in seconds / 30 minutes.
|
||||
private int currentlyRunningSyncEvent = -1;
|
||||
private Random rand;
|
||||
private Map<Integer, Event> eventPool;
|
||||
private final Random rand;
|
||||
private final Map<Integer, Event> eventPool;
|
||||
|
||||
private static final String DOES_NOT_EXIST = " does not exist.";
|
||||
|
||||
|
@ -32,7 +32,7 @@ import com.iluwatar.eda.model.User;
|
||||
*/
|
||||
public class UserCreatedEvent extends AbstractEvent {
|
||||
|
||||
private User user;
|
||||
private final User user;
|
||||
|
||||
public UserCreatedEvent(User user) {
|
||||
this.user = user;
|
||||
|
@ -32,7 +32,7 @@ import com.iluwatar.eda.model.User;
|
||||
*/
|
||||
public class UserUpdatedEvent extends AbstractEvent {
|
||||
|
||||
private User user;
|
||||
private final User user;
|
||||
|
||||
public UserUpdatedEvent(User user) {
|
||||
this.user = user;
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class EventDispatcher {
|
||||
|
||||
private Map<Class<? extends Event>, Handler<? extends Event>> handlers;
|
||||
private final Map<Class<? extends Event>, Handler<? extends Event>> handlers;
|
||||
|
||||
public EventDispatcher() {
|
||||
handlers = new HashMap<>();
|
||||
|
@ -32,7 +32,7 @@ import com.iluwatar.eda.event.UserUpdatedEvent;
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String username;
|
||||
private final String username;
|
||||
|
||||
public User(String username) {
|
||||
this.username = username;
|
||||
|
@ -49,7 +49,7 @@ public class Audio {
|
||||
|
||||
private volatile Thread updateThread = null;
|
||||
|
||||
private PlayMessage[] pendingAudio = new PlayMessage[MAX_PENDING];
|
||||
private final PlayMessage[] pendingAudio = new PlayMessage[MAX_PENDING];
|
||||
|
||||
// Visible only for testing purposes
|
||||
Audio() {
|
||||
|
@ -35,7 +35,7 @@ public class Commander implements CommanderExtension {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Commander.class);
|
||||
|
||||
private CommanderUnit unit;
|
||||
private final CommanderUnit unit;
|
||||
|
||||
public Commander(CommanderUnit commanderUnit) {
|
||||
this.unit = commanderUnit;
|
||||
|
@ -35,7 +35,7 @@ public class Sergeant implements SergeantExtension {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Sergeant.class);
|
||||
|
||||
private SergeantUnit unit;
|
||||
private final SergeantUnit unit;
|
||||
|
||||
public Sergeant(SergeantUnit sergeantUnit) {
|
||||
this.unit = sergeantUnit;
|
||||
|
@ -34,7 +34,7 @@ import units.SoldierUnit;
|
||||
public class Soldier implements SoldierExtension {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class);
|
||||
|
||||
private SoldierUnit unit;
|
||||
private final SoldierUnit unit;
|
||||
|
||||
public Soldier(SoldierUnit soldierUnit) {
|
||||
this.unit = soldierUnit;
|
||||
|
@ -83,7 +83,7 @@ public abstract class DwarvenMineWorker {
|
||||
|
||||
public abstract String name();
|
||||
|
||||
static enum Action {
|
||||
enum Action {
|
||||
GO_TO_SLEEP, WAKE_UP, GO_HOME, GO_TO_MINE, WORK
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class DwarvenGoldmineFacadeTest {
|
||||
|
||||
private class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender() {
|
||||
((Logger) LoggerFactory.getLogger("root")).addAppender(this);
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class ElfBlacksmith implements Blacksmith {
|
||||
|
||||
private static Map<WeaponType, ElfWeapon> ELFARSENAL;
|
||||
private static final Map<WeaponType, ElfWeapon> ELFARSENAL;
|
||||
|
||||
static {
|
||||
ELFARSENAL = new HashMap<>(WeaponType.values().length);
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.factory.method;
|
||||
*/
|
||||
public class ElfWeapon implements Weapon {
|
||||
|
||||
private WeaponType weaponType;
|
||||
private final WeaponType weaponType;
|
||||
|
||||
public ElfWeapon(WeaponType weaponType) {
|
||||
this.weaponType = weaponType;
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class OrcBlacksmith implements Blacksmith {
|
||||
|
||||
private static Map<WeaponType, OrcWeapon> ORCARSENAL;
|
||||
private static final Map<WeaponType, OrcWeapon> ORCARSENAL;
|
||||
|
||||
static {
|
||||
ORCARSENAL = new HashMap<>(WeaponType.values().length);
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.factory.method;
|
||||
*/
|
||||
public class OrcWeapon implements Weapon {
|
||||
|
||||
private WeaponType weaponType;
|
||||
private final WeaponType weaponType;
|
||||
|
||||
public OrcWeapon(WeaponType weaponType) {
|
||||
this.weaponType = weaponType;
|
||||
|
@ -30,7 +30,7 @@ public enum WeaponType {
|
||||
|
||||
SHORT_SWORD("short sword"), SPEAR("spear"), AXE("axe"), UNDEFINED("");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
WeaponType(String title) {
|
||||
this.title = title;
|
||||
|
@ -42,7 +42,7 @@ import java.util.Properties;
|
||||
*/
|
||||
public class PropertiesFeatureToggleVersion implements Service {
|
||||
|
||||
private boolean isEnhanced;
|
||||
private final boolean isEnhanced;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link PropertiesFeatureToggleVersion} using the passed {@link
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.featuretoggle.user;
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Default Constructor setting the username.
|
||||
|
@ -35,8 +35,8 @@ import java.util.List;
|
||||
*/
|
||||
public class UserGroup {
|
||||
|
||||
private static List<User> freeGroup = new ArrayList<>();
|
||||
private static List<User> paidGroup = new ArrayList<>();
|
||||
private static final List<User> freeGroup = new ArrayList<>();
|
||||
private static final List<User> paidGroup = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -94,7 +94,7 @@ public class App {
|
||||
.filter(positives())
|
||||
.first(4)
|
||||
.last(2)
|
||||
.map(number -> "String[" + valueOf(number) + "]")
|
||||
.map(number -> "String[" + number + "]")
|
||||
.asList();
|
||||
prettyPrint("The lazy list contains the last two of the first four positive numbers "
|
||||
+ "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
|
||||
|
@ -198,7 +198,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new DecoratingIterator<T>(null) {
|
||||
Iterator<E> oldTypeIterator = iterable.iterator();
|
||||
final Iterator<E> oldTypeIterator = iterable.iterator();
|
||||
|
||||
@Override
|
||||
public T computeNext() {
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.flux.action;
|
||||
*/
|
||||
public abstract class Action {
|
||||
|
||||
private ActionType type;
|
||||
private final ActionType type;
|
||||
|
||||
public Action(ActionType type) {
|
||||
this.type = type;
|
||||
|
@ -28,6 +28,6 @@ package com.iluwatar.flux.action;
|
||||
*/
|
||||
public enum ActionType {
|
||||
|
||||
MENU_ITEM_SELECTED, CONTENT_CHANGED;
|
||||
MENU_ITEM_SELECTED, CONTENT_CHANGED
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public enum Content {
|
||||
PRODUCTS("Products - This page lists the company's products."), COMPANY(
|
||||
"Company - This page displays information about the company.");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
Content(String title) {
|
||||
this.title = title;
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.flux.action;
|
||||
*/
|
||||
public class ContentAction extends Action {
|
||||
|
||||
private Content content;
|
||||
private final Content content;
|
||||
|
||||
public ContentAction(Content content) {
|
||||
super(ActionType.CONTENT_CHANGED);
|
||||
|
@ -29,7 +29,7 @@ package com.iluwatar.flux.action;
|
||||
*/
|
||||
public class MenuAction extends Action {
|
||||
|
||||
private MenuItem menuItem;
|
||||
private final MenuItem menuItem;
|
||||
|
||||
public MenuAction(MenuItem menuItem) {
|
||||
super(ActionType.MENU_ITEM_SELECTED);
|
||||
|
@ -30,7 +30,7 @@ public enum MenuItem {
|
||||
|
||||
HOME("Home"), PRODUCTS("Products"), COMPANY("Company");
|
||||
|
||||
private String title;
|
||||
private final String title;
|
||||
|
||||
MenuItem(String title) {
|
||||
this.title = title;
|
||||
|
@ -39,7 +39,7 @@ public final class Dispatcher {
|
||||
|
||||
private static Dispatcher instance = new Dispatcher();
|
||||
|
||||
private List<Store> stores = new LinkedList<>();
|
||||
private final List<Store> stores = new LinkedList<>();
|
||||
|
||||
private Dispatcher() {
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class Store {
|
||||
|
||||
private List<View> views = new LinkedList<>();
|
||||
private final List<View> views = new LinkedList<>();
|
||||
|
||||
public abstract void onAction(Action action);
|
||||
|
||||
|
@ -34,8 +34,8 @@ public class AlchemistShop {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AlchemistShop.class);
|
||||
|
||||
private List<Potion> topShelf;
|
||||
private List<Potion> bottomShelf;
|
||||
private final List<Potion> topShelf;
|
||||
private final List<Potion> bottomShelf;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -36,7 +36,7 @@ import java.util.List;
|
||||
*/
|
||||
public class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private List<ILoggingEvent> log = new LinkedList<>();
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
public InMemoryAppender() {
|
||||
((Logger) LoggerFactory.getLogger("root")).addAppender(this);
|
||||
|
@ -95,7 +95,7 @@ public class App {
|
||||
* ArithmeticSumTask.
|
||||
*/
|
||||
static class ArithmeticSumTask implements AsyncTask<Long> {
|
||||
private long numberOfElements;
|
||||
private final long numberOfElements;
|
||||
|
||||
public ArithmeticSumTask(long numberOfElements) {
|
||||
this.numberOfElements = numberOfElements;
|
||||
|
@ -48,7 +48,7 @@ public class AsynchronousService {
|
||||
* tasks should be performed in the background which does not affect the performance of main
|
||||
* thread.
|
||||
*/
|
||||
private ExecutorService service;
|
||||
private final ExecutorService service;
|
||||
|
||||
/**
|
||||
* Creates an asynchronous service using {@code workQueue} as communication channel between
|
||||
|
@ -32,7 +32,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class InMemoryBank implements WireTransfers {
|
||||
|
||||
private static Map<String, Integer> accounts = new HashMap<>();
|
||||
private static final Map<String, Integer> accounts = new HashMap<>();
|
||||
|
||||
static {
|
||||
accounts
|
||||
|
@ -34,7 +34,7 @@ import java.util.Optional;
|
||||
*/
|
||||
public class InMemoryTicketRepository implements LotteryTicketRepository {
|
||||
|
||||
private static Map<LotteryTicketId, LotteryTicket> tickets = new HashMap<>();
|
||||
private static final Map<LotteryTicketId, LotteryTicket> tickets = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Optional<LotteryTicket> findById(LotteryTicketId id) {
|
||||
|
@ -116,7 +116,7 @@ public class LotteryNumbers {
|
||||
*/
|
||||
private static class RandomNumberGenerator {
|
||||
|
||||
private PrimitiveIterator.OfInt randomIterator;
|
||||
private final PrimitiveIterator.OfInt randomIterator;
|
||||
|
||||
/**
|
||||
* Initialize a new random number generator that generates random numbers in the range [min,
|
||||
|
@ -30,7 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
public class LotteryTicketId {
|
||||
|
||||
private static AtomicInteger numAllocated = new AtomicInteger(0);
|
||||
private static final AtomicInteger numAllocated = new AtomicInteger(0);
|
||||
private final int id;
|
||||
|
||||
public LotteryTicketId() {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user