760fd40f44510ccb7c4d117ae0d1d0581facb246
[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     // FIXME: 6.0.0: this interface does not have an implementation
34     interface NumericalRestrictions extends TypeStatement {
35         default @Nullable RangeStatement getRange() {
36             return findFirstDeclaredSubstatement(RangeStatement.class).orElse(null);
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     // FIXME: 6.0.0: this interface does not have an implementation
54     interface StringRestrictions extends TypeStatement {
55         default @Nullable LengthStatement getLength() {
56             final Optional<LengthStatement> opt = findFirstDeclaredSubstatement(LengthStatement.class);
57             return opt.isPresent() ? opt.get() : null;
58         }
59
60         default @NonNull Collection<? extends PatternStatement> getPatterns() {
61             return declaredSubstatements(PatternStatement.class);
62         }
63     }
64
65     @Rfc6020AbnfRule("enum-specification")
66     interface EnumSpecification extends TypeStatement {
67
68         default @NonNull Collection<? extends EnumStatement> getEnums() {
69             return declaredSubstatements(EnumStatement.class);
70         }
71     }
72
73     @Rfc6020AbnfRule("leafref-specification")
74     interface LeafrefSpecification extends TypeStatement {
75         default @NonNull PathStatement getPath() {
76             return findFirstDeclaredSubstatement(PathStatement.class).get();
77         }
78
79         /**
80          * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
81          * null.
82          *
83          * @return require-instance statement, if present.
84          */
85         default @Nullable RequireInstanceStatement getRequireInstance() {
86             final Optional<RequireInstanceStatement> opt =
87                     findFirstDeclaredSubstatement(RequireInstanceStatement.class);
88             return opt.isPresent() ? opt.get() : null;
89         }
90     }
91
92     @Rfc6020AbnfRule("instanceidentifier-specification")
93     interface InstanceIdentifierSpecification extends TypeStatement {
94         /**
95          * Return require-instance statement child, if present. For RFC6020 semantics, this method always returns
96          * null.
97          *
98          * @return require-instance statement, if present.
99          */
100         default @Nullable RequireInstanceStatement getRequireInstance() {
101             final Optional<RequireInstanceStatement> opt =
102                     findFirstDeclaredSubstatement(RequireInstanceStatement.class);
103             return opt.isPresent() ? opt.get() : null;
104         }
105     }
106
107     @Rfc6020AbnfRule("identityref-specification")
108     interface IdentityRefSpecification extends TypeStatement {
109         /**
110          * Returns the base statements.
111          *
112          * @return collection of base statements (in YANG 1.1 models) or a collection containing just one base
113          *         statement (in YANG 1.0 models)
114          */
115         default @NonNull Collection<? extends BaseStatement> getBases() {
116             return declaredSubstatements(BaseStatement.class);
117         }
118     }
119
120     @Rfc6020AbnfRule("bits-specification")
121     interface BitsSpecification extends TypeStatement {
122         default @NonNull Collection<? extends BitStatement> getBits() {
123             return declaredSubstatements(BitStatement.class);
124         }
125     }
126
127     @Rfc6020AbnfRule("union-specification")
128     interface UnionSpecification extends TypeStatement {
129         default @NonNull Collection<? extends TypeStatement> getTypes() {
130             return declaredSubstatements(TypeStatement.class);
131         }
132     }
133
134     @Rfc6020AbnfRule("binary-specification")
135     interface BinarySpecification extends TypeStatement {
136         default @NonNull Collection<? extends LengthStatement> getLength() {
137             return declaredSubstatements(LengthStatement.class);
138         }
139     }
140 }