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