Refactored base yang-java 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     public InstanceIdentifier(final RevisionAwareXPath xpath) {
38         this.xpath = xpath;
39     }
40
41     public InstanceIdentifier(final RevisionAwareXPath xpath, final boolean requireInstance) {
42         this.xpath = xpath;
43         this.requireInstance = requireInstance;
44     }
45
46     /*
47      * (non-Javadoc)
48      *
49      * @see
50      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
51      */
52     @Override
53     public InstanceIdentifierTypeDefinition getBaseType() {
54         return this;
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
61      */
62     @Override
63     public String getUnits() {
64         return units;
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see
71      * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
72      * ()
73      */
74     @Override
75     public Object getDefaultValue() {
76         return xpath;
77     }
78
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
83      */
84     @Override
85     public QName getQName() {
86         return name;
87     }
88
89     /*
90      * (non-Javadoc)
91      *
92      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
93      */
94     @Override
95     public SchemaPath getPath() {
96         return path;
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see
103      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
104      */
105     @Override
106     public String getDescription() {
107         return description;
108     }
109
110     /*
111      * (non-Javadoc)
112      *
113      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
114      */
115     @Override
116     public String getReference() {
117         return reference;
118     }
119
120     /*
121      * (non-Javadoc)
122      *
123      * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
124      */
125     @Override
126     public Status getStatus() {
127         return Status.CURRENT;
128     }
129
130     /*
131      * (non-Javadoc)
132      *
133      * @see
134      * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
135      * ()
136      */
137     @Override
138     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
139         return Collections.emptyList();
140     }
141
142     /*
143      * (non-Javadoc)
144      *
145      * @see org.opendaylight.yangtools.yang.model.api.type.
146      * InstanceIdentifierTypeDefinition# getPathStatement()
147      */
148     @Override
149     public RevisionAwareXPath getPathStatement() {
150         return xpath;
151     }
152
153     /*
154      * (non-Javadoc)
155      *
156      * @see org.opendaylight.yangtools.yang.model.api.type.
157      * InstanceIdentifierTypeDefinition# requireInstance()
158      */
159     @Override
160     public boolean requireInstance() {
161         return requireInstance;
162     }
163
164     @Override
165     public int hashCode() {
166         final int prime = 31;
167         int result = 1;
168         result = prime * result + (requireInstance ? 1231 : 1237);
169         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
170         return result;
171     }
172
173     @Override
174     public boolean equals(Object obj) {
175         if (this == obj)
176             return true;
177         if (obj == null)
178             return false;
179         if (getClass() != obj.getClass())
180             return false;
181         InstanceIdentifier other = (InstanceIdentifier) obj;
182         if (requireInstance != other.requireInstance)
183             return false;
184         if (xpath == null) {
185             if (other.xpath != null)
186                 return false;
187         } else if (!xpath.equals(other.xpath))
188             return false;
189         return true;
190     }
191
192 }