2 * Copyright (c) 2015 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.parser.stmt.rfc6020.effective.type;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
15 public class RangeConstraintEffectiveImpl implements RangeConstraint {
17 public static final String DEFAULT_REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.2.4";
18 private final Number min;
19 private final Number max;
21 private final String description;
22 private final String reference;
24 private final String errorAppTag;
25 private final String errorMessage;
27 public RangeConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
28 final Optional<String> reference) {
32 this.min = Preconditions.checkNotNull(min, "min must not be null.");
33 this.max = Preconditions.checkNotNull(max, "max must not be null.");
34 this.description = description.orNull();
35 this.reference = reference.orNull();
37 this.errorAppTag = "range-out-of-specified-bounds";
38 this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
42 public String getDescription() {
47 public String getErrorAppTag() {
52 public String getErrorMessage() {
57 public String getReference() {
62 public Number getMin() {
67 public Number getMax() {
72 public int hashCode() {
75 result = prime * result + Objects.hashCode(description);
76 result = prime * result + errorAppTag.hashCode();
77 result = prime * result + errorMessage.hashCode();
78 result = prime * result + max.hashCode();
79 result = prime * result + min.hashCode();
80 result = prime * result + Objects.hashCode(reference);
85 public boolean equals(final Object obj) {
92 if (getClass() != obj.getClass()) {
95 final RangeConstraintEffectiveImpl other = (RangeConstraintEffectiveImpl) obj;
96 if (!Objects.equals(description, other.description)) {
99 if (!Objects.equals(max, other.max)) {
102 if (!Objects.equals(min, other.min)) {
105 if (!Objects.equals(reference, other.reference)) {
112 public String toString() {
113 final StringBuilder builder = new StringBuilder();
114 builder.append(RangeConstraintEffectiveImpl.class.getSimpleName());
115 builder.append(" [min=");
117 builder.append(", max=");
119 builder.append(", description=");
120 builder.append(description);
121 builder.append(", reference=");
122 builder.append(reference);
123 builder.append(", errorAppTag=");
124 builder.append(errorAppTag);
125 builder.append(", errorMessage=");
126 builder.append(errorMessage);
128 return builder.toString();