Removed sonar warnings. 05/46705/5
authorDana Kutenicsova <dana.kutenics@gmail.com>
Wed, 5 Oct 2016 20:20:13 +0000 (22:20 +0200)
committerDana Kutenicsova <dana.kutenics@gmail.com>
Tue, 15 Nov 2016 12:59:57 +0000 (12:59 +0000)
Change-Id: Ia29cb315308f0bb153447b8961b7dd9f2562ca65
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java

index a714fdc9d27dd4c1901fa1f0ef25045b82cb138b..c81aa9bec5398a4ed20259cc240fda14075eac81 100644 (file)
@@ -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;
index 68a33be5e67e02cf30f9fa83ca123fd82545ad76..63755f9e62c69d56c37dfa6442c91447bf42b8f7 100644 (file)
@@ -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);
index 02ebb061f058e4f7de68afa57048a2f8683651b0..94cd58fc090e54443ad8619517020361149a4454 100644 (file)
@@ -23,22 +23,22 @@ public class ConfigSnapshot {
 
     public static final String SNAPSHOT_ROOT_ELEMENT_NAME = "snapshot";
 
-    private String configSnapshot;
+    private String configXml;
     private SortedSet<String> capabilities = new TreeSet<>();
     private Set<String> features = new HashSet<>();
 
     ConfigSnapshot(String configXml, SortedSet<String> capabilities) {
-        this.configSnapshot = configXml;
+        this.configXml = configXml;
         this.capabilities = capabilities;
     }
 
     ConfigSnapshot(String configXml, SortedSet<String> capabilities, Set<String> 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();
     }
-
 }
 
index dacc35b83e4a7c8dfa6bb635bf97f936e6861391..2970367c719d55b0d6a27b725806ec66464cb952 100644 (file)
@@ -23,11 +23,13 @@ class SnapshotHandler implements DomHandler<String, StreamResult> {
 
     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<String, StreamResult> {
         return xml.substring(beginIndex, endIndex);
     }
 
+    @Override
     public Source marshal(String n, ValidationEventHandler errorHandler) {
         try {
             String xml = START_TAG + n.trim() + END_TAG;