1 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
3 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
5 import java.util.Collection;
6 import java.util.HashSet;
7 import java.util.LinkedList;
8 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
9 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
10 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
11 import org.opendaylight.yangtools.yang.model.api.stmt.ListStatement;
12 import com.google.common.base.Optional;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.List;
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.DerivableSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
25 public class ListEffectiveStatementImpl extends
26 AbstractEffectiveDocumentedDataNodeContainer<QName, ListStatement>
27 implements ListSchemaNode, DerivableSchemaNode {
28 private final QName qname;
29 private final SchemaPath path;
33 ListSchemaNode original;
34 boolean configuration;
35 ConstraintDefinition constraints;
38 ImmutableList<QName> keyDefinition;
39 ImmutableSet<AugmentationSchema> augmentations;
40 ImmutableList<UnknownSchemaNode> unknownNodes;
42 public ListEffectiveStatementImpl(
43 StmtContext<QName, ListStatement, EffectiveStatement<QName, ListStatement>> ctx) {
45 this.qname = ctx.getStatementArgument();
46 this.path = Utils.getSchemaPath(ctx);
47 // :TODO init other fields
50 initSubstatementCollections();
56 private void initKeyDefinition() {
57 List<QName> keyDefinition = new LinkedList<QName>();
58 KeyEffectiveStatementImpl key = firstEffective(KeyEffectiveStatementImpl.class);
61 Collection<SchemaNodeIdentifier> keyParts = key.argument();
62 for (SchemaNodeIdentifier keyPart : keyParts) {
63 keyDefinition.add(keyPart.getLastComponent());
67 this.keyDefinition = ImmutableList.copyOf(keyDefinition);
70 private void initSubstatementCollections() {
71 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
73 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
74 HashSet<AugmentationSchema> augmentations = new HashSet<AugmentationSchema>();
76 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
77 if (effectiveStatement instanceof UnknownSchemaNode) {
78 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
79 unknownNodes.add(unknownNode);
81 if (effectiveStatement instanceof AugmentationSchema) {
82 AugmentationSchema augmentationSchema = (AugmentationSchema) effectiveStatement;
83 augmentations.add(augmentationSchema);
87 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
88 this.augmentations = ImmutableSet.copyOf(augmentations);
92 public QName getQName() {
97 public SchemaPath getPath() {
102 public List<QName> getKeyDefinition() {
103 return keyDefinition;
107 public boolean isAugmenting() {
112 public boolean isAddedByUses() {
117 public Optional<ListSchemaNode> getOriginal() {
118 return Optional.fromNullable(original);
122 public boolean isConfiguration() {
123 return configuration;
127 public ConstraintDefinition getConstraints() {
132 public Set<AugmentationSchema> getAvailableAugmentations() {
133 return augmentations;
137 public boolean isUserOrdered() {
142 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
147 public int hashCode() {
148 final int prime = 31;
150 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
151 result = prime * result + ((path == null) ? 0 : path.hashCode());
156 public boolean equals(final Object obj) {
163 if (getClass() != obj.getClass()) {
166 final ListEffectiveStatementImpl other = (ListEffectiveStatementImpl) obj;
168 if (other.qname != null) {
171 } else if (!qname.equals(other.qname)) {
175 if (other.path != null) {
178 } else if (!path.equals(other.path)) {
185 public String toString() {
186 return "list " + qname.getLocalName();