fac9330d04427f86339064a4c37eda15b770a55a
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / impl / ContainerSchemaNodeImpl.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yangtools.yang.parser.builder.impl;
10
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableSet;
14 import java.util.List;
15 import java.util.Objects;
16 import java.util.Set;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
24 import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainer;
25
26 final class ContainerSchemaNodeImpl extends AbstractDocumentedDataNodeContainer implements
27         ContainerSchemaNode, DerivableSchemaNode {
28     private final QName qname;
29     private final SchemaPath path;
30
31     boolean augmenting;
32     boolean addedByUses;
33     boolean configuration;
34     ContainerSchemaNode original;
35     ConstraintDefinition constraints;
36
37     ImmutableSet<AugmentationSchema> augmentations;
38     ImmutableList<UnknownSchemaNode> unknownNodes;
39
40     boolean presence;
41
42     public ContainerSchemaNodeImpl(final ContainerSchemaNodeBuilder builder) {
43         super(builder);
44         this.qname = builder.getQName();
45         this.path = builder.getPath();
46     }
47
48     @Override
49     public QName getQName() {
50         return qname;
51     }
52
53     @Override
54     public SchemaPath getPath() {
55         return path;
56     }
57
58     @Override
59     public boolean isAugmenting() {
60         return augmenting;
61     }
62
63     @Override
64     public boolean isAddedByUses() {
65         return addedByUses;
66     }
67
68     @Override
69     public Optional<ContainerSchemaNode> getOriginal() {
70         return Optional.fromNullable(original);
71     }
72
73     @Override
74     public boolean isConfiguration() {
75         return configuration;
76     }
77
78     @Override
79     public ConstraintDefinition getConstraints() {
80         return constraints;
81     }
82
83     @Override
84     public Set<AugmentationSchema> getAvailableAugmentations() {
85         return augmentations;
86     }
87
88     @Override
89     public boolean isPresenceContainer() {
90         return presence;
91     }
92
93     @Override
94     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
95         return unknownNodes;
96     }
97
98     @Override
99     public int hashCode() {
100         final int prime = 31;
101         int result = 1;
102         result = prime * result + Objects.hashCode(qname);
103         result = prime * result + Objects.hashCode(path);
104         return result;
105     }
106
107     @Override
108     public boolean equals(final Object obj) {
109         if (this == obj) {
110             return true;
111         }
112         if (obj == null) {
113             return false;
114         }
115         if (getClass() != obj.getClass()) {
116             return false;
117         }
118         ContainerSchemaNodeImpl other = (ContainerSchemaNodeImpl) obj;
119         if (qname == null) {
120             if (other.qname != null) {
121                 return false;
122             }
123         } else if (!qname.equals(other.qname)) {
124             return false;
125         }
126         if (path == null) {
127             if (other.path != null) {
128                 return false;
129             }
130         } else if (!path.equals(other.path)) {
131             return false;
132         }
133         return true;
134     }
135
136     @Override
137     public String toString() {
138         return "container " + qname.getLocalName();
139     }
140
141 }