e4406164f895422b988b3df3e25c0a57c0edcff1
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / LeafSchemaNodeImpl.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.base.Optional;
11 import com.google.common.collect.ImmutableList;
12 import java.util.List;
13 import java.util.Objects;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
16 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.Status;
20 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
22
23 final class LeafSchemaNodeImpl implements LeafSchemaNode, DerivableSchemaNode {
24     private final QName qname;
25     private final SchemaPath path;
26     String description;
27     String reference;
28     Status status;
29     boolean augmenting;
30     boolean addedByUses;
31     LeafSchemaNode original;
32     boolean configuration;
33     ConstraintDefinition constraintsDef;
34     TypeDefinition<?> type;
35     ImmutableList<UnknownSchemaNode> unknownNodes;
36     String defaultStr;
37     String unitsStr;
38
39     LeafSchemaNodeImpl(final QName qname, final SchemaPath path) {
40         this.qname = qname;
41         this.path = path;
42     }
43
44     @Override
45     public QName getQName() {
46         return qname;
47     }
48
49     @Override
50     public SchemaPath getPath() {
51         return path;
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 isAugmenting() {
71         return augmenting;
72     }
73
74     @Override
75     public boolean isAddedByUses() {
76         return addedByUses;
77     }
78
79     @Override
80     public Optional<LeafSchemaNode> getOriginal() {
81         return Optional.fromNullable(original);
82     }
83
84     @Override
85     public boolean isConfiguration() {
86         return configuration;
87     }
88
89     @Override
90     public ConstraintDefinition getConstraints() {
91         return constraintsDef;
92     }
93
94     @Override
95     public TypeDefinition<?> getType() {
96         return type;
97     }
98
99     @Override
100     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
101         return unknownNodes;
102     }
103
104     @Override
105     public String getDefault() {
106         return defaultStr;
107     }
108
109     @Override
110     public String getUnits() {
111         return unitsStr;
112     }
113
114     @Override
115     public int hashCode() {
116         final int prime = 31;
117         int result = 1;
118         result = prime * result + Objects.hashCode(qname);
119         result = prime * result + Objects.hashCode(path);
120         return result;
121     }
122
123     @Override
124     public boolean equals(final Object obj) {
125         if (this == obj) {
126             return true;
127         }
128         if (obj == null) {
129             return false;
130         }
131         if (getClass() != obj.getClass()) {
132             return false;
133         }
134         LeafSchemaNodeImpl other = (LeafSchemaNodeImpl) obj;
135         if (qname == null) {
136             if (other.qname != null) {
137                 return false;
138             }
139         } else if (!qname.equals(other.qname)) {
140             return false;
141         }
142         if (path == null) {
143             if (other.path != null) {
144                 return false;
145             }
146         } else if (!path.equals(other.path)) {
147             return false;
148         }
149         return true;
150     }
151
152     @Override
153     public String toString() {
154         StringBuilder sb = new StringBuilder(LeafSchemaNodeImpl.class.getSimpleName());
155         sb.append("[");
156         sb.append("qname=").append(qname);
157         sb.append(", path=").append(path);
158         sb.append("]");
159         return sb.toString();
160     }
161 }