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.LengthConstraint;
15 public class LengthConstraintEffectiveImpl implements LengthConstraint {
17 private final Number min;
18 private final Number max;
20 private final String description;
21 private final String reference;
23 private final String errorAppTag;
24 private final String errorMessage;
26 public LengthConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
27 final Optional<String> reference) {
31 this.min = Preconditions.checkNotNull(min, "min must not be null.");
32 this.max = Preconditions.checkNotNull(max, "max must not be null");
33 this.description = description.orNull();
34 this.reference = reference.orNull();
36 this.errorAppTag = "length-out-of-specified-bounds";
37 this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
41 public Number getMin() {
46 public Number getMax() {
51 public String getDescription() {
56 public String getErrorAppTag() {
61 public String getErrorMessage() {
66 public String getReference() {
71 public int hashCode() {
74 result = prime * result + Objects.hashCode(description);
75 result = prime * result + errorAppTag.hashCode();
76 result = prime * result + errorMessage.hashCode();
77 result = prime * result + max.hashCode();
78 result = prime * result + min.hashCode();
79 result = prime * result + Objects.hashCode(reference);
84 public boolean equals(final Object obj) {
91 if (getClass() != obj.getClass()) {
94 final LengthConstraintEffectiveImpl other = (LengthConstraintEffectiveImpl) obj;
95 if (description == null) {
96 if (other.description != null) {
99 } else if (!description.equals(other.description)) {
102 if (errorAppTag == null) {
103 if (other.errorAppTag != null) {
106 } else if (!errorAppTag.equals(other.errorAppTag)) {
109 if (errorMessage == null) {
110 if (other.errorMessage != null) {
113 } else if (!errorMessage.equals(other.errorMessage)) {
116 if (!Objects.equals(max, other.max)) {
119 if (!Objects.equals(min, other.min)) {
122 if (reference == null) {
123 if (other.reference != null) {
126 } else if (!reference.equals(other.reference)) {
133 public String toString() {
134 StringBuilder builder = new StringBuilder();
135 builder.append(LengthConstraintEffectiveImpl.class.getSimpleName());
136 builder.append(" [min=");
138 builder.append(", max=");
140 builder.append(", description=");
141 builder.append(description);
142 builder.append(", errorAppTag=");
143 builder.append(errorAppTag);
144 builder.append(", reference=");
145 builder.append(reference);
146 builder.append(", errorMessage=");
147 builder.append(errorMessage);
149 return builder.toString();