Merge from development repository.
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / model / parser / builder / impl / FeatureBuilder.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.parser.builder.impl;
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.FeatureDefinition;
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.parser.builder.api.SchemaNodeBuilder;
19
20 public class FeatureBuilder implements SchemaNodeBuilder {
21
22     private final FeatureDefinitionImpl instance;
23     private final QName qname;
24
25     FeatureBuilder(QName qname) {
26         this.qname = qname;
27         instance = new FeatureDefinitionImpl(qname);
28     }
29
30     @Override
31     public FeatureDefinitionImpl build() {
32         return instance;
33     }
34
35     @Override
36     public QName getQName() {
37         return qname;
38     }
39
40     @Override
41     public void setPath(SchemaPath path) {
42         instance.setPath(path);
43     }
44
45     @Override
46     public void setDescription(String description) {
47         instance.setDescription(description);
48     }
49
50     @Override
51     public void setReference(String reference) {
52         instance.setReference(reference);
53     }
54
55     @Override
56     public void setStatus(Status status) {
57         instance.setStatus(status);
58     }
59
60     private static class FeatureDefinitionImpl implements FeatureDefinition {
61         private final QName qname;
62         private SchemaPath path;
63         private String description;
64         private String reference;
65         private Status status;
66         private List<UnknownSchemaNode> unknownSchemaNodes = Collections
67                 .emptyList();
68
69         private FeatureDefinitionImpl(QName qname) {
70             this.qname = qname;
71         }
72
73         @Override
74         public QName getQName() {
75             return qname;
76         }
77
78         @Override
79         public SchemaPath getPath() {
80             return path;
81         }
82
83         private void setPath(SchemaPath path) {
84             this.path = path;
85             ;
86         }
87
88         @Override
89         public String getDescription() {
90             return description;
91         }
92
93         private void setDescription(String description) {
94             this.description = description;
95         }
96
97         @Override
98         public String getReference() {
99             return reference;
100         }
101
102         private void setReference(String reference) {
103             this.reference = reference;
104         }
105
106         @Override
107         public Status getStatus() {
108             return status;
109         }
110
111         private void setStatus(Status status) {
112             this.status = status;
113         }
114
115         @Override
116         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
117             return unknownSchemaNodes;
118         }
119
120         @Override
121         public int hashCode() {
122             final int prime = 31;
123             int result = 1;
124             result = prime * result + ((qname == null) ? 0 : qname.hashCode());
125             result = prime * result + ((path == null) ? 0 : path.hashCode());
126             result = prime * result
127                     + ((description == null) ? 0 : description.hashCode());
128             result = prime * result
129                     + ((reference == null) ? 0 : reference.hashCode());
130             result = prime * result
131                     + ((status == null) ? 0 : status.hashCode());
132             return result;
133         }
134
135         @Override
136         public boolean equals(Object obj) {
137             if (this == obj) {
138                 return true;
139             }
140             if (obj == null) {
141                 return false;
142             }
143             if (getClass() != obj.getClass()) {
144                 return false;
145             }
146             FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
147             if (qname == null) {
148                 if (other.qname != null) {
149                     return false;
150                 }
151             } else if (!qname.equals(other.qname)) {
152                 return false;
153             }
154             if (path == null) {
155                 if (other.path != null) {
156                     return false;
157                 }
158             } else if (!path.equals(other.path)) {
159                 return false;
160             }
161             if (description == null) {
162                 if (other.description != null) {
163                     return false;
164                 }
165             } else if (!description.equals(other.description)) {
166                 return false;
167             }
168             if (reference == null) {
169                 if (other.reference != null) {
170                     return false;
171                 }
172             } else if (!reference.equals(other.reference)) {
173                 return false;
174             }
175             if (status == null) {
176                 if (other.status != null) {
177                     return false;
178                 }
179             } else if (!status.equals(other.status)) {
180                 return false;
181             }
182             return true;
183         }
184
185         @Override
186         public String toString() {
187             StringBuilder sb = new StringBuilder(
188                     FeatureDefinitionImpl.class.getSimpleName());
189             sb.append("[name=" + qname);
190             sb.append(", path=" + path);
191             sb.append(", description=" + description);
192             sb.append(", reference=" + reference);
193             sb.append(", status=" + status + "]");
194             return sb.toString();
195         }
196     }
197
198 }