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.type;
10 import com.google.common.collect.ImmutableList;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Objects;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
21 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedNode;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
26 public class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, BitStatement>
27 implements BitEffectiveStatement {
29 private final QName qname;
30 private final SchemaPath schemaPath;
31 private final Long declaredPosition;
32 private final List<UnknownSchemaNode> unknownSchemaNodes;
34 public BitEffectiveStatementImpl(final StmtContext<QName, BitStatement, ?> ctx) {
37 qname = ctx.getStatementArgument();
38 schemaPath = ctx.getSchemaPath().get();
40 final List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
41 Long declaredPositionInit = null;
42 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
43 if (effectiveStatement instanceof PositionEffectiveStatementImpl) {
44 declaredPositionInit = ((PositionEffectiveStatementImpl) effectiveStatement).argument();
46 if (effectiveStatement instanceof UnknownSchemaNode) {
47 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
51 declaredPosition = declaredPositionInit;
52 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
55 public Long getDeclaredPosition() {
56 return declaredPosition;
59 public String getName() {
60 return qname.getLocalName();
63 public QName getQName() {
67 public SchemaPath getPath() {
73 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
74 return unknownSchemaNodes;
78 public int hashCode() {
81 result = prime * result + qname.hashCode();
82 result = prime * result + schemaPath.hashCode();
83 result = prime * result + Objects.hashCode(declaredPosition);
84 result = prime * result + Objects.hashCode(unknownSchemaNodes);
89 public boolean equals(final Object obj) {
96 if (getClass() != obj.getClass()) {
99 final BitsTypeDefinition.Bit other = (BitsTypeDefinition.Bit) obj;
100 return Objects.equals(qname, other.getQName()) && Objects.equals(schemaPath, other.getPath());
104 public String toString() {
105 return BitEffectiveStatementImpl.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position="
106 + declaredPosition + "]";