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