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 org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
19 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedNode;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
24 public class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, BitStatement> {
26 private final QName qName;
27 private final SchemaPath schemaPath;
28 private final Long declaredPosition;
29 private final List<UnknownSchemaNode> unknownSchemaNodes;
31 public BitEffectiveStatementImpl(final StmtContext<QName, BitStatement, ?> ctx) {
34 qName = ctx.getStatementArgument();
35 schemaPath = ctx.getSchemaPath().get();
37 final List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
38 Long declaredPositionInit = null;
39 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
40 if (effectiveStatement instanceof PositionEffectiveStatementImpl) {
41 declaredPositionInit = ((PositionEffectiveStatementImpl) effectiveStatement).argument();
43 if (effectiveStatement instanceof UnknownSchemaNode) {
44 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
48 declaredPosition = declaredPositionInit;
49 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
52 public Long getDeclaredPosition() {
53 return declaredPosition;
56 public String getName() {
57 return qName.getLocalName();
60 public QName getQName() {
64 public SchemaPath getPath() {
69 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
70 return unknownSchemaNodes;
74 public int hashCode() {
77 result = prime * result + qName.hashCode();
78 result = prime * result + schemaPath.hashCode();
79 result = prime * result + Objects.hashCode(declaredPosition);
80 result = prime * result + Objects.hashCode(unknownSchemaNodes);
85 public boolean equals(final Object obj) {
92 if (getClass() != obj.getClass()) {
95 final BitsTypeDefinition.Bit other = (BitsTypeDefinition.Bit) obj;
96 return Objects.equals(qName, other.getQName()) && Objects.equals(schemaPath, other.getPath());
100 public String toString() {
101 return BitEffectiveStatementImpl.class.getSimpleName() + "[name=" + qName.getLocalName() + ", position="
102 + declaredPosition + "]";