* 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();
}
}