Bug 5200: Yang parser doesn't fill error-app-tag and error-message in constraints
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / PatternConstraintEffectiveImpl.java
index 1b8bbc91267885c8de15710b7049ca497139a89b..d8799648f621afc21a084bf0a08df6e8950dda15 100644 (file)
@@ -17,21 +17,24 @@ public class PatternConstraintEffectiveImpl implements PatternConstraint {
     private final String regEx;
     private final String description;
     private final String reference;
-
     private final String errorAppTag;
     private final String errorMessage;
 
     public PatternConstraintEffectiveImpl(final String regex, final Optional<String> description,
             final Optional<String> reference) {
+        this(regex, description.orNull(), reference.orNull(), "invalid-regular-expression", String.format(
+                "String %s is not valid regular expression.", regex));
+    }
 
+    public PatternConstraintEffectiveImpl(final String regex, final String description, final String reference,
+            final String errorAppTag, final String errorMessage) {
         super();
-
         this.regEx = Preconditions.checkNotNull(regex, "regex must not be null.");
-        this.description = description.orNull();
-        this.reference = reference.orNull();
-
-        errorAppTag = "invalid-regular-expression";
-        errorMessage = String.format("String %s is not valid regular expression.", regex);
+        this.description = description;
+        this.reference = reference;
+        this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression";
+        this.errorMessage = errorMessage != null ? errorMessage : String.format(
+                "String %s is not valid regular expression.", regex);
     }
 
     @Override
@@ -83,39 +86,19 @@ public class PatternConstraintEffectiveImpl implements PatternConstraint {
             return false;
         }
         final PatternConstraintEffectiveImpl other = (PatternConstraintEffectiveImpl) 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 (reference == null) {
-            if (other.reference != null) {
-                return false;
-            }
-        } else if (!reference.equals(other.reference)) {
+        if (!Objects.equals(reference, other.reference)) {
             return false;
         }
-        if (regEx == null) {
-            if (other.regEx != null) {
-                return false;
-            }
-        } else if (!regEx.equals(other.regEx)) {
+        if (!Objects.equals(regEx, other.regEx)) {
             return false;
         }
         return true;