2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
17 * {@link Immutable} implementation of {@link LengthConstraint}.
19 * Range constraint based on supplied parameters with additional behaviour:
22 * <li>{@link RangeConstraint#getErrorAppTag()} returns
23 * <code>range-out-of-specified-bounds</code>
24 * <li>{@link RangeConstraint#getErrorMessage() returns <code>The argument is
25 * out of bounds <<i>min</i>, <i>max</i> ></code>
28 final class RangeConstraintImpl implements RangeConstraint, Immutable {
29 private final Number min;
30 private final Number max;
32 private final String description;
33 private final String reference;
35 private final String errorAppTag;
36 private final String errorMessage;
38 RangeConstraintImpl(final Number min, final Number max, final Optional<String> description,
39 final Optional<String> reference) {
40 this(min, max, description, reference, "range-out-of-specified-bounds", "The argument is out of bounds <" + min
44 RangeConstraintImpl(final Number min, final Number max, final Optional<String> description,
45 final Optional<String> reference, final String errorAppTag, final String errorMessage) {
46 this.min = Preconditions.checkNotNull(min, "min must not be null.");
47 this.max = Preconditions.checkNotNull(max, "max must not be null.");
48 this.description = description.orNull();
49 this.reference = reference.orNull();
50 this.errorAppTag = errorAppTag != null ? errorAppTag : "range-out-of-specified-bounds";
51 this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
56 public String getDescription() {
61 public String getErrorAppTag() {
66 public String getErrorMessage() {
71 public String getReference() {
76 public Number getMin() {
81 public Number getMax() {
86 public int hashCode() {
89 result = prime * result + Objects.hashCode(description);
90 result = prime * result + errorAppTag.hashCode();
91 result = prime * result + errorMessage.hashCode();
92 result = prime * result + max.hashCode();
93 result = prime * result + min.hashCode();
94 result = prime * result + Objects.hashCode(reference);
99 public boolean equals(final Object obj) {
106 if (getClass() != obj.getClass()) {
109 final RangeConstraintImpl other = (RangeConstraintImpl) obj;
110 if (!Objects.equals(description, other.description)) {
113 if (!Objects.equals(max, other.max)) {
116 if (!Objects.equals(min, other.min)) {
119 if (!Objects.equals(reference, other.reference)) {
126 public String toString() {
127 final StringBuilder builder = new StringBuilder();
128 builder.append("RangeConstraintImpl [min=");
130 builder.append(", max=");
132 builder.append(", description=");
133 builder.append(description);
134 builder.append(", reference=");
135 builder.append(reference);
136 builder.append(", errorAppTag=");
137 builder.append(errorAppTag);
138 builder.append(", errorMessage=");
139 builder.append(errorMessage);
141 return builder.toString();