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 (!Objects.equals(description, other.description)) {
98 if (!Objects.equals(errorAppTag, other.errorAppTag)) {
101 if (!Objects.equals(errorMessage, other.errorMessage)) {
104 if (!Objects.equals(max, other.max)) {
107 if (!Objects.equals(min, other.min)) {
110 if (!Objects.equals(reference, other.reference)) {
117 public String toString() {
118 StringBuilder builder = new StringBuilder();
119 builder.append(LengthConstraintEffectiveImpl.class.getSimpleName());
120 builder.append(" [min=");
122 builder.append(", max=");
124 builder.append(", description=");
125 builder.append(description);
126 builder.append(", errorAppTag=");
127 builder.append(errorAppTag);
128 builder.append(", reference=");
129 builder.append(reference);
130 builder.append(", errorMessage=");
131 builder.append(errorMessage);
133 return builder.toString();