Fix findbugs violations in md-sal - part 1
[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.Preconditions;
11 import java.util.Collection;
12 import java.util.Optional;
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  * @deprecated Use {@link RegistrationTreeNode} instead.
28  */
29 @Deprecated
30 public class ListenerNode implements StoreTreeNode<ListenerNode>, Identifiable<PathArgument> {
31     final RegistrationTreeNode<DataChangeListenerRegistration<?>> delegate;
32
33     ListenerNode(final RegistrationTreeNode<DataChangeListenerRegistration<?>> delegate) {
34         this.delegate = Preconditions.checkNotNull(delegate);
35     }
36
37     @Override
38     public PathArgument getIdentifier() {
39         return delegate.getIdentifier();
40     }
41
42     @Override
43     public Optional<ListenerNode> getChild(final PathArgument child) {
44         final RegistrationTreeNode<DataChangeListenerRegistration<?>> c = delegate.getExactChild(child);
45         if (c == null) {
46             return Optional.empty();
47         }
48
49         return Optional.of(new ListenerNode(c));
50     }
51
52     /**
53      * Return the list of current listeners. This collection is guaranteed
54      * to be immutable only while the walker, through which this node is
55      * reachable remains unclosed.
56      *
57      * @return the list of current listeners
58      */
59     public Collection<DataChangeListenerRegistration<?>> getListeners() {
60         return delegate.getRegistrations();
61     }
62
63     @Override
64     public int hashCode() {
65         return delegate.hashCode();
66     }
67
68     @Override
69     public boolean equals(final Object obj) {
70         if (obj == null || getClass() != obj.getClass()) {
71             return false;
72         }
73
74         return delegate.equals(((ListenerNode)obj).delegate);
75     }
76
77     @Override
78     public String toString() {
79         return delegate.toString();
80     }
81 }