b06bdede01667eade37bb5a616a40b776f81806f
[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         this(min, max, description.orNull(), reference.orNull(), "length-out-of-specified-bounds",
29             "The argument is out of bounds <" + min + ", " + max + ">");
30     }
31
32     public LengthConstraintEffectiveImpl(final Number min, final Number max, final String description,
33             final String reference, final String errorAppTag, final String errorMessage) {
34         this.min = Preconditions.checkNotNull(min, "min must not be null.");
35         this.max = Preconditions.checkNotNull(max, "max must not be null");
36         this.description = description;
37         this.reference = reference;
38         this.errorAppTag = errorAppTag != null ? errorAppTag : "length-out-of-specified-bounds";
39         this.errorMessage = errorMessage != null ? errorMessage : "The argument is out of bounds <" + min + ", " + max
40                 + ">";
41     }
42
43     @Override
44     public Number getMin() {
45         return min;
46     }
47
48     @Override
49     public Number getMax() {
50         return max;
51     }
52
53     @Override
54     public String getDescription() {
55         return description;
56     }
57
58     @Override
59     public String getErrorAppTag() {
60         return errorAppTag;
61     }
62
63     @Override
64     public String getErrorMessage() {
65         return errorMessage;
66     }
67
68     @Override
69     public String getReference() {
70         return reference;
71     }
72
73     @Override
74     public int hashCode() {
75         final int prime = 31;
76         int result = 1;
77         result = prime * result + Objects.hashCode(description);
78         result = prime * result + errorAppTag.hashCode();
79         result = prime * result + errorMessage.hashCode();
80         result = prime * result + max.hashCode();
81         result = prime * result + min.hashCode();
82         result = prime * result + Objects.hashCode(reference);
83         return result;
84     }
85
86     @Override
87     public boolean equals(final Object obj) {
88         if (this == obj) {
89             return true;
90         }
91         if (obj == null) {
92             return false;
93         }
94         if (getClass() != obj.getClass()) {
95             return false;
96         }
97         final LengthConstraintEffectiveImpl other = (LengthConstraintEffectiveImpl) obj;
98         if (!Objects.equals(description, other.description)) {
99             return false;
100         }
101         if (!Objects.equals(errorAppTag, other.errorAppTag)) {
102             return false;
103         }
104         if (!Objects.equals(errorMessage, other.errorMessage)) {
105             return false;
106         }
107         if (!Objects.equals(max, other.max)) {
108             return false;
109         }
110         if (!Objects.equals(min, other.min)) {
111             return false;
112         }
113         if (!Objects.equals(reference, other.reference)) {
114             return false;
115         }
116         return true;
117     }
118
119     @Override
120     public String toString() {
121         return LengthConstraintEffectiveImpl.class.getSimpleName()
122                 + " [min=" + min
123                 + ", max=" + max
124                 + ", description=" + description
125                 + ", errorAppTag=" + errorAppTag
126                 + ", reference=" + reference
127                 + ", errorMessage=" + errorMessage
128                 + "]";
129     }
130 }