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.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.parser.spi.meta.StmtContext;
17 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListStatement;
18 import com.google.common.base.Optional;
19 import com.google.common.collect.ImmutableList;
20 import java.util.List;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
23 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
27 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
29 public class LeafListEffectiveStatementImpl extends
30 AbstractEffectiveDocumentedNode<QName, LeafListStatement> implements
31 LeafListSchemaNode, DerivableSchemaNode {
32 private final QName qname;
33 private final SchemaPath path;
37 LeafListSchemaNode original;
38 boolean configuration;
39 ConstraintDefinition constraintsDef;
40 TypeDefinition<?> type;
43 private ImmutableList<UnknownSchemaNode> unknownNodes;
45 public LeafListEffectiveStatementImpl(
46 StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
48 this.qname = ctx.getStatementArgument();
49 this.path = Utils.getSchemaPath(ctx);
50 // :TODO init other fields
52 initSubstatementCollections();
56 private void initCopyType(
57 StmtContext<QName, LeafListStatement, EffectiveStatement<QName, LeafListStatement>> ctx) {
59 TypeOfCopy typeOfCopy = ctx.getTypeOfCopy();
61 case ADDED_BY_AUGMENTATION:
63 original = (LeafListSchemaNode) ctx.getOriginalCtx()
68 original = (LeafListSchemaNode) ctx.getOriginalCtx()
76 private void initSubstatementCollections() {
77 Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements = effectiveSubstatements();
79 List<UnknownSchemaNode> unknownNodesInit = new LinkedList<>();
81 for (EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements) {
82 if (effectiveStatement instanceof UnknownSchemaNode) {
83 UnknownSchemaNode unknownNode = (UnknownSchemaNode) effectiveStatement;
84 unknownNodesInit.add(unknownNode);
88 this.unknownNodes = ImmutableList.copyOf(unknownNodesInit);
92 public QName getQName() {
97 public SchemaPath getPath() {
102 public boolean isAugmenting() {
107 public boolean isAddedByUses() {
112 public Optional<LeafListSchemaNode> getOriginal() {
113 return Optional.fromNullable(original);
117 public boolean isConfiguration() {
118 return configuration;
122 public ConstraintDefinition getConstraints() {
123 return constraintsDef;
127 public TypeDefinition<?> getType() {
132 public boolean isUserOrdered() {
137 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
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 LeafListEffectiveStatementImpl other = (LeafListEffectiveStatementImpl) 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 LeafListEffectiveStatementImpl.class.getSimpleName());
186 return sb.toString();