Bug3659: UnknownSchemaNodeImpl retains empty ArrayLists FIX
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / UnknownSchemaNodeImpl.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.parser.builder.impl;
9
10 import com.google.common.collect.ImmutableList;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17
18 final class UnknownSchemaNodeImpl implements UnknownSchemaNode {
19     private final QName qname;
20     private final SchemaPath path;
21     private ExtensionDefinition extension;
22     String description;
23     String reference;
24     Status status = Status.CURRENT;
25     private List<UnknownSchemaNode> unknownNodes = ImmutableList.of();
26     private QName nodeType;
27     private String nodeParameter;
28     boolean addedByUses;
29
30     UnknownSchemaNodeImpl(final QName qname, final SchemaPath path) {
31         this.qname = qname;
32         this.path = path;
33     }
34
35     @Override
36     public QName getQName() {
37         return qname;
38     }
39
40     @Override
41     public SchemaPath getPath() {
42         return path;
43     }
44
45     @Override
46     public ExtensionDefinition getExtensionDefinition() {
47         return extension;
48     }
49
50     void setExtensionDefinition(final ExtensionDefinition extension) {
51         this.extension = extension;
52     }
53
54     @Override
55     public String getDescription() {
56         return description;
57     }
58
59     @Override
60     public String getReference() {
61         return reference;
62     }
63
64     @Override
65     public Status getStatus() {
66         return status;
67     }
68
69     @Override
70     public boolean isAddedByUses() {
71         return addedByUses;
72     }
73
74     @Override
75     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
76         return unknownNodes;
77     }
78
79     void setUnknownSchemaNodes(final List<UnknownSchemaNode> unknownNodes) {
80         if (unknownNodes != null) {
81             this.unknownNodes = ImmutableList.copyOf(unknownNodes);
82         }
83     }
84
85     @Override
86     public QName getNodeType() {
87         return nodeType;
88     }
89
90     void setNodeType(final QName nodeType) {
91         this.nodeType = nodeType;
92     }
93
94     @Override
95     public String getNodeParameter() {
96         return nodeParameter;
97     }
98
99     void setNodeParameter(final String nodeParameter) {
100         this.nodeParameter = nodeParameter;
101     }
102
103     @Override
104     public String toString() {
105         StringBuilder sb = new StringBuilder();
106         sb.append(nodeType.getNamespace());
107         sb.append(":");
108         sb.append(nodeType.getLocalName());
109         sb.append(" ");
110         sb.append(nodeParameter);
111         return sb.toString();
112     }
113
114     @Override
115     public int hashCode() {
116         final int prime = 31;
117         int result = 1;
118         result = prime * result + ((qname == null) ? 0 : qname.hashCode());
119         result = prime * result + ((path == null) ? 0 : path.hashCode());
120         result = prime * result + ((nodeType == null) ? 0 : nodeType.hashCode());
121         result = prime * result + ((nodeParameter == null) ? 0 : nodeParameter.hashCode());
122         return result;
123     }
124
125     @Override
126     public boolean equals(final Object obj) {
127         if (this == obj) {
128             return true;
129         }
130         if (obj == null) {
131             return false;
132         }
133         if (getClass() != obj.getClass()) {
134             return false;
135         }
136         UnknownSchemaNodeImpl other = (UnknownSchemaNodeImpl) obj;
137         if (qname == null) {
138             if (other.qname != null) {
139                 return false;
140             }
141         } else if (!qname.equals(other.qname)) {
142             return false;
143         }
144         if (path == null) {
145             if (other.path != null) {
146                 return false;
147             }
148         } else if (!path.equals(other.path)) {
149             return false;
150         }
151         if (nodeType == null) {
152             if (other.nodeType != null) {
153                 return false;
154             }
155         } else if (!nodeType.equals(other.nodeType)) {
156             return false;
157         }
158         if (nodeParameter == null) {
159             if (other.nodeParameter != null) {
160                 return false;
161             }
162         } else if (!nodeParameter.equals(other.nodeParameter)) {
163             return false;
164         }
165         return true;
166     }
167
168 }