Propagate @NonNull collection annotations
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / ActionNodeContainer.java
index b46df1fb416ed6204ba0d455f9390ddedc36baad..c258c38d75ef3bc46d7495ee3a4cb786f7b3beb8 100644 (file)
@@ -5,32 +5,42 @@
  * 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;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableSet;
-import java.util.Set;
+import java.util.Collection;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
 
 /**
- * Node which can contain action nodes
+ * Node which can contain action nodes.
  */
 @Beta
 public interface ActionNodeContainer {
-
     /**
-     * All implementations should override this method.
-     * The default definition of this method is used in YANG 1.0 (RFC6020) implementations of
-     * AugmentationSchema, GroupingDefinition, ListSchemaNode and ContainerSchemaNode
-     * which do not allow action statements.
-     * These YANG statements have been changed in YANG 1.1 (RFC7950) and can now contain action statements.
-     *
-     * The default definition is also used by implementations of ContainerSchemaNode which do not support
-     * action statements such as InputEffectiveStatementImpl, OutputEffectiveStatementImpl and SchemaContext.
+     * Return the set of actions.
      *
      * @return set of action nodes
      */
-    default Set<ActionDefinition> getActions() {
-        return ImmutableSet.of();
+    @NonNull Collection<? extends @NonNull ActionDefinition> getActions();
+
+    /**
+     * Find an action based on its QName. Default implementation searches the set returned by {@link #getActions()}.
+     *
+     * @param qname Action's QName
+     * @return Action definition, if found
+     * @throws NullPointerException if qname is null
+     */
+    default Optional<ActionDefinition> findAction(final QName qname) {
+        requireNonNull(qname);
+        for (ActionDefinition action : getActions()) {
+            if (qname.equals(action.getQName())) {
+                return Optional.of(action);
+            }
+        }
+        return Optional.empty();
     }
 }