2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.parser.rfc7950.stmt;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.ImmutableMap;
15 import java.util.Collection;
17 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
24 * Baseline stateless implementation of an EffectiveStatement. This class adds a few default implementations and
25 * namespace dispatch, but does not actually force any state on its subclasses. This approach is different from
26 * {@link EffectiveStatementBase} in that it adds requirements for an implementation, but it leaves it up to the final
27 * class to provide object layout.
30 * This finds immense value in catering the common case, for example effective statements which can, but typically
31 * do not, contain substatements.
33 * @param <A> Argument type ({@link Void} if statement does not have argument.)
34 * @param <D> Class representing declared version of this statement.
37 public abstract class AbstractEffectiveStatement<A, D extends DeclaredStatement<A>>
38 implements EffectiveStatement<A, D> {
40 public final <K, V, N extends IdentifierNamespace<K, V>> V get(final Class<N> namespace, final K identifier) {
41 return getAll(namespace).get(requireNonNull(identifier));
45 public final <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(final Class<N> namespace) {
46 final Optional<? extends Map<K, V>> ret = getNamespaceContents(requireNonNull(namespace));
47 return ret.isPresent() ? ret.get() : ImmutableMap.of();
51 public Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements() {
52 return ImmutableList.of();
56 * Return the statement-specific contents of specified namespace, if available.
58 * @param namespace Requested namespace
59 * @return Namespace contents, if available.
61 protected <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends Map<K, V>> getNamespaceContents(
62 final @NonNull Class<N> namespace) {
63 return Optional.empty();