Remove yang-test
[controller.git] / opendaylight / config / config-api / src / main / java / org / opendaylight / controller / config / api / ValidationException.java
index f27d12399528c38c144fc17ea0354c243365a1a6..9daacd16dcffcbf1b2de9fdbbf4146124d9832ca 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -15,42 +15,41 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 /**
- * This exception is not intended to be used while implementing modules,
- * itaggregates validation exceptions and sends them back to the user.
+ * This exception is not intended to be used while implementing modules, it
+ * aggregates validation exceptions and sends them back to the user. Use
+ * {@link org.opendaylight.controller.config.api.JmxAttributeValidationException}
+ * for validating modules instead.
  */
-public class ValidationException extends RuntimeException {
+public class ValidationException extends Exception {
     private static final long serialVersionUID = -6072893219820274247L;
 
-    private final Map<String/* module name */, Map<String/* instance name */, ExceptionMessageWithStackTrace>> failedValidations;
+    private final Map<String/* module name */,
+        Map<String/* instance name */,
+        ExceptionMessageWithStackTrace>> failedValidations;
 
     public ValidationException(
-            Map<String /* module name */, Map<String /* instance name */, ExceptionMessageWithStackTrace>> failedValidations) {
+            final Map<String /* module name */,
+            Map<String /* instance name */,
+            ExceptionMessageWithStackTrace>> failedValidations) {
         super(failedValidations.toString());
         this.failedValidations = Collections.unmodifiableMap(failedValidations);
     }
 
     public static ValidationException createFromCollectedValidationExceptions(
-            List<ValidationException> collectedExceptions) {
+            final List<ValidationException> collectedExceptions) {
         Map<String, Map<String, ExceptionMessageWithStackTrace>> failedValidations = new HashMap<>();
         for (ValidationException ve : collectedExceptions) {
-            for (Entry<String, Map<String, ExceptionMessageWithStackTrace>> outerEntry : ve
-                    .getFailedValidations().entrySet()) {
-                for (Entry<String, ExceptionMessageWithStackTrace> innerEntry : outerEntry
-                        .getValue().entrySet()) {
+            for (Entry<String, Map<String, ExceptionMessageWithStackTrace>> outerEntry : ve.getFailedValidations()
+                    .entrySet()) {
+                for (Entry<String, ExceptionMessageWithStackTrace> innerEntry : outerEntry.getValue().entrySet()) {
                     String moduleName = outerEntry.getKey();
                     String instanceName = innerEntry.getKey();
                     ExceptionMessageWithStackTrace ex = innerEntry.getValue();
                     Map<String, ExceptionMessageWithStackTrace> instanceToExMap = failedValidations
-                            .get(moduleName);
-                    if (instanceToExMap == null) {
-                        instanceToExMap = new HashMap<>();
-                        failedValidations.put(moduleName, instanceToExMap);
-                    }
+                            .computeIfAbsent(moduleName, k -> new HashMap<>());
                     if (instanceToExMap.containsKey(instanceName)) {
-                        throw new IllegalArgumentException(
-                                "Cannot merge with same module name "
-                                        + moduleName + " and instance name "
-                                        + instanceName);
+                        throw new IllegalArgumentException("Cannot merge with same module name " + moduleName
+                                + " and instance name " + instanceName);
                     }
                     instanceToExMap.put(instanceName, ex);
                 }
@@ -59,34 +58,36 @@ public class ValidationException extends RuntimeException {
         return new ValidationException(failedValidations);
     }
 
-    public static ValidationException createForSingleException(
-            ModuleIdentifier moduleIdentifier, Exception e) {
+    public static ValidationException createForSingleException(final ModuleIdentifier moduleIdentifier,
+            final Exception exception) {
         Map<String, Map<String, ExceptionMessageWithStackTrace>> failedValidations = new HashMap<>();
         Map<String, ExceptionMessageWithStackTrace> innerMap = new HashMap<>();
 
         failedValidations.put(moduleIdentifier.getFactoryName(), innerMap);
-        innerMap.put(moduleIdentifier.getInstanceName(),
-                new ExceptionMessageWithStackTrace(e));
+        innerMap.put(moduleIdentifier.getInstanceName(), new ExceptionMessageWithStackTrace(exception));
         return new ValidationException(failedValidations);
     }
 
-    public Map<String/* module name */, Map<String/* instance name */, ExceptionMessageWithStackTrace>> getFailedValidations() {
+    public Map<String/* module name */,
+        Map<String/* instance name */,
+        ExceptionMessageWithStackTrace>> getFailedValidations() {
         return failedValidations;
     }
 
     public static class ExceptionMessageWithStackTrace {
-        private String message, stackTrace;
+        private String message;
+        private String stackTrace;
 
         public ExceptionMessageWithStackTrace() {
         }
 
-        public ExceptionMessageWithStackTrace(String message, String stackTrace) {
+        public ExceptionMessageWithStackTrace(final String message, final String stackTrace) {
             this.message = message;
             this.stackTrace = stackTrace;
         }
 
-        public ExceptionMessageWithStackTrace(Exception e) {
-            this(e.getMessage(), Arrays.toString(e.getStackTrace()));
+        public ExceptionMessageWithStackTrace(final Exception exception) {
+            this(exception.getMessage(), Arrays.toString(exception.getStackTrace()));
         }
 
         public String getMessage() {
@@ -97,44 +98,49 @@ public class ValidationException extends RuntimeException {
             return stackTrace;
         }
 
-        public void setMessage(String message) {
+        public void setMessage(final String message) {
             this.message = message;
         }
 
-        public void setTrace(String stackTrace) {
-            this.stackTrace = stackTrace;
+        public void setStackTrace(final String trace) {
+            this.stackTrace = trace;
         }
 
         @Override
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result
-                    + ((message == null) ? 0 : message.hashCode());
-            result = prime * result
-                    + ((stackTrace == null) ? 0 : stackTrace.hashCode());
+            result = prime * result + (message == null ? 0 : message.hashCode());
+            result = prime * result + (stackTrace == null ? 0 : stackTrace.hashCode());
             return result;
         }
 
         @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
+        public boolean equals(final Object obj) {
+            if (this == obj) {
                 return true;
-            if (obj == null)
+            }
+            if (obj == null) {
                 return false;
-            if (getClass() != obj.getClass())
+            }
+            if (getClass() != obj.getClass()) {
                 return false;
+            }
             ExceptionMessageWithStackTrace other = (ExceptionMessageWithStackTrace) obj;
             if (message == null) {
-                if (other.message != null)
+                if (other.message != null) {
                     return false;
-            } else if (!message.equals(other.message))
+                }
+            } else if (!message.equals(other.message)) {
                 return false;
+            }
             if (stackTrace == null) {
-                if (other.stackTrace != null)
+                if (other.stackTrace != null) {
                     return false;
-            } else if (!stackTrace.equals(other.stackTrace))
+                }
+            } else if (!stackTrace.equals(other.stackTrace)) {
                 return false;
+            }
             return true;
         }
 
@@ -142,6 +148,5 @@ public class ValidationException extends RuntimeException {
         public String toString() {
             return message;
         }
-
     }
 }