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