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.HashSet;
12 import java.util.LinkedList;
14 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import com.google.common.base.Optional;
19 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.ImmutableSet;
21 import java.util.List;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
25 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
26 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
27 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
29 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
31 public class CaseEffectiveStatementImpl extends
32 AbstractEffectiveDocumentedDataNodeContainer<QName, CaseStatement>
33 implements ChoiceCaseNode, DerivableSchemaNode {
34 private final QName qname;
35 private final SchemaPath path;
39 ChoiceCaseNode original;
40 ConstraintDefinition constraints;
42 ImmutableSet<AugmentationSchema> augmentations;
43 ImmutableList<UnknownSchemaNode> unknownNodes;
45 public CaseEffectiveStatementImpl(
46 StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> 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 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
59 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
61 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
62 if (effectiveStatement instanceof UnknownSchemaNode) {
63 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
64 unknownNodesInit.add(unknownNode);
66 if (effectiveStatement instanceof AugmentationSchema) {
67 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
68 augmentationsInit.add(augmentationSchema);
72 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
73 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
77 public QName getQName() {
82 public SchemaPath getPath() {
87 public boolean isConfiguration() {
92 public ConstraintDefinition getConstraints() {
97 public boolean isAugmenting() {
102 public boolean isAddedByUses() {
107 public Optional<ChoiceCaseNode> getOriginal() {
108 return Optional.fromNullable(original);
112 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
117 public Set<AugmentationSchema> getAvailableAugmentations() {
118 return augmentations;
122 public int hashCode() {
123 final int prime = 31;
125 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
126 result = prime * result + ((path == null) ? 0 : path.hashCode());
131 public boolean equals(final Object obj) {
138 if (getClass() != obj.getClass()) {
141 CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
143 if (other.qname != null) {
146 } else if (!qname.equals(other.qname)) {
150 if (other.path != null) {
153 } else if (!path.equals(other.path)) {
160 public String toString() {
161 StringBuilder sb = new StringBuilder(
162 CaseEffectiveStatementImpl.class.getSimpleName());
167 return sb.toString();