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 org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
12 import java.util.Collection;
13 import java.util.HashSet;
14 import java.util.LinkedList;
15 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.CaseStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import com.google.common.base.Optional;
20 import com.google.common.collect.ImmutableList;
21 import com.google.common.collect.ImmutableSet;
22 import java.util.List;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
26 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
27 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
28 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
32 public class CaseEffectiveStatementImpl extends
33 AbstractEffectiveDocumentedDataNodeContainer<QName, CaseStatement>
34 implements ChoiceCaseNode, DerivableSchemaNode {
35 private final QName qname;
36 private final SchemaPath path;
40 ChoiceCaseNode original;
41 ConstraintDefinition constraints;
43 ImmutableSet<AugmentationSchema> augmentations;
44 ImmutableList<UnknownSchemaNode> unknownNodes;
46 public CaseEffectiveStatementImpl(
47 StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
49 this.qname = ctx.getStatementArgument();
50 this.path = Utils.getSchemaPath(ctx);
51 // :TODO init other fields
53 initSubstatementCollections();
57 private void initCopyType(
58 StmtContext<QName, CaseStatement, EffectiveStatement<QName, CaseStatement>> ctx) {
60 TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
62 case ADDED_BY_AUGMENTATION:
64 original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
68 original = (ChoiceCaseNode) ctx.getOriginalCtx().buildEffective();
75 private void initSubstatementCollections() {
76 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
78 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
79 Set<AugmentationSchema> augmentationsInit = new HashSet<>();
81 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
82 if (effectiveStatement instanceof UnknownSchemaNode) {
83 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
84 unknownNodesInit.add(unknownNode);
86 if (effectiveStatement instanceof AugmentationSchema) {
87 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
88 augmentationsInit.add(augmentationSchema);
92 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
93 this.augmentations = ImmutableSet.copyOf(augmentationsInit);
97 public QName getQName() {
102 public SchemaPath getPath() {
107 public boolean isConfiguration() {
112 public ConstraintDefinition getConstraints() {
117 public boolean isAugmenting() {
122 public boolean isAddedByUses() {
127 public Optional<ChoiceCaseNode> getOriginal() {
128 return Optional.fromNullable(original);
132 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
137 public Set<AugmentationSchema> getAvailableAugmentations() {
138 return augmentations;
142 public int hashCode() {
143 final int prime = 31;
145 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
146 result = prime * result + ((path == null) ? 0 : path.hashCode());
151 public boolean equals(final Object obj) {
158 if (getClass() != obj.getClass()) {
161 CaseEffectiveStatementImpl other = (CaseEffectiveStatementImpl) obj;
163 if (other.qname != null) {
166 } else if (!qname.equals(other.qname)) {
170 if (other.path != null) {
173 } else if (!path.equals(other.path)) {
180 public String toString() {
181 StringBuilder sb = new StringBuilder(
182 CaseEffectiveStatementImpl.class.getSimpleName());
187 return sb.toString();