2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
10 import java.util.Collection;
11 import java.util.LinkedList;
13 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.model.api.stmt.LeafStatement;
17 import com.google.common.base.Optional;
18 import com.google.common.collect.ImmutableList;
19 import java.util.List;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
22 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
28 public class LeafEffectiveStatementImpl extends
29 AbstractEffectiveDocumentedNode<QName, LeafStatement> implements
30 LeafSchemaNode, DerivableSchemaNode {
31 private final QName qname;
32 private final SchemaPath path;
36 LeafSchemaNode original;
37 boolean configuration;
38 ConstraintDefinition constraintsDef;
39 TypeDefinition<?> type;
43 private ImmutableList<UnknownSchemaNode> unknownNodes;
45 public LeafEffectiveStatementImpl(
46 StmtContext<QName, LeafStatement, EffectiveStatement<QName, LeafStatement>> ctx) {
48 this.qname = ctx.getStatementArgument();
49 this.path = Utils.getSchemaPath(ctx);
50 // :TODO init other fields
52 initSubstatementCollections();
55 private void initSubstatementCollections() {
56 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
58 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
60 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
61 if (effectiveStatement instanceof UnknownSchemaNode) {
62 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
63 unknownNodes.add(unknownNode);
67 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
71 public QName getQName() {
76 public SchemaPath getPath() {
81 public boolean isAugmenting() {
86 public boolean isAddedByUses() {
91 public Optional<LeafSchemaNode> getOriginal() {
92 return Optional.fromNullable(original);
96 public boolean isConfiguration() {
101 public ConstraintDefinition getConstraints() {
102 return constraintsDef;
106 public TypeDefinition<?> getType() {
111 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
116 public String getDefault() {
121 public String getUnits() {
126 public int hashCode() {
127 final int prime = 31;
129 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
130 result = prime * result + ((path == null) ? 0 : path.hashCode());
135 public boolean equals(final Object obj) {
142 if (getClass() != obj.getClass()) {
145 LeafEffectiveStatementImpl other = (LeafEffectiveStatementImpl) obj;
147 if (other.qname != null) {
150 } else if (!qname.equals(other.qname)) {
154 if (other.path != null) {
157 } else if (!path.equals(other.path)) {
164 public String toString() {
165 StringBuilder sb = new StringBuilder(
166 LeafEffectiveStatementImpl.class.getSimpleName());
168 sb.append("qname=").append(qname);
169 sb.append(", path=").append(path);
171 return sb.toString();