32ca55e4465b9722f164e380258eef9616044d28
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / type / LengthConstraintEffectiveImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
9
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;
14
15 public class LengthConstraintEffectiveImpl implements LengthConstraint {
16
17     private final Number min;
18     private final Number max;
19
20     private final String description;
21     private final String reference;
22
23     private final String errorAppTag;
24     private final String errorMessage;
25
26     public LengthConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
27             final Optional<String> reference) {
28
29         super();
30
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();
35
36         this.errorAppTag = "length-out-of-specified-bounds";
37         this.errorMessage = "The argument is out of bounds <" + min + ", " + max + ">";
38     }
39
40     @Override
41     public Number getMin() {
42         return min;
43     }
44
45     @Override
46     public Number getMax() {
47         return max;
48     }
49
50     @Override
51     public String getDescription() {
52         return description;
53     }
54
55     @Override
56     public String getErrorAppTag() {
57         return errorAppTag;
58     }
59
60     @Override
61     public String getErrorMessage() {
62         return errorMessage;
63     }
64
65     @Override
66     public String getReference() {
67         return reference;
68     }
69
70     @Override
71     public int hashCode() {
72         final int prime = 31;
73         int result = 1;
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);
80         return result;
81     }
82
83     @Override
84     public boolean equals(final Object obj) {
85         if (this == obj) {
86             return true;
87         }
88         if (obj == null) {
89             return false;
90         }
91         if (getClass() != obj.getClass()) {
92             return false;
93         }
94         final LengthConstraintEffectiveImpl other = (LengthConstraintEffectiveImpl) obj;
95         if (!Objects.equals(description, other.description)) {
96             return false;
97         }
98         if (!Objects.equals(errorAppTag, other.errorAppTag)) {
99             return false;
100         }
101         if (!Objects.equals(errorMessage, other.errorMessage)) {
102             return false;
103         }
104         if (!Objects.equals(max, other.max)) {
105             return false;
106         }
107         if (!Objects.equals(min, other.min)) {
108             return false;
109         }
110         if (!Objects.equals(reference, other.reference)) {
111             return false;
112         }
113         return true;
114     }
115
116     @Override
117     public String toString() {
118         StringBuilder builder = new StringBuilder();
119         builder.append(LengthConstraintEffectiveImpl.class.getSimpleName());
120         builder.append(" [min=");
121         builder.append(min);
122         builder.append(", max=");
123         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);
132         builder.append("]");
133         return builder.toString();
134     }
135 }