/* * Copyright (c) 2022 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.model.api.meta; import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableList; import java.util.Map; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.Empty; /** * Abstract base class for {@link EffectiveStatement} implementations. * * @param Argument type ({@link Empty} if statement does not have argument.) * @param Class representing declared version of this statement. */ public abstract non-sealed class AbstractEffectiveStatement> extends AbstractModelStatement implements EffectiveStatement { /** * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}. * * @param masked list to unmask * @return Unmasked list * @throws NullPointerException if masked is null * @throws ClassCastException if masked object does not match EffectiveStatement */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected static final @NonNull ImmutableList> unmaskList( final @NonNull Object masked) { return (ImmutableList) unmaskList(masked, EffectiveStatement.class); } protected static final @NonNull Optional filterOptional(final @NonNull Optional optional, final @NonNull Class type) { return optional.filter(type::isInstance).map(type::cast); } protected static final @NonNull Optional findValue(final Map map, final K key) { return Optional.ofNullable(map.get(requireNonNull(key))); } }