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