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) {
28 this(min, max, description.orNull(), reference.orNull(), "length-out-of-specified-bounds", "The argument is out of bounds <"
29 + min + ", " + max + ">");
32 public LengthConstraintEffectiveImpl(final Number min, final Number max, final String description,
33 final String reference, final String errorAppTag, final String errorMessage) {
35 this.min = Preconditions.checkNotNull(min, "min must not be null.");
36 this.max = Preconditions.checkNotNull(max, "max must not be null");
37 this.description = description;
38 this.reference = reference;
39 this.errorAppTag = errorAppTag != null ? errorAppTag : "length-out-of-specified-bounds";
40 this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
45 public Number getMin() {
50 public Number getMax() {
55 public String getDescription() {
60 public String getErrorAppTag() {
65 public String getErrorMessage() {
70 public String getReference() {
75 public int hashCode() {
78 result = prime * result + Objects.hashCode(description);
79 result = prime * result + errorAppTag.hashCode();
80 result = prime * result + errorMessage.hashCode();
81 result = prime * result + max.hashCode();
82 result = prime * result + min.hashCode();
83 result = prime * result + Objects.hashCode(reference);
88 public boolean equals(final Object obj) {
95 if (getClass() != obj.getClass()) {
98 final LengthConstraintEffectiveImpl other = (LengthConstraintEffectiveImpl) obj;
99 if (!Objects.equals(description, other.description)) {
102 if (!Objects.equals(errorAppTag, other.errorAppTag)) {
105 if (!Objects.equals(errorMessage, other.errorMessage)) {
108 if (!Objects.equals(max, other.max)) {
111 if (!Objects.equals(min, other.min)) {
114 if (!Objects.equals(reference, other.reference)) {
121 public String toString() {
122 StringBuilder builder = new StringBuilder();
123 builder.append(LengthConstraintEffectiveImpl.class.getSimpleName());
124 builder.append(" [min=");
126 builder.append(", max=");
128 builder.append(", description=");
129 builder.append(description);
130 builder.append(", errorAppTag=");
131 builder.append(errorAppTag);
132 builder.append(", reference=");
133 builder.append(reference);
134 builder.append(", errorMessage=");
135 builder.append(errorMessage);
137 return builder.toString();