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

@@ -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;