Switch position statement to use Uint32
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / bit / BitEffectiveStatementImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.bit;
9
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.common.Uint32;
12 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.BitEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.BitStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.PositionEffectiveStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNode;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19
20 // FIXME: 5.0.0: hide this class
21 public final class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode<QName, BitStatement>
22         implements BitEffectiveStatement {
23
24     private final QName qname;
25     private final SchemaPath schemaPath;
26     private final Uint32 declaredPosition;
27
28     BitEffectiveStatementImpl(final StmtContext<QName, BitStatement, ?> ctx) {
29         super(ctx);
30
31         qname = ctx.getStatementArgument();
32         schemaPath = ctx.getSchemaPath().get();
33
34         Uint32 declaredPositionInit = null;
35         for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
36             if (effectiveStatement instanceof PositionEffectiveStatement) {
37                 declaredPositionInit = ((PositionEffectiveStatement) effectiveStatement).argument();
38             }
39         }
40
41         declaredPosition = declaredPositionInit;
42     }
43
44     public Uint32 getDeclaredPosition() {
45         return declaredPosition;
46     }
47
48     public String getName() {
49         return qname.getLocalName();
50     }
51
52     public QName getQName() {
53         return qname;
54     }
55
56     public SchemaPath getPath() {
57         return schemaPath;
58     }
59
60     @Override
61     public String toString() {
62         return BitEffectiveStatementImpl.class.getSimpleName() + "[name=" + qname.getLocalName() + ", position="
63                 + declaredPosition + "]";
64     }
65 }