2912bddcf22b2f0c05ca8eafd69e6eac46399dc8
[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 (description == null) {
96             if (other.description != null) {
97                 return false;
98             }
99         } else if (!description.equals(other.description)) {
100             return false;
101         }
102         if (errorAppTag == null) {
103             if (other.errorAppTag != null) {
104                 return false;
105             }
106         } else if (!errorAppTag.equals(other.errorAppTag)) {
107             return false;
108         }
109         if (errorMessage == null) {
110             if (other.errorMessage != null) {
111                 return false;
112             }
113         } else if (!errorMessage.equals(other.errorMessage)) {
114             return false;
115         }
116         if (!Objects.equals(max, other.max)) {
117             return false;
118         }
119         if (!Objects.equals(min, other.min)) {
120             return false;
121         }
122         if (reference == null) {
123             if (other.reference != null) {
124                 return false;
125             }
126         } else if (!reference.equals(other.reference)) {
127             return false;
128         }
129         return true;
130     }
131
132     @Override
133     public String toString() {
134         StringBuilder builder = new StringBuilder();
135         builder.append(LengthConstraintEffectiveImpl.class.getSimpleName());
136         builder.append(" [min=");
137         builder.append(min);
138         builder.append(", max=");
139         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);
148         builder.append("]");
149         return builder.toString();
150     }
151 }