/* * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; import java.util.Map; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; /** * Baseline stateless implementation of an EffectiveStatement. This class adds a few default implementations and * namespace dispatch, but does not actually force any state on its subclasses. This approach is different from * {@link EffectiveStatementBase} in that it adds requirements for an implementation, but it leaves it up to the final * class to provide object layout. * *

* This finds immense value in catering the common case, for example effective statements which can, but typically * do not, contain substatements. * * @param Argument type ({@link Void} if statement does not have argument.) * @param Class representing declared version of this statement. */ @Beta public abstract class AbstractEffectiveStatement> implements EffectiveStatement { @Override public final > Optional get(final Class namespace, final K identifier) { return Optional.ofNullable(getAll(namespace).get(requireNonNull(identifier))); } @Override public final > Map getAll(final Class namespace) { final Optional> ret = getNamespaceContents(requireNonNull(namespace)); return ret.isPresent() ? ret.get() : ImmutableMap.of(); } /** * Return the statement-specific contents of specified namespace, if available. * * @param namespace Requested namespace * @return Namespace contents, if available. */ protected > Optional> getNamespaceContents( final @NonNull Class namespace) { return Optional.empty(); } }