Merge "BUG-1276: fixed generated union constructor"
[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.concepts.Immutable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.Status;
18 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
20
21 /**
22  * The <code>default</code> implementation of Instance Identifier Type
23  * Definition interface.
24  *
25  * Instance Identifier has only two possible variants - one with
26  * {@link #requireInstance()} which returns true, other one
27  * returns false.
28  *
29  * @see InstanceIdentifierTypeDefinition
30  *
31  */
32 public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition, Immutable {
33
34     private static final QName NAME = BaseTypes.INSTANCE_IDENTIFIER_QNAME;
35     private static final SchemaPath PATH = SchemaPath.create(true, NAME);
36     private static final String DESCRIPTION = "The instance-identifier built-in type is used to "
37             + "uniquely identify a particular instance node in the data tree.";
38     private static final String REFERENCE = "https://tools.ietf.org/html/rfc6020#section-9.13";
39
40     private static final String UNITS = "";
41     private final Boolean requireInstance;
42
43     private static final InstanceIdentifier INSTANCE_WITH_REQUIRED_TRUE = new InstanceIdentifier(true);
44     private static final InstanceIdentifier INSTANCE_WITH_REQUIRED_FALSE = new InstanceIdentifier(false);
45
46     /**
47      * Constructs new instance identifier.
48      *
49      * @param xpath
50      * @deprecated Use {@link #getInstance()} for default one, since Instance Identifier does not have xpath.
51      */
52     @Deprecated
53     public InstanceIdentifier(final RevisionAwareXPath xpath) {
54         requireInstance = true;
55     }
56
57     /**
58      * Constructs new instance identifier.
59      *
60      * @param xpath
61      * @param requireInstance if instance of data is required
62      * @deprecated Use {@link #create(boolean)}, since Instance Identifier does not have xpath.
63      */
64     @Deprecated
65     public InstanceIdentifier(final RevisionAwareXPath xpath, final boolean requireInstance) {
66         this.requireInstance = requireInstance;
67     }
68
69     private InstanceIdentifier(final boolean requiredInstance) {
70         this.requireInstance = requiredInstance;
71     }
72
73     public static InstanceIdentifier getInstance() {
74         return INSTANCE_WITH_REQUIRED_TRUE;
75     }
76
77     public static InstanceIdentifier create(final boolean requireInstance) {
78         return requireInstance ? INSTANCE_WITH_REQUIRED_TRUE : INSTANCE_WITH_REQUIRED_FALSE;
79     }
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see
85      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
86      */
87     @Override
88     public InstanceIdentifierTypeDefinition getBaseType() {
89         return null;
90     }
91
92     /*
93      * (non-Javadoc)
94      *
95      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
96      */
97     @Override
98     public String getUnits() {
99         return UNITS;
100     }
101
102     /*
103      * (non-Javadoc)
104      *
105      * @see
106      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
107      * ()
108      */
109     @Override
110     public Object getDefaultValue() {
111         return null;
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
118      */
119     @Override
120     public QName getQName() {
121         return NAME;
122     }
123
124     /*
125      * (non-Javadoc)
126      *
127      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
128      */
129     @Override
130     public SchemaPath getPath() {
131         return PATH;
132     }
133
134     /*
135      * (non-Javadoc)
136      *
137      * @see
138      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
139      */
140     @Override
141     public String getDescription() {
142         return DESCRIPTION;
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
149      */
150     @Override
151     public String getReference() {
152         return REFERENCE;
153     }
154
155     /*
156      * (non-Javadoc)
157      *
158      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
159      */
160     @Override
161     public Status getStatus() {
162         return Status.CURRENT;
163     }
164
165     /*
166      * (non-Javadoc)
167      *
168      * @see
169      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
170      * ()
171      */
172     @Override
173     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
174         return Collections.emptyList();
175     }
176
177     /*
178      * (non-Javadoc)
179      *
180      * @see org.opendaylight.yangtools.yang.model.api.type.
181      * InstanceIdentifierTypeDefinition# getPathStatement()
182      */
183     @Override
184     @Deprecated
185     public RevisionAwareXPath getPathStatement() {
186         return null;
187     }
188
189     /*
190      * (non-Javadoc)
191      *
192      * @see org.opendaylight.yangtools.yang.model.api.type.
193      * InstanceIdentifierTypeDefinition# requireInstance()
194      */
195     @Override
196     public boolean requireInstance() {
197         return requireInstance;
198     }
199
200     @Override
201     public int hashCode() {
202         final int prime = 31;
203         int result = 1;
204         result = prime * result + requireInstance.hashCode();
205         return result;
206     }
207
208     @Override
209     public boolean equals(final Object obj) {
210         if (this == obj) {
211             return true;
212         }
213         if (obj == null) {
214             return false;
215         }
216         if (getClass() != obj.getClass()) {
217             return false;
218         }
219         InstanceIdentifier other = (InstanceIdentifier) obj;
220         return requireInstance.equals(other.requireInstance);
221     }
222
223
224
225 }