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.Status;
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.BitStatement;
20 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
28 public class BitEffectiveStatementImpl extends DeclaredEffectiveStatementBase<QName, BitStatement> implements
29 BitsTypeDefinition.Bit {
31 private final QName qName;
32 private final SchemaPath schemaPath;
33 private Long position;
34 private String description;
35 private String reference;
36 private Status status;
37 private final List<UnknownSchemaNode> unknownSchemaNodes;
39 public BitEffectiveStatementImpl(final StmtContext<QName, BitStatement, ?> ctx) {
42 List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
44 qName = ctx.getStatementArgument();
45 schemaPath = ctx.getSchemaPath().get();
47 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
48 if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
49 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
51 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
52 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
54 if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
55 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
57 if (effectiveStatement instanceof PositionEffectiveStatementImpl) {
58 position = ((PositionEffectiveStatementImpl) effectiveStatement).argument();
61 if (effectiveStatement instanceof UnknownSchemaNode) {
62 unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement);
66 unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit);
70 public Long getPosition() {
75 public String getName() {
76 return qName.getLocalName();
80 public QName getQName() {
85 public SchemaPath getPath() {
90 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
91 return unknownSchemaNodes;
95 public String getDescription() {
100 public String getReference() {
105 public Status getStatus() {
110 public int hashCode() {
111 final int prime = 31;
113 result = prime * result + qName.hashCode();
114 result = prime * result + schemaPath.hashCode();
115 result = prime * result + Objects.hashCode(position);
116 result = prime * result + Objects.hashCode(unknownSchemaNodes);
121 public boolean equals(final Object obj) {
128 if (getClass() != obj.getClass()) {
131 BitsTypeDefinition.Bit other = (BitsTypeDefinition.Bit) obj;
132 return Objects.equals(qName, other.getQName()) && Objects.equals(schemaPath, other.getPath());
136 public String toString() {
137 return BitEffectiveStatementImpl.class.getSimpleName() + "[name=" + qName.getLocalName() + ", position="