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%2FRangeConstraintImpl.java;h=132d52a1db05d7baf46e58613217e18f413373dc;hb=635af1cfca70d0be0192f997c155d80cbbc5ba5d;hp=70acbc84eb4b37b55c7fcf348b358d5920fad8bd;hpb=45cc8ec7bc55e59639ae3df1b8f1c35fe7026386;p=yangtools.git diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java index 70acbc84eb..132d52a1db 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java @@ -7,12 +7,11 @@ */ package org.opendaylight.yangtools.yang.model.util; -import org.opendaylight.yangtools.concepts.Immutable; -import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; -import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; - 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.RangeConstraint; /** * {@link Immutable} implementation of {@link LengthConstraint}. @@ -38,14 +37,19 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable { RangeConstraintImpl(final Number min, final Number max, final Optional description, final Optional reference) { - super(); + this(min, max, description, reference, "range-out-of-specified-bounds", "The argument is out of bounds <" + min + + ", " + max + ">"); + } + + RangeConstraintImpl(final Number min, final Number max, final Optional description, + final Optional 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 = "range-out-of-specified-bounds"; - this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">"; + this.errorAppTag = errorAppTag != null ? errorAppTag : "range-out-of-specified-bounds"; + this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max + + ">"; } @Override @@ -82,12 +86,12 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + Objects.hashCode(description); result = prime * result + errorAppTag.hashCode(); result = prime * result + errorMessage.hashCode(); result = prime * result + max.hashCode(); result = prime * result + min.hashCode(); - result = prime * result + ((reference == null) ? 0 : reference.hashCode()); + result = prime * result + Objects.hashCode(reference); return result; } @@ -103,32 +107,16 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable { return false; } final RangeConstraintImpl other = (RangeConstraintImpl) 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 (max == null) { - if (other.max != null) { - return false; - } - } else if (!max.equals(other.max)) { + if (!Objects.equals(max, other.max)) { return false; } - if (min == null) { - if (other.min != null) { - return false; - } - } else if (!min.equals(other.min)) { + if (!Objects.equals(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;