Propagate @NonNull collection annotations
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / NotificationNodeContainer.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QName;
16
17 public interface NotificationNodeContainer {
18     /**
19      * Return the set of notifications in this container, keyed by QName. RFC7950 specifies that
20      * {@link AugmentationSchemaNode}s, {@link GroupingDefinition}s, {@link ListSchemaNode}s and
21      * {@link ContainerSchemaNode}s can also contain {@link NotificationDefinition}s.
22       *
23      * @return set of notification nodes
24      */
25     @NonNull Collection<? extends @NonNull NotificationDefinition> getNotifications();
26
27     /**
28      * Find a notification based on its QName. Default implementation searches the set returned by
29      * {@link #getNotifications()}.
30      *
31      * @param qname Notification QName
32      * @return Notification definition, if found
33      * @throws NullPointerException if qname is null
34      */
35     default Optional<NotificationDefinition> findNotification(final QName qname) {
36         requireNonNull(qname);
37         for (NotificationDefinition notif : getNotifications()) {
38             if (qname.equals(notif.getQName())) {
39                 return Optional.of(notif);
40             }
41         }
42         return Optional.empty();
43     }
44 }