From: Dana Kutenicsova Date: Wed, 5 Oct 2016 20:20:13 +0000 (+0200) Subject: Removed sonar warnings. X-Git-Tag: release/carbon~394 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=a110503f173ba4fbeb07a61d3c7ebf1688dfc9d6 Removed sonar warnings. Change-Id: Ia29cb315308f0bb153447b8961b7dd9f2562ca65 Signed-off-by: Dana Kutenicsova --- diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java index a714fdc9d2..c81aa9bec5 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java @@ -56,30 +56,30 @@ public class XmlFileStorageAdapter implements StorageAdapter, Persister { return instance; } - File storage = extractStorageFileFromProperties(propertiesProvider); - LOG.debug("Using file {}", storage.getAbsolutePath()); + File localStorage = extractStorageFileFromProperties(propertiesProvider); + LOG.debug("Using file {}", localStorage.getAbsolutePath()); // Create file if it does not exist - File parentFile = storage.getAbsoluteFile().getParentFile(); - if (parentFile.exists() == false) { + File parentFile = localStorage.getAbsoluteFile().getParentFile(); + if (!parentFile.exists()) { LOG.debug("Creating parent folders {}", parentFile); parentFile.mkdirs(); } - if (storage.exists() == false) { + if (!localStorage.exists()) { LOG.debug("Storage file does not exist, creating empty file"); try { - boolean result = storage.createNewFile(); - if (result == false) { - throw new RuntimeException("Unable to create storage file " + storage); + boolean result = localStorage.createNewFile(); + if (!result) { + throw new RuntimeException("Unable to create storage file " + localStorage); } } catch (IOException e) { - throw new RuntimeException("Unable to create storage file " + storage, e); + throw new RuntimeException("Unable to create storage file " + localStorage, e); } } if (numberOfStoredBackups == 0) { throw new RuntimeException(NUMBER_OF_BACKUPS + " property should be either set to positive value, or ommited. Can not be set to 0."); } - setFileStorage(storage); + setFileStorage(localStorage); instance = this; return this; diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java index 68a33be5e6..63755f9e62 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java @@ -80,7 +80,7 @@ public final class Config { xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(from)); - return ((Config) um.unmarshal(xsr)); + return (Config) um.unmarshal(xsr); } catch (JAXBException | XMLStreamException e) { throw new PersistException("Unable to restore configuration", e); } @@ -104,7 +104,7 @@ public final class Config { } public void addConfigSnapshot(ConfigSnapshot snap, int numberOfStoredBackups) { - if(shouldReplaceLast(numberOfStoredBackups) && snapshots.isEmpty() == false) { + if (shouldReplaceLast(numberOfStoredBackups) && !snapshots.isEmpty()) { snapshots.remove(0); } snapshots.add(snap); diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java index 02ebb061f0..94cd58fc09 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java @@ -23,22 +23,22 @@ public class ConfigSnapshot { public static final String SNAPSHOT_ROOT_ELEMENT_NAME = "snapshot"; - private String configSnapshot; + private String configXml; private SortedSet capabilities = new TreeSet<>(); private Set features = new HashSet<>(); ConfigSnapshot(String configXml, SortedSet capabilities) { - this.configSnapshot = configXml; + this.configXml = configXml; this.capabilities = capabilities; } ConfigSnapshot(String configXml, SortedSet capabilities, Set features) { - this.configSnapshot = configXml; + this.configXml = configXml; this.capabilities = capabilities; this.features = features; } - public ConfigSnapshot() { + ConfigSnapshot() { } public static ConfigSnapshot fromConfigSnapshot(ConfigSnapshotHolder cfg) { @@ -51,11 +51,11 @@ public class ConfigSnapshot { @XmlAnyElement(SnapshotHandler.class) public String getConfigSnapshot() { - return configSnapshot; + return configXml; } public void setConfigSnapshot(String configSnapshot) { - this.configSnapshot = configSnapshot; + this.configXml = configSnapshot; } @XmlElement(name = "capability") @@ -83,12 +83,11 @@ public class ConfigSnapshot { @Override public String toString() { final StringBuilder sb = new StringBuilder("ConfigSnapshot{"); - sb.append("configSnapshot='").append(configSnapshot).append('\''); + sb.append("configSnapshot='").append(configXml).append('\''); sb.append(", capabilities=").append(capabilities); sb.append(", features=").append(features); sb.append('}'); return sb.toString(); } - } diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java index dacc35b83e..2970367c71 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java @@ -23,11 +23,13 @@ class SnapshotHandler implements DomHandler { private StringWriter xmlWriter = new StringWriter(); + @Override public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) { xmlWriter.getBuffer().setLength(0); return new StreamResult(xmlWriter); } + @Override public String getElement(StreamResult rt) { String xml = rt.getWriter().toString(); int beginIndex = xml.indexOf(START_TAG) + START_TAG.length(); @@ -37,6 +39,7 @@ class SnapshotHandler implements DomHandler { return xml.substring(beginIndex, endIndex); } + @Override public Source marshal(String n, ValidationEventHandler errorHandler) { try { String xml = START_TAG + n.trim() + END_TAG;