Populate data/ hierarchy
[yangtools.git] / model / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / stmt / TypeStatement.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.model.api.stmt;
9
10 import java.util.Collection;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
18
19 @Rfc6020AbnfRule("type-stmt")
20 public interface TypeStatement extends DeclaredStatement<QName> {
21     @Override
22     default StatementDefinition statementDefinition() {
23         return YangStmtMapping.TYPE;
24     }
25
26     @Rfc6020AbnfRule("numerical-restrictions")
27     // FIXME: 7.0.0: this interface does not have an implementation
28     interface NumericalRestrictions extends TypeStatement {
29         default @Nullable RangeStatement getRange() {
30             return findFirstDeclaredSubstatement(RangeStatement.class).orElse(null);
31         }
32     }
33
34     @Rfc6020AbnfRule("decimal64-specification")
35     interface Decimal64Specification extends TypeStatement {
36         default @NonNull FractionDigitsStatement getFractionDigits() {
37             return findFirstDeclaredSubstatement(FractionDigitsStatement.class).get();
38         }
39
40         default @Nullable RangeStatement getRange() {
41             final Optional<RangeStatement> opt = findFirstDeclaredSubstatement(RangeStatement.class);
42             return opt.isPresent() ? opt.get() : null;
43         }
44     }
45
46     @Rfc6020AbnfRule("string-restrictions")
47     // FIXME: 7.0.0: this interface does not have an implementation
48     interface StringRestrictions extends TypeStatement {
49         default @Nullable LengthStatement getLength() {
50             final Optional<LengthStatement> opt = findFirstDeclaredSubstatement(LengthStatement.class);
51             return opt.isPresent() ? opt.get() : null;
52         }
53
54         default @NonNull Collection<? extends PatternStatement> getPatterns() {
55             return declaredSubstatements(PatternStatement.class);
56         }
57     }
58
59     @Rfc6020AbnfRule("enum-specification")
60     interface EnumSpecification extends TypeStatement {
61
62         default @NonNull Collection<? extends EnumStatement> getEnums() {
63             return declaredSubstatements(EnumStatement.class);
64         }
65     }
66
67     @Rfc6020AbnfRule("leafref-specification")
68     interface LeafrefSpecification extends TypeStatement {
69         default @NonNull PathStatement getPath() {
70             return findFirstDeclaredSubstatement(PathStatement.class).get();
71         }
72
73         /**
74          * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
75          * null.
76          *
77          * @return require-instance statement, if present.
78          */
79         default @Nullable RequireInstanceStatement getRequireInstance() {
80             final Optional<RequireInstanceStatement> opt =
81                     findFirstDeclaredSubstatement(RequireInstanceStatement.class);
82             return opt.isPresent() ? opt.get() : null;
83         }
84     }
85
86     @Rfc6020AbnfRule("instanceidentifier-specification")
87     interface InstanceIdentifierSpecification extends TypeStatement {
88         /**
89          * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
90          * null.
91          *
92          * @return require-instance statement, if present.
93          */
94         default @Nullable RequireInstanceStatement getRequireInstance() {
95             final Optional<RequireInstanceStatement> opt =
96                     findFirstDeclaredSubstatement(RequireInstanceStatement.class);
97             return opt.isPresent() ? opt.get() : null;
98         }
99     }
100
101     @Rfc6020AbnfRule("identityref-specification")
102     interface IdentityRefSpecification extends TypeStatement {
103         /**
104          * Returns the base statements.
105          *
106          * @return collection of base statements (in YANG 1.1 models) or a collection containing just one base
107          *         statement (in YANG 1.0 models)
108          */
109         default @NonNull Collection<? extends BaseStatement> getBases() {
110             return declaredSubstatements(BaseStatement.class);
111         }
112     }
113
114     @Rfc6020AbnfRule("bits-specification")
115     interface BitsSpecification extends TypeStatement {
116         default @NonNull Collection<? extends BitStatement> getBits() {
117             return declaredSubstatements(BitStatement.class);
118         }
119     }
120
121     @Rfc6020AbnfRule("union-specification")
122     interface UnionSpecification extends TypeStatement {
123         default @NonNull Collection<? extends TypeStatement> getTypes() {
124             return declaredSubstatements(TypeStatement.class);
125         }
126     }
127
128     @Rfc6020AbnfRule("binary-specification")
129     interface BinarySpecification extends TypeStatement {
130         default @NonNull Collection<? extends LengthStatement> getLength() {
131             return declaredSubstatements(LengthStatement.class);
132         }
133     }
134 }