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) {
29 this(min, max, description.orNull(), reference.orNull(), "range-out-of-specified-bounds",
30 "The argument is out of bounds <" + min + ", " + max + ">");
33 public RangeConstraintEffectiveImpl(final Number min, final Number max, final String description,
34 final String reference, final String errorAppTag, final String errorMessage) {
36 this.min = Preconditions.checkNotNull(min, "min must not be null.");
37 this.max = Preconditions.checkNotNull(max, "max must not be null.");
38 this.description = description;
39 this.reference = reference;
40 this.errorAppTag = errorAppTag != null ? errorAppTag : "range-out-of-specified-bounds";
41 this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
46 public String getDescription() {
51 public String getErrorAppTag() {
56 public String getErrorMessage() {
61 public String getReference() {
66 public Number getMin() {
71 public Number getMax() {
76 public int hashCode() {
79 result = prime * result + Objects.hashCode(description);
80 result = prime * result + errorAppTag.hashCode();
81 result = prime * result + errorMessage.hashCode();
82 result = prime * result + max.hashCode();
83 result = prime * result + min.hashCode();
84 result = prime * result + Objects.hashCode(reference);
89 public boolean equals(final Object obj) {
96 if (getClass() != obj.getClass()) {
99 final RangeConstraintEffectiveImpl other = (RangeConstraintEffectiveImpl) obj;
100 if (!Objects.equals(description, other.description)) {
103 if (!Objects.equals(max, other.max)) {
106 if (!Objects.equals(min, other.min)) {
109 if (!Objects.equals(reference, other.reference)) {
116 public String toString() {
117 return RangeConstraintEffectiveImpl.class.getSimpleName() + " [min=" + min + ", max=" + max + ", description="
118 + description + ", reference=" + reference + ", errorAppTag=" + errorAppTag + ", errorMessage="
119 + errorMessage + "]";