2 * Copyright (c) 2022 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.model.api.meta;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
14 import java.util.Optional;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.Empty;
19 * Abstract base class for {@link EffectiveStatement} implementations.
21 * @param <A> Argument type ({@link Empty} if statement does not have argument.)
22 * @param <D> Class representing declared version of this statement.
24 public abstract non-sealed class AbstractEffectiveStatement<A, D extends DeclaredStatement<A>>
25 extends AbstractModelStatement<A> implements EffectiveStatement<A, D> {
27 * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
29 * @param masked list to unmask
30 * @return Unmasked list
31 * @throws NullPointerException if masked is null
32 * @throws ClassCastException if masked object does not match EffectiveStatement
34 @SuppressWarnings({ "rawtypes", "unchecked" })
35 protected static final @NonNull ImmutableList<? extends @NonNull EffectiveStatement<?, ?>> unmaskList(
36 final @NonNull Object masked) {
37 return (ImmutableList) unmaskList(masked, EffectiveStatement.class);
40 protected static final <E> @NonNull Optional<E> filterOptional(final @NonNull Optional<?> optional,
41 final @NonNull Class<E> type) {
42 return optional.filter(type::isInstance).map(type::cast);
45 protected static final <K, V> @NonNull Optional<V> findValue(final Map<K, V> map, final K key) {
46 return Optional.ofNullable(map.get(requireNonNull(key)));