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