2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.api.meta;
10 import com.google.common.annotations.Beta;
11 import java.util.Collection;
13 import java.util.Optional;
14 import java.util.stream.Stream;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.yang.common.Empty;
20 * Effective model statement which should be used to derive application behaviour.
22 * @param <A> Argument type ({@link Empty} if statement does not have argument.)
23 * @param <D> Class representing declared version of this statement.
25 public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends ModelStatement<A> {
27 * Returns statement, which was explicit declaration of this effective
30 * @return statement, which was explicit declaration of this effective
31 * statement or null if statement was inferred from context.
33 @Nullable D getDeclared();
36 * Returns value associated with supplied identifier.
38 * @param <K> Identifier type
39 * @param <V> Value type
40 * @param <N> Namespace identifier type
41 * @param namespace Namespace type
42 * @param identifier Identifier of element.
43 * @return Value if present
45 //<K, V, N extends IdentifierNamespace<? super K, ? extends V>> V
46 <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends V> get(@NonNull Class<N> namespace,
47 @NonNull K identifier);
50 * Returns all local values from supplied namespace.
52 * @param <K> Identifier type
53 * @param <V> Value type
54 * @param <N> Namespace identifier type
55 * @param namespace Namespace type
56 * @return Key-value mappings, empty if the namespace does not exist.
57 * @throws NullPointerException if namespace is null
59 <K, V, N extends IdentifierNamespace<K, V>> @NonNull Map<K, V> getAll(@NonNull Class<N> namespace);
62 * Returns a collection of all effective substatements.
64 * @return collection of all effective substatements.
66 @NonNull Collection<? extends @NonNull EffectiveStatement<?, ?>> effectiveSubstatements();
69 * Find the first effective substatement of specified type.
71 * @param <T> substatement type
72 * @param type substatement type
73 * @return First effective substatement, or empty if no match is found.
76 default <T> Optional<T> findFirstEffectiveSubstatement(final @NonNull Class<T> type) {
77 return effectiveSubstatements().stream().filter(type::isInstance).findFirst().map(type::cast);
81 * Find the first effective substatement of specified type and return its value.
83 * @param <T> substatement type
84 * @param <V> substatement argument type
85 * @param type substatement type
86 * @return First effective substatement's argument, or empty if no match is found.
89 default <V, T extends EffectiveStatement<V, ?>> Optional<V> findFirstEffectiveSubstatementArgument(
90 final @NonNull Class<T> type) {
91 return findFirstEffectiveSubstatement(type).map(EffectiveStatement::argument);
95 * Find all effective substatements of specified type and return them as a stream.
97 * @param <T> substatement type
98 * @param type substatement type
99 * @return A stream of all effective substatements of specified type.
102 default <T extends EffectiveStatement<?, ?>> Stream<T> streamEffectiveSubstatements(final @NonNull Class<T> type) {
103 return effectiveSubstatements().stream().filter(type::isInstance).map(type::cast);