Use Empty instead of Void for argument
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / meta / EffectiveStatement.java
index 580d8a3d1af51d0340e7f438016475ca9a9962a5..fe8d8b2522299bdc586ae654ec6915c863444ec0 100644 (file)
@@ -7,22 +7,19 @@
  */
 package org.opendaylight.yangtools.yang.model.api.meta;
 
-import static java.util.Objects.requireNonNull;
-
 import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableMap;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Optional;
 import java.util.stream.Stream;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.common.Empty;
 
 /**
  * Effective model statement which should be used to derive application behaviour.
  *
- * @param <A> Argument type ({@link Void} if statement does not have argument.)
+ * @param <A> Argument type ({@link Empty} if statement does not have argument.)
  * @param <D> Class representing declared version of this statement.
  */
 public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends ModelStatement<A> {
@@ -33,8 +30,7 @@ public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends M
      * @return statement, which was explicit declaration of this effective
      *         statement or null if statement was inferred from context.
      */
-    @Nullable
-    D getDeclared();
+    @Nullable D getDeclared();
 
     /**
      * Returns value associated with supplied identifier.
@@ -44,25 +40,11 @@ public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends M
      * @param <N> Namespace identifier type
      * @param namespace Namespace type
      * @param identifier Identifier of element.
-     * @return Value if present, null otherwise.
+     * @return Value if present
      */
     //<K, V, N extends IdentifierNamespace<? super K, ? extends V>> V
-    // FIXME: 3.0.0: make this return an Optional, not a nullable
-    @Nullable
-    <K, V, N extends IdentifierNamespace<K, V>> V get(@Nonnull Class<N> namespace, @Nonnull K identifier);
-
-    /**
-     * Returns all local values from supplied namespace.
-     *
-     * @param <K> Identifier type
-     * @param <V> Value type
-     * @param <N> Namespace identifier type
-     * @param namespace Namespace type
-     * @return Value if present, null otherwise.
-     */
-    // FIXME: 3.0.0: make this contract return empty maps on non-presence
-    @Nullable
-    <K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAll(@Nonnull Class<N> namespace);
+    <K, V, N extends IdentifierNamespace<K, V>> Optional<? extends V> get(@NonNull Class<N> namespace,
+            @NonNull K identifier);
 
     /**
      * Returns all local values from supplied namespace.
@@ -72,50 +54,52 @@ public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends M
      * @param <N> Namespace identifier type
      * @param namespace Namespace type
      * @return Key-value mappings, empty if the namespace does not exist.
+     * @throws NullPointerException if namespace is null
      */
-    // FIXME: 3.0.0: remove this in favor of fixed getAll()
-    default <K, V, N extends IdentifierNamespace<K, V>> @NonNull Map<K, V> findAll(@NonNull final Class<N> namespace) {
-        final Map<K, V> map = getAll(requireNonNull(namespace));
-        return map == null ? ImmutableMap.of() : map;
-    }
+    <K, V, N extends IdentifierNamespace<K, V>> @NonNull Map<K, V> getAll(@NonNull Class<N> namespace);
 
     /**
      * Returns a collection of all effective substatements.
      *
      * @return collection of all effective substatements.
      */
-    @Nonnull Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements();
+    @NonNull Collection<? extends @NonNull EffectiveStatement<?, ?>> effectiveSubstatements();
 
     /**
      * Find the first effective substatement of specified type.
      *
+     * @param <T> substatement type
+     * @param type substatement type
      * @return First effective substatement, or empty if no match is found.
      */
     @Beta
-    default <T extends EffectiveStatement<?, ?>> Optional<T> findFirstEffectiveSubstatement(
-            @Nonnull final Class<T> type) {
+    default <T> Optional<T> findFirstEffectiveSubstatement(final @NonNull Class<T> type) {
         return effectiveSubstatements().stream().filter(type::isInstance).findFirst().map(type::cast);
     }
 
     /**
      * Find the first effective substatement of specified type and return its value.
      *
+     * @param <T> substatement type
+     * @param <V> substatement argument type
+     * @param type substatement type
      * @return First effective substatement's argument, or empty if no match is found.
      */
     @Beta
     default <V, T extends EffectiveStatement<V, ?>> Optional<V> findFirstEffectiveSubstatementArgument(
-            @Nonnull final Class<T> type) {
-        return effectiveSubstatements().stream().filter(type::isInstance).findFirst().map(type::cast)
-                .map(EffectiveStatement::argument);
+            final @NonNull Class<T> type) {
+        return findFirstEffectiveSubstatement(type).map(EffectiveStatement::argument);
     }
 
     /**
      * Find all effective substatements of specified type and return them as a stream.
      *
+     * @param <T> substatement type
+     * @param type substatement type
      * @return A stream of all effective substatements of specified type.
      */
     @Beta
-    default <T extends EffectiveStatement<?, ?>> Stream<T> streamEffectiveSubstatements(@Nonnull final Class<T> type) {
+    default <T extends EffectiveStatement<?, ?>> Stream<T> streamEffectiveSubstatements(final @NonNull Class<T> type) {
         return effectiveSubstatements().stream().filter(type::isInstance).map(type::cast);
     }
 }