Fixed a bug to block the creation of a static host on an ISL port, removed the code...
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / main / java / org / opendaylight / controller / yang / 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.parser.builder.impl;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14 import org.opendaylight.controller.yang.common.QName;
15 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
16 import org.opendaylight.controller.yang.model.api.SchemaPath;
17 import org.opendaylight.controller.yang.model.api.Status;
18 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
19 import org.opendaylight.controller.yang.parser.builder.api.AbstractSchemaNodeBuilder;
20 import org.opendaylight.controller.yang.parser.util.Comparators;
21
22 public final class FeatureBuilder extends AbstractSchemaNodeBuilder {
23     private boolean isBuilt;
24     private final FeatureDefinitionImpl instance;
25
26     FeatureBuilder(final int line, final QName qname) {
27         super(line, qname);
28         instance = new FeatureDefinitionImpl(qname);
29     }
30
31     @Override
32     public FeatureDefinitionImpl build() {
33         if (!isBuilt) {
34             instance.setPath(schemaPath);
35             instance.setDescription(description);
36             instance.setReference(reference);
37             instance.setStatus(status);
38
39             // UNKNOWN NODES
40             if (unknownNodes == null) {
41                 unknownNodes = new ArrayList<UnknownSchemaNode>();
42                 for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
43                     unknownNodes.add(b.build());
44                 }
45                 Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
46             }
47             instance.setUnknownSchemaNodes(unknownNodes);
48
49             isBuilt = true;
50         }
51         return instance;
52     }
53
54     private final class FeatureDefinitionImpl implements FeatureDefinition {
55         private final QName qname;
56         private SchemaPath path;
57         private String description;
58         private String reference;
59         private Status status = Status.CURRENT;
60         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
61
62         private FeatureDefinitionImpl(final QName qname) {
63             this.qname = qname;
64         }
65
66         @Override
67         public QName getQName() {
68             return qname;
69         }
70
71         @Override
72         public SchemaPath getPath() {
73             return path;
74         }
75
76         private void setPath(final SchemaPath path) {
77             this.path = path;
78         }
79
80         @Override
81         public String getDescription() {
82             return description;
83         }
84
85         private void setDescription(final String description) {
86             this.description = description;
87         }
88
89         @Override
90         public String getReference() {
91             return reference;
92         }
93
94         private void setReference(final String reference) {
95             this.reference = reference;
96         }
97
98         @Override
99         public Status getStatus() {
100             return status;
101         }
102
103         private void setStatus(Status status) {
104             if (status != null) {
105                 this.status = status;
106             }
107         }
108
109         @Override
110         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
111             return unknownNodes;
112         }
113
114         private void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
115             if (unknownNodes != null) {
116                 this.unknownNodes = unknownNodes;
117             }
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             return result;
127         }
128
129         @Override
130         public boolean equals(Object obj) {
131             if (this == obj) {
132                 return true;
133             }
134             if (obj == null) {
135                 return false;
136             }
137             if (getClass() != obj.getClass()) {
138                 return false;
139             }
140             FeatureDefinitionImpl other = (FeatureDefinitionImpl) obj;
141             if (qname == null) {
142                 if (other.qname != null) {
143                     return false;
144                 }
145             } else if (!qname.equals(other.qname)) {
146                 return false;
147             }
148             if (path == null) {
149                 if (other.path != null) {
150                     return false;
151                 }
152             } else if (!path.equals(other.path)) {
153                 return false;
154             }
155             return true;
156         }
157
158         @Override
159         public String toString() {
160             StringBuilder sb = new StringBuilder(FeatureDefinitionImpl.class.getSimpleName());
161             sb.append("[name=" + qname + "]");
162             return sb.toString();
163         }
164     }
165
166 }