Merge "Bug 1331 - Generate SPIs and yangs to target/generated-sources/ subfolders"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / util / 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.util;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
13 import org.opendaylight.yangtools.yang.model.api.Status;
14 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
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     protected String description;
23     protected String reference;
24     protected Status status = Status.CURRENT;
25
26     protected AbstractSchemaNodeBuilder(final String moduleName, final int line, final QName qname) {
27         super(moduleName, line);
28         this.qname = qname;
29     }
30
31     @Override
32     public QName getQName() {
33         return qname;
34     }
35
36     @Override
37     public SchemaPath getPath() {
38         return schemaPath;
39     }
40
41     @Override
42     public void setPath(final SchemaPath path) {
43         this.schemaPath = path;
44     }
45
46     @Override
47     public String getDescription() {
48         return description;
49     }
50
51     @Override
52     public void setDescription(final String description) {
53         this.description = description;
54     }
55
56     @Override
57     public String getReference() {
58         return reference;
59     }
60
61     @Override
62     public void setReference(final String reference) {
63         this.reference = reference;
64     }
65
66     @Override
67     public Status getStatus() {
68         return status;
69     }
70
71     @Override
72     public void setStatus(Status status) {
73         this.status = Preconditions.checkNotNull(status, "status cannot be null");
74     }
75
76     @Override
77     public int hashCode() {
78         final int prime = 31;
79         int result = super.hashCode();
80         result = prime * result + ((getParent() == null) ? 0 : getParent().hashCode());
81         result = prime * result + ((schemaPath == null) ? 0 : schemaPath.hashCode());
82         return result;
83     }
84
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj) {
88             return true;
89         }
90         if (obj == null) {
91             return false;
92         }
93         if (getClass() != obj.getClass()) {
94             return false;
95         }
96         if (!super.equals(obj)) {
97             return false;
98         }
99         AbstractSchemaNodeBuilder other = (AbstractSchemaNodeBuilder) obj;
100         if (getParent() == null) {
101             if (other.getParent() != null) {
102                 return false;
103             }
104         } else if (!getParent().equals(other.getParent())) {
105             return false;
106         }
107         if (schemaPath == null) {
108             if (other.schemaPath != null) {
109                 return false;
110             }
111         } else if (!schemaPath.equals(other.schemaPath)) {
112             return false;
113         }
114         return true;
115     }
116
117 }