Merge "Documentation generator improvements."
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / StringType.java
1 /*
2  * Copyright (c) 2013 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.model.util;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.Status;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
19 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
20 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
21
22 /**
23  * The <code>default</code> implementation of String Type Definition interface.
24  *
25  * @see StringTypeDefinition
26  */
27 public final class StringType implements StringTypeDefinition {
28     private static final StringType INSTANCE = new StringType();
29     private final QName name = BaseTypes.constructQName("string");
30     private final SchemaPath path = new SchemaPath(Collections.singletonList(name), true);
31     private static final String DEFAULT_VALUE = "";
32     private static final String DESCRIPTION = "";
33     private static final String REFERENCE = "";
34     private final List<LengthConstraint> lengthStatements;
35     private final List<PatternConstraint> patterns;
36     private static final String UNITS = "";
37
38     /**
39      * Default Constructor.
40      */
41     private StringType() {
42         final List<LengthConstraint> constraints = new ArrayList<LengthConstraint>();
43         constraints.add(BaseConstraints.lengthConstraint(0, Integer.MAX_VALUE, "", ""));
44         lengthStatements = Collections.unmodifiableList(constraints);
45         patterns = Collections.emptyList();
46     }
47
48     public static StringType getInstance() {
49         return INSTANCE;
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see
56      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
57      */
58     @Override
59     public StringTypeDefinition getBaseType() {
60         return null;
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
67      */
68     @Override
69     public String getUnits() {
70         return UNITS;
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see
77      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
78      * ()
79      */
80     @Override
81     public Object getDefaultValue() {
82         return DEFAULT_VALUE;
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
89      */
90     @Override
91     public QName getQName() {
92         return name;
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
99      */
100     @Override
101     public SchemaPath getPath() {
102         return path;
103     }
104
105     /*
106      * (non-Javadoc)
107      *
108      * @see
109      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
110      */
111     @Override
112     public String getDescription() {
113         return DESCRIPTION;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
120      */
121     @Override
122     public String getReference() {
123         return REFERENCE;
124     }
125
126     /*
127      * (non-Javadoc)
128      *
129      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
130      */
131     @Override
132     public Status getStatus() {
133         return Status.CURRENT;
134     }
135
136     /*
137      * (non-Javadoc)
138      *
139      * @see
140      * com.csico.yang.model.base.type.api.StringTypeDefinition#getLengthStatements
141      * ()
142      */
143     @Override
144     public List<LengthConstraint> getLengthConstraints() {
145         return lengthStatements;
146     }
147
148     /*
149      * (non-Javadoc)
150      *
151      * @see
152      * com.csico.yang.model.base.type.api.StringTypeDefinition#getPatterns()
153      */
154     @Override
155     public List<PatternConstraint> getPatternConstraints() {
156         return patterns;
157     }
158
159     @Override
160     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
161         return Collections.emptyList();
162     }
163
164     @Override
165     public int hashCode() {
166         final int prime = 31;
167         int result = 1;
168         result = prime * result + ((lengthStatements == null) ? 0 : lengthStatements.hashCode());
169         result = prime * result + ((name == null) ? 0 : name.hashCode());
170         result = prime * result + ((path == null) ? 0 : path.hashCode());
171         result = prime * result + ((patterns == null) ? 0 : patterns.hashCode());
172         return result;
173     }
174
175     @Override
176     public boolean equals(Object obj) {
177         if (this == obj) {
178             return true;
179         }
180         if (obj == null) {
181             return false;
182         }
183         if (getClass() != obj.getClass()) {
184             return false;
185         }
186         StringType other = (StringType) obj;
187         if (lengthStatements == null) {
188             if (other.lengthStatements != null) {
189                 return false;
190             }
191         } else if (!lengthStatements.equals(other.lengthStatements)) {
192             return false;
193         }
194         if (name == null) {
195             if (other.name != null) {
196                 return false;
197             }
198         } else if (!name.equals(other.name)) {
199             return false;
200         }
201         if (path == null) {
202             if (other.path != null) {
203                 return false;
204             }
205         } else if (!path.getPath().equals(other.path.getPath())) {
206             return false;
207         }
208         if (patterns == null) {
209             if (other.patterns != null) {
210                 return false;
211             }
212         } else if (!patterns.equals(other.patterns)) {
213             return false;
214         }
215         return true;
216     }
217
218     @Override
219     public String toString() {
220         StringBuilder builder = new StringBuilder();
221         builder.append("StringType [name=");
222         builder.append(name);
223         builder.append(", path=");
224         builder.append(path);
225         builder.append(", defaultValue=");
226         builder.append(DEFAULT_VALUE);
227         builder.append(", description=");
228         builder.append(DESCRIPTION);
229         builder.append(", reference=");
230         builder.append(REFERENCE);
231         builder.append(", lengthStatements=");
232         builder.append(lengthStatements);
233         builder.append(", patterns=");
234         builder.append(patterns);
235         builder.append(", units=");
236         builder.append(UNITS);
237         builder.append("]");
238         return builder.toString();
239     }
240 }