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.LeafListStatement;
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.LeafListSchemaNode;
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 LeafListEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements LeafListSchemaNode, DerivableSchemaNode {
29 private final QName qname;
30 private final SchemaPath path;
34 LeafListSchemaNode original;
35 boolean configuration;
36 ConstraintDefinition constraintsDef;
37 TypeDefinition<?> type;
40 private ImmutableList<UnknownSchemaNode> unknownNodes;
42 public LeafListEffectiveStatementImpl(StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
44 this.qname = ctx.getStatementArgument();
45 this.path = Utils.getSchemaPath(ctx);
46 //:TODO init other fields
48 initSubstatementCollections();
51 private void initSubstatementCollections() {
52 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
54 LinkedList<UnknownSchemaNode> unknownNodes = new LinkedList<UnknownSchemaNode>();
56 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
57 if (effectiveStatement instanceof UnknownSchemaNode) {
58 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
59 unknownNodes.add(unknownNode);
63 this.unknownNodes = ImmutableList.copyOf(unknownNodes);
67 public QName getQName() {
72 public SchemaPath getPath() {
77 public boolean isAugmenting() {
82 public boolean isAddedByUses() {
87 public Optional<LeafListSchemaNode> getOriginal() {
88 return Optional.fromNullable(original);
92 public boolean isConfiguration() {
97 public ConstraintDefinition getConstraints() {
98 return constraintsDef;
102 public TypeDefinition<?> getType() {
107 public boolean isUserOrdered() {
112 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
117 public int hashCode() {
118 final int prime = 31;
120 result = prime * result + ((qname == null) ? 0 : qname.hashCode());
121 result = prime * result + ((path == null) ? 0 : path.hashCode());
126 public boolean equals(final Object obj) {
133 if (getClass() != obj.getClass()) {
136 LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) obj;
138 if (other.qname != null) {
141 } else if (!qname.equals(other.qname)) {
145 if (other.path != null) {
148 } else if (!path.equals(other.path)) {
155 public String toString() {
156 StringBuilder sb = new StringBuilder(LeafListEffectiveStatementImpl.class.getSimpleName());
160 return sb.toString();