Merge "Refactored implementation of getBaseType method for yang built-in types."
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / InstanceIdentifier.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.Collections;
11 import java.util.List;
12
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
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.InstanceIdentifierTypeDefinition;
19
20 /**
21  * The <code>default</code> implementation of Instance Identifier Type
22  * Definition interface.
23  *
24  * @see InstanceIdentifierTypeDefinition
25  */
26 public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
27     private static final QName NAME = BaseTypes.constructQName("instance-identifier");
28     private static final SchemaPath PATH = new SchemaPath(Collections.singletonList(NAME), true);
29     private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
30             + "uniquely identify a particular instance node in the data tree.";
31     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
32
33     private final RevisionAwareXPath xpath;
34     private static final String UNITS = "";
35     private boolean requireInstance = true;
36
37     private static final int HASH_BOOLEAN_TRUE = 1231;
38     private static final int HASH_BOOLEAN_FALSE = 1237;
39
40     public InstanceIdentifier(final RevisionAwareXPath xpath) {
41         this.xpath = xpath;
42     }
43
44     public InstanceIdentifier(final RevisionAwareXPath xpath, final boolean requireInstance) {
45         this.xpath = xpath;
46         this.requireInstance = requireInstance;
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see
53      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
54      */
55     @Override
56     public InstanceIdentifierTypeDefinition getBaseType() {
57         return null;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
64      */
65     @Override
66     public String getUnits() {
67         return UNITS;
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see
74      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
75      * ()
76      */
77     @Override
78     public Object getDefaultValue() {
79         return xpath;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
86      */
87     @Override
88     public QName getQName() {
89         return NAME;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
96      */
97     @Override
98     public SchemaPath getPath() {
99         return PATH;
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see
106      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
107      */
108     @Override
109     public String getDescription() {
110         return DESCRIPTION;
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
117      */
118     @Override
119     public String getReference() {
120         return REFERENCE;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
127      */
128     @Override
129     public Status getStatus() {
130         return Status.CURRENT;
131     }
132
133     /*
134      * (non-Javadoc)
135      *
136      * @see
137      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
138      * ()
139      */
140     @Override
141     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
142         return Collections.emptyList();
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see org.opendaylight.yangtools.yang.model.api.type.
149      * InstanceIdentifierTypeDefinition# getPathStatement()
150      */
151     @Override
152     public RevisionAwareXPath getPathStatement() {
153         return xpath;
154     }
155
156     /*
157      * (non-Javadoc)
158      *
159      * @see org.opendaylight.yangtools.yang.model.api.type.
160      * InstanceIdentifierTypeDefinition# requireInstance()
161      */
162     @Override
163     public boolean requireInstance() {
164         return requireInstance;
165     }
166
167     @Override
168     public int hashCode() {
169         final int prime = 31;
170         int result = 1;
171         result = prime * result + (requireInstance ? HASH_BOOLEAN_TRUE : HASH_BOOLEAN_FALSE);
172         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
173         return result;
174     }
175
176     @Override
177     public boolean equals(Object obj) {
178         if (this == obj) {
179             return true;
180         }
181         if (obj == null) {
182             return false;
183         }
184         if (getClass() != obj.getClass()) {
185             return false;
186         }
187         InstanceIdentifier other = (InstanceIdentifier) obj;
188         if (requireInstance != other.requireInstance) {
189             return false;
190         }
191         if (xpath == null) {
192             if (other.xpath != null) {
193                 return false;
194             }
195         } else if (!xpath.equals(other.xpath)) {
196             return false;
197         }
198         return true;
199     }
200
201 }