Bug 5200: Yang parser doesn't fill error-app-tag and error-message in constraints
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / LengthConstraintImpl.java
index 6472d269f24b11cd81197ee381a9c785fc416708..58f24dc190b3abb1ef9a98c8a4d476254079daac 100644 (file)
@@ -38,14 +38,19 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable {
 
     LengthConstraintImpl(final Number min, final Number max, final Optional<String> description,
             final Optional<String> reference) {
-        super();
+        this(min, max, description, reference, "length-out-of-specified-bounds", "The argument is out of bounds <"
+                + min + ", " + max + ">");
+    }
+
+    LengthConstraintImpl(final Number min, final Number max, final Optional<String> description,
+            final Optional<String> reference, final String errorAppTag, final String errorMessage) {
         this.min = Preconditions.checkNotNull(min, "min must not be null.");
         this.max = Preconditions.checkNotNull(max, "max must not be null");
         this.description = description.orNull();
         this.reference = reference.orNull();
-
-        this.errorAppTag = "length-out-of-specified-bounds";
-        this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
+        this.errorAppTag = errorAppTag != null ? errorAppTag : "length-out-of-specified-bounds";
+        this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
+                + ">";
     }
 
     @Override
@@ -103,25 +108,13 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable {
             return false;
         }
         final LengthConstraintImpl other = (LengthConstraintImpl) obj;
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
+        if (!Objects.equals(description, other.description)) {
             return false;
         }
-        if (errorAppTag == null) {
-            if (other.errorAppTag != null) {
-                return false;
-            }
-        } else if (!errorAppTag.equals(other.errorAppTag)) {
+        if (!Objects.equals(errorAppTag, other.errorAppTag)) {
             return false;
         }
-        if (errorMessage == null) {
-            if (other.errorMessage != null) {
-                return false;
-            }
-        } else if (!errorMessage.equals(other.errorMessage)) {
+        if (!Objects.equals(errorMessage, other.errorMessage)) {
             return false;
         }
         if (max != other.max) {
@@ -130,11 +123,7 @@ final class LengthConstraintImpl implements LengthConstraint, Immutable {
         if (min != other.min) {
             return false;
         }
-        if (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
         return true;