X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Futil%2FPatternConstraintImpl.java;h=cd0ca2cf2431afb1977e82ab1cf45ebcad300e10;hb=635af1cfca70d0be0192f997c155d80cbbc5ba5d;hp=8ab67a7636c02d72813cbc7dacea29b4de6fe2bc;hpb=06318ba0f909fdb0b8ffd26b0e89708ee2d21ce3;p=yangtools.git diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java index 8ab67a7636..cd0ca2cf24 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java @@ -7,11 +7,11 @@ */ package org.opendaylight.yangtools.yang.model.util; -import org.opendaylight.yangtools.concepts.Immutable; -import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; - import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import java.util.Objects; +import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; /** * {@link Immutable} implementation of {@link PatternConstraint} @@ -34,17 +34,19 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { private final String errorAppTag; private final String errorMessage; - public PatternConstraintImpl(final String regex, final Optional description, - final Optional reference) { - super(); + PatternConstraintImpl(final String regex, final Optional description, final Optional reference) { + this(regex, description, reference, "invalid-regular-expression", String.format( + "String %s is not valid regular expression.", regex)); + } + + PatternConstraintImpl(final String regex, final Optional description, final Optional reference, + final String errorAppTag, final String errorMessage) { this.regex = Preconditions.checkNotNull(regex, "regex must not be null."); this.description = description.orNull(); this.reference = reference.orNull(); - - // FIXME: Lookup better suitable error tag. - errorAppTag = "invalid-regular-expression"; - // TODO: add erro message - errorMessage = ""; + this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression"; + this.errorMessage = errorMessage != null ? errorMessage : String.format( + "String %s is not valid regular expression.", regex); } @Override @@ -76,10 +78,10 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode()); - result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode()); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + Objects.hashCode(description); + result = prime * result + Objects.hashCode(errorAppTag); + result = prime * result + Objects.hashCode(errorMessage); + result = prime * result + Objects.hashCode(reference); result = prime * result + regex.hashCode(); return result; } @@ -96,39 +98,19 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { return false; } final PatternConstraintImpl other = (PatternConstraintImpl) 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;