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