2 * Copyright (c) 2014 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.model.util;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
17 * {@link Immutable} implementation of {@link LengthConstraint}.
19 * Length constraint based on supplied parameters with additional behaviour:
22 * <li>{@link LengthConstraint#getErrorAppTag()} returns
23 * <code>length-out-of-specified-bounds</code>
24 * <li>{@link LengthConstraint#getErrorMessage() returns <code>The argument is
25 * out of bounds <<i>min</i>, <i>max</i> ></code>
28 final class LengthConstraintImpl implements LengthConstraint, Immutable {
30 private final Number min;
31 private final Number max;
33 private final String description;
34 private final String reference;
36 private final String errorAppTag;
37 private final String errorMessage;
39 LengthConstraintImpl(final Number min, final Number max, final Optional<String> description,
40 final Optional<String> reference) {
42 this.min = Preconditions.checkNotNull(min, "min must not be null.");
43 this.max = Preconditions.checkNotNull(max, "max must not be null");
44 this.description = description.orNull();
45 this.reference = reference.orNull();
47 this.errorAppTag = "length-out-of-specified-bounds";
48 this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
52 public String getDescription() {
57 public String getErrorAppTag() {
62 public String getErrorMessage() {
67 public String getReference() {
72 public Number getMin() {
77 public Number getMax() {
82 public int hashCode() {
85 result = prime * result + Objects.hashCode(description);
86 result = prime * result + errorAppTag.hashCode();
87 result = prime * result + errorMessage.hashCode();
88 result = prime * result + max.hashCode();
89 result = prime * result + min.hashCode();
90 result = prime * result + Objects.hashCode(reference);
95 public boolean equals(final Object obj) {
102 if (getClass() != obj.getClass()) {
105 final LengthConstraintImpl other = (LengthConstraintImpl) obj;
106 if (description == null) {
107 if (other.description != null) {
110 } else if (!description.equals(other.description)) {
113 if (errorAppTag == null) {
114 if (other.errorAppTag != null) {
117 } else if (!errorAppTag.equals(other.errorAppTag)) {
120 if (errorMessage == null) {
121 if (other.errorMessage != null) {
124 } else if (!errorMessage.equals(other.errorMessage)) {
127 if (max != other.max) {
130 if (min != other.min) {
133 if (reference == null) {
134 if (other.reference != null) {
137 } else if (!reference.equals(other.reference)) {
144 public String toString() {
145 StringBuilder builder = new StringBuilder();
146 builder.append("LengthConstraintImpl [min=");
148 builder.append(", max=");
150 builder.append(", description=");
151 builder.append(description);
152 builder.append(", errorAppTag=");
153 builder.append(errorAppTag);
154 builder.append(", reference=");
155 builder.append(reference);
156 builder.append(", errorMessage=");
157 builder.append(errorMessage);
159 return builder.toString();