Merge "Bug 2841: Fixed missing output element in Restconf RPCs"
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / tree / ListenerNode.java
1 /**
2  * Copyright (c) 2014 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.controller.md.sal.dom.store.impl.tree;
9
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeNode;
14 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
15 import org.opendaylight.yangtools.concepts.Identifiable;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
18
19 /**
20  * This is a single node within the listener tree. Note that the data returned from
21  * and instance of this class is guaranteed to have any relevance or consistency
22  * only as long as the {@link ListenerWalker} instance through which it is reached remains
23  * unclosed.
24  *
25  * @author Robert Varga
26  */
27 public class ListenerNode implements StoreTreeNode<ListenerNode>, Identifiable<PathArgument> {
28     final RegistrationTreeNode<DataChangeListenerRegistration<?>> delegate;
29
30     ListenerNode(final RegistrationTreeNode<DataChangeListenerRegistration<?>> delegate) {
31         this.delegate = Preconditions.checkNotNull(delegate);
32     }
33
34     @Override
35     public PathArgument getIdentifier() {
36         return delegate.getIdentifier();
37     }
38
39     @Override
40     public Optional<ListenerNode> getChild(final PathArgument child) {
41         final RegistrationTreeNode<DataChangeListenerRegistration<?>> c = delegate.getExactChild(child);
42         if (c == null) {
43             return Optional.absent();
44         }
45
46         return Optional.of(new ListenerNode(c));
47     }
48
49     /**
50      * Return the list of current listeners. This collection is guaranteed
51      * to be immutable only while the walker, through which this node is
52      * reachable remains unclosed.
53      *
54      * @return the list of current listeners
55      */
56     public Collection<DataChangeListenerRegistration<?>> getListeners() {
57         return delegate.getRegistrations();
58     }
59
60     @Override
61     public int hashCode() {
62         return delegate.hashCode();
63     }
64
65     @Override
66     public boolean equals(final Object obj) {
67         return delegate.equals(obj);
68     }
69
70     @Override
71     public String toString() {
72         return delegate.toString();
73     }
74 }