Make fields immutable (final) where possible

This commit is contained in:
René Scheibe
2022-06-08 16:13:03 +02:00
committed by GitHub
parent 9f4428153c
commit 80af14a2e6
40 changed files with 80 additions and 84 deletions

View File

@@ -36,8 +36,8 @@ import org.apache.ftpserver.usermanager.impl.WritePermission;
*
*/
public class TestUserManager extends AbstractUserManager {
private BaseUser testUser;
private BaseUser anonUser;
private final BaseUser testUser;
private final BaseUser anonUser;
private static final String TEST_USERNAME = "demo";
private static final String TEST_PASSWORD = "demo";

View File

@@ -42,7 +42,7 @@ import org.springframework.messaging.support.GenericMessage;
*/
public class HelloWorldApp {
private static Log logger = LogFactory.getLog(HelloWorldApp.class);
private static final Log logger = LogFactory.getLog(HelloWorldApp.class);
public static void main(String[] args) {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);

View File

@@ -27,7 +27,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*/
public class HttpClientDemo {
private static Log logger = LogFactory.getLog(HttpClientDemo.class);
private static final Log logger = LogFactory.getLog(HttpClientDemo.class);
public static void main(String[] args) {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(

View File

@@ -27,9 +27,9 @@ import java.util.Map;
public enum Gender {
MALE("M"),FEMALE("F");
private static Map<String, Gender> map;
private String identifier;
private static final Map<String, Gender> map;
private final String identifier;
private Gender(String identifier) {
this.identifier = identifier;
@@ -37,12 +37,12 @@ public enum Gender {
public String getIdentifier() {
return identifier;
}
}
public static Gender getGenderByIdentifier(String identifier) {
return map.get(identifier);
}
static {
map = new HashMap<String, Gender>();
for(Gender gender:EnumSet.allOf(Gender.class)) {

View File

@@ -13,9 +13,9 @@
package org.springframework.integration.samples.jdbc.domain;
public class User {
private String username;
private String password;
private String email;
private final String username;
private final String password;
private final String email;
public User(String username, String password, String email) {
super();

View File

@@ -30,7 +30,7 @@ import org.springframework.messaging.MessagingException;
*
*/
public class GmailInboundImapIdleAdapterTestApp {
private static Log logger = LogFactory.getLog(GmailInboundImapIdleAdapterTestApp.class);
private static final Log logger = LogFactory.getLog(GmailInboundImapIdleAdapterTestApp.class);
public static void main (String[] args) throws Exception {

View File

@@ -32,7 +32,7 @@ import org.springframework.messaging.MessagingException;
*/
public class GmailInboundPop3AdapterTestApp {
private static Log logger = LogFactory.getLog(GmailInboundPop3AdapterTestApp.class);
private static final Log logger = LogFactory.getLog(GmailInboundPop3AdapterTestApp.class);
public static void main (String[] args) throws Exception {
@SuppressWarnings("resource")

View File

@@ -40,10 +40,10 @@ import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
*/
public class BrokerRunning extends TestWatcher {
private static Log logger = LogFactory.getLog(BrokerRunning.class);
private static final Log logger = LogFactory.getLog(BrokerRunning.class);
// Static so that we only test once on failure: speeds up test suite
private static Map<Integer, Boolean> brokerOnline = new HashMap<>();
private static final Map<Integer, Boolean> brokerOnline = new HashMap<>();
private final int port;

View File

@@ -34,7 +34,7 @@ import org.springframework.integration.annotation.ServiceActivator;
*/
@MessageEndpoint
public class EvenLogger {
private static Log logger = LogFactory.getLog(EvenLogger.class);
private static final Log logger = LogFactory.getLog(EvenLogger.class);
@ServiceActivator
public void log(int i) {

View File

@@ -34,7 +34,7 @@ import org.springframework.integration.annotation.ServiceActivator;
*/
@MessageEndpoint
public class OddLogger {
private static Log logger = LogFactory.getLog(OddLogger.class);
private static final Log logger = LogFactory.getLog(OddLogger.class);
@ServiceActivator
public void log(int i) {

View File

@@ -23,9 +23,9 @@ import java.math.BigDecimal;
*/
public class Quote {
private String ticker;
private final String ticker;
private BigDecimal price;
private final BigDecimal price;
public Quote(String ticker, BigDecimal price) {
this.ticker = ticker;

View File

@@ -25,9 +25,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
*/
public class CustomOrder {
private int number;
private final int number;
private String sender;
private final String sender;
private String message;

View File

@@ -25,16 +25,16 @@ import java.util.Map;
*/
public class Traffic {
private Map<String, String> incidents = new HashMap<String, String>();
private final Map<String, String> incidents = new HashMap<String, String>();
public void addIncident(String title, String description){
incidents.put(title, description);
}
public Map<String, String> getIncidents(){
return incidents;
}
public String toString(){
return "Traffic: {" + incidents.keySet().toString() + "}";
}

View File

@@ -40,8 +40,8 @@ import org.w3c.dom.Node;
* @since SpringOne2GX - 2010, Chicago
*/
public class TrafficHttpConverter implements HttpMessageConverter<Traffic> {
private List<MediaType> supportedMediaTypes = Collections.emptyList();
private final List<MediaType> supportedMediaTypes = Collections.emptyList();
public boolean canRead(Class<?> clazz, MediaType mediaType) {
return Traffic.class.equals(clazz);
}

View File

@@ -47,9 +47,9 @@ public class WeatherMarshaller implements Marshaller, Unmarshaller, Initializing
private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
private Map<String, String> namespacePrefixes = new HashMap<String, String>();
private final Map<String, String> namespacePrefixes = new HashMap<String, String>();
private String xpathPrefix = "/p:GetCityWeatherByZIPResponse/p:GetCityWeatherByZIPResult/";
private static final String XPATH_PREFIX = "/p:GetCityWeatherByZIPResponse/p:GetCityWeatherByZIPResult/";
public Object unmarshal(Source source) throws IOException, XmlMappingException {
@@ -63,16 +63,16 @@ public class WeatherMarshaller implements Marshaller, Unmarshaller, Initializing
throw new MarshallingFailureException("Failed to unmarshal SOAP Response", e);
}
Weather weather = new Weather();
String expression = xpathPrefix + "p:City";
String expression = XPATH_PREFIX + "p:City";
String city = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setCity(city);
expression = xpathPrefix + "p:State";
expression = XPATH_PREFIX + "p:State";
String state = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setState(state);
expression = xpathPrefix + "p:Temperature";
expression = XPATH_PREFIX + "p:Temperature";
String temperature = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setTemperature(temperature);
expression = xpathPrefix + "p:Description";
expression = XPATH_PREFIX + "p:Description";
String description = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
weather.setDescription(description);
return weather;

View File

@@ -41,7 +41,7 @@ import org.springframework.xml.transform.StringSource;
*/
public class InContainerTests {
private static Log logger = LogFactory.getLog(InContainerTests.class);
private static final Log logger = LogFactory.getLog(InContainerTests.class);
private static final String WS_URI = "http://localhost:8080/ws-inbound-gateway/echoservice";
private final WebServiceTemplate template = new WebServiceTemplate();

View File

@@ -25,7 +25,7 @@ import org.w3c.dom.Document;
* @author Gary Russell
*/
public class ExternalResupply {
private static Log logger = LogFactory.getLog(ExternalResupply.class);
private static final Log logger = LogFactory.getLog(ExternalResupply.class);
public void orderResupply(Document resupplyOrder) {
logger.info("Placing resupply order: \n" + XmlUtil.docAsString(resupplyOrder));

View File

@@ -25,7 +25,7 @@ import org.w3c.dom.Document;
* @author Gary Russell
*/
public class WarehouseDispatch {
private static Log logger = LogFactory.getLog(WarehouseDispatch.class);
private static final Log logger = LogFactory.getLog(WarehouseDispatch.class);
public void dispatch(Document orderItem){
logger.info("Warehouse dispatching orderItem: \n" + XmlUtil.docAsString(orderItem));