Merge "Fix for Bug 511 (yang)"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / api / AbstractSchemaNodeBuilder.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.api;
9
10 import java.util.List;
11
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
15
16 /**
17  * Basic implementation of SchemaNodeBuilder.
18  */
19 public abstract class AbstractSchemaNodeBuilder extends AbstractBuilder implements SchemaNodeBuilder {
20     protected final QName qname;
21     protected SchemaPath schemaPath;
22
23     protected AbstractSchemaNodeBuilder(final String moduleName, final int line, final QName qname) {
24         super(moduleName, line);
25         this.qname = qname;
26     }
27
28     @Override
29     public int hashCode() {
30         final int prime = 31;
31         int result = super.hashCode();
32         result = prime * result + ((parentBuilder == null) ? 0 : parentBuilder.hashCode());
33         result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
34         return result;
35     }
36
37     @Override
38     public boolean equals(Object obj) {
39         if (this == obj) {
40             return true;
41         }
42         if (obj == null) {
43             return false;
44         }
45         if (getClass() != obj.getClass()) {
46             return false;
47         }
48         if (!super.equals(obj)) {
49             return false;
50         }
51         AbstractSchemaNodeBuilder other = (AbstractSchemaNodeBuilder) obj;
52         if (parentBuilder == null) {
53             if (other.parentBuilder != null) {
54                 return false;
55             }
56         } else if (!parentBuilder.equals(other.parentBuilder)) {
57             return false;
58         }
59         if (schemaPath == null) {
60             if (other.schemaPath != null) {
61                 return false;
62             }
63         } else if (!schemaPath.equals(other.schemaPath)) {
64             return false;
65         }
66         return true;
67     }
68
69     @Override
70     public QName getQName() {
71         return qname;
72     }
73
74     public void setUnknownNodes(List<UnknownSchemaNode> unknownNodes) {
75         this.unknownNodes.addAll(unknownNodes);
76     }
77
78 }