Merge "(Bug 2035) - Increasing default Akka config for auto-down of unreachable nodes...
[controller.git] / opendaylight / md-sal / sal-dom-api / src / main / java / org / opendaylight / controller / md / sal / dom / api / DOMDataTreeIdentifier.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/epl-v10.html
6  */
7 package org.opendaylight.controller.md.sal.dom.api;
8
9 import com.google.common.base.Preconditions;
10 import java.io.Serializable;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.yangtools.concepts.Immutable;
14 import org.opendaylight.yangtools.concepts.Path;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16
17 /**
18  * A unique identifier for a particular subtree. It is composed of the logical
19  * data store type and the instance identifier of the root node.
20  */
21 public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeIdentifier>, Serializable {
22     private static final long serialVersionUID = 1L;
23     private final YangInstanceIdentifier rootIdentifier;
24     private final LogicalDatastoreType datastoreType;
25
26     public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType, final YangInstanceIdentifier rootIdentifier) {
27         this.datastoreType = Preconditions.checkNotNull(datastoreType);
28         this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
29     }
30
31     /**
32      * Return the logical data store type.
33      *
34      * @return Logical data store type. Guaranteed to be non-null.
35      */
36     public @Nonnull LogicalDatastoreType getDatastoreType() {
37         return datastoreType;
38     }
39
40     /**
41      * Return the {@link YangInstanceIdentifier} of the root node.
42      *
43      * @return Instance identifier corresponding to the root node.
44      */
45     public @Nonnull YangInstanceIdentifier getRootIdentifier() {
46         return rootIdentifier;
47     }
48
49     @Override
50     public boolean contains(final DOMDataTreeIdentifier other) {
51         return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = 1;
58         result = prime * result + datastoreType.hashCode();
59         result = prime * result + rootIdentifier.hashCode();
60         return result;
61     }
62
63     @Override
64     public boolean equals(final Object obj) {
65         if (this == obj) {
66             return true;
67         }
68         if (!(obj instanceof DOMDataTreeIdentifier)) {
69             return false;
70         }
71         DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
72         if (datastoreType != other.datastoreType) {
73             return false;
74         }
75         return rootIdentifier.equals(other.rootIdentifier);
76     }
77 }