BUG-865: deprecate pre-Beryllium parser elements
[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 java.util.Objects;
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.Status;
15 import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
16
17 /**
18  * Basic implementation of SchemaNodeBuilder.
19  *
20  * @deprecated Pre-Beryllium implementation, scheduled for removal.
21  */
22 @Deprecated
23 public abstract class AbstractSchemaNodeBuilder extends AbstractBuilder implements SchemaNodeBuilder {
24     protected final QName qname;
25     protected SchemaPath schemaPath;
26     protected String description;
27     protected String reference;
28     protected Status status = Status.CURRENT;
29
30     protected AbstractSchemaNodeBuilder(final String moduleName, final int line, final QName qname) {
31         super(moduleName, line);
32         this.qname = qname;
33     }
34
35     @Override
36     public QName getQName() {
37         return qname;
38     }
39
40     @Override
41     public SchemaPath getPath() {
42         return schemaPath;
43     }
44
45     @Override
46     public void setPath(final SchemaPath path) {
47         this.schemaPath = path;
48     }
49
50     @Override
51     public String getDescription() {
52         return description;
53     }
54
55     @Override
56     public void setDescription(final String description) {
57         this.description = description;
58     }
59
60     @Override
61     public String getReference() {
62         return reference;
63     }
64
65     @Override
66     public void setReference(final String reference) {
67         this.reference = reference;
68     }
69
70     @Override
71     public Status getStatus() {
72         return status;
73     }
74
75     @Override
76     public void setStatus(final Status status) {
77         this.status = Preconditions.checkNotNull(status, "status cannot be null");
78     }
79
80     @Override
81     public int hashCode() {
82         final int prime = 31;
83         int result = super.hashCode();
84         result = prime * result + Objects.hashCode(getParent());
85         result = prime * result + Objects.hashCode(schemaPath);
86         return result;
87     }
88
89     @Override
90     public boolean equals(final Object obj) {
91         if (this == obj) {
92             return true;
93         }
94         if (obj == null) {
95             return false;
96         }
97         if (getClass() != obj.getClass()) {
98             return false;
99         }
100         if (!super.equals(obj)) {
101             return false;
102         }
103         AbstractSchemaNodeBuilder other = (AbstractSchemaNodeBuilder) obj;
104         if (getParent() == null) {
105             if (other.getParent() != null) {
106                 return false;
107             }
108         } else if (!getParent().equals(other.getParent())) {
109             return false;
110         }
111         if (schemaPath == null) {
112             if (other.schemaPath != null) {
113                 return false;
114             }
115         } else if (!schemaPath.equals(other.schemaPath)) {
116             return false;
117         }
118         return true;
119     }
120
121 }