*/
package org.opendaylight.yangtools.yang.model.util;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-
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.LengthConstraint;
/**
* {@link Immutable} implementation of {@link LengthConstraint}.
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
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;
}
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) {
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;