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=780a59f5c19abbc17f04b4d7bf3242ab1ef8a16e;hb=23cf7d9f6fcea816d1e938e37b52165781710634;hp=eecc2a01f5295f45bc14ed966c9b61740a94a50a;hpb=eb5710c6b416b915591eeef26ea4639ce5eb1ef3;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 eecc2a01f5..780a59f5c1 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,23 +7,24 @@ */ package org.opendaylight.yangtools.yang.model.util; -import com.google.common.base.Optional; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.util.Objects; +import java.util.Optional; import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.yang.model.api.type.ModifierKind; import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; /** - * {@link Immutable} implementation of {@link PatternConstraint} + * {@link Immutable} implementation of {@link PatternConstraint}. * + *

* Creates an instance of Range constraint based on supplied parameters with * additional behaviour: - * *

- * */ final class PatternConstraintImpl implements PatternConstraint, Immutable { @@ -33,55 +34,60 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { private final String errorAppTag; private final String errorMessage; + private final ModifierKind modifier; - public PatternConstraintImpl(final String regex, final Optional description, - final Optional reference) { - super(); - this.regex = Preconditions.checkNotNull(regex, "regex must not be null."); - this.description = description.orNull(); - this.reference = reference.orNull(); + PatternConstraintImpl(final String regex, final Optional description, final Optional reference) { + this(regex, description, reference, null, null, Optional.empty()); + } - // FIXME: Lookup better suitable error tag. - errorAppTag = "invalid-regular-expression"; - // TODO: add erro message - errorMessage = ""; + PatternConstraintImpl(final String regex, final Optional description, final Optional reference, + final String errorAppTag, final String errorMessage, final Optional modifier) { + this.regex = Preconditions.checkNotNull(regex, "regex must not be null."); + this.description = description.orElse(null); + this.reference = reference.orElse(null); + this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression"; + this.errorMessage = errorMessage; + this.modifier = modifier.orElse(null); } @Override - public String getDescription() { - return description; + public Optional getDescription() { + return Optional.ofNullable(description); } @Override - public String getErrorAppTag() { - return errorAppTag; + public Optional getErrorAppTag() { + return Optional.ofNullable(errorAppTag); } @Override - public String getErrorMessage() { - return errorMessage; + public Optional getErrorMessage() { + return Optional.ofNullable(errorMessage); } @Override - public String getReference() { - return reference; + public Optional getReference() { + return Optional.ofNullable(reference); } @Override - public String getRegularExpression() { + public String getJavaPatternString() { return regex; } + @Override + public String getRegularExpressionString() { + throw new UnsupportedOperationException(); + } + + @Override + public Optional getModifier() { + return Optional.ofNullable(modifier); + } + @Override public int hashCode() { - final int prime = 31; - int result = 1; - 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; + return Objects.hash(description, errorAppTag, errorMessage, reference, regex, modifier); } @Override @@ -89,45 +95,19 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof PatternConstraintImpl)) { return false; } final PatternConstraintImpl other = (PatternConstraintImpl) obj; - if (!Objects.equals(description, other.description)) { - return false; - } - if (!Objects.equals(errorAppTag, other.errorAppTag)) { - return false; - } - if (!Objects.equals(errorMessage, other.errorMessage)) { - return false; - } - if (!Objects.equals(reference, other.reference)) { - return false; - } - if (!Objects.equals(regex, other.regex)) { - return false; - } - return true; + return Objects.equals(description, other.description) && Objects.equals(errorAppTag, other.errorAppTag) + && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(reference, other.reference) + && Objects.equals(regex, other.regex) && Objects.equals(modifier, other.modifier); } @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("PatternConstraintImpl [regex="); - builder.append(regex); - builder.append(", description="); - builder.append(description); - builder.append(", reference="); - builder.append(reference); - builder.append(", errorAppTag="); - builder.append(errorAppTag); - builder.append(", errorMessage="); - builder.append(errorMessage); - builder.append("]"); - return builder.toString(); + return MoreObjects.toStringHelper(this).omitNullValues().add("regex", regex).add("description", description) + .add("reference", reference).add("errorAppTag", errorAppTag).add("errorMessage", errorMessage) + .add("modifier", modifier).toString(); } -} \ No newline at end of file +}