2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.api;
10 import com.google.common.base.Preconditions;
11 import java.io.Serializable;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.concepts.Path;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 * A unique identifier for a particular subtree. It is composed of the logical
21 * data store type and the instance identifier of the root node.
23 public final class DataTreeIdentifier<T extends DataObject> implements Immutable,
24 Path<DataTreeIdentifier<?>>, Serializable {
25 private static final long serialVersionUID = 1L;
26 private final InstanceIdentifier<T> rootIdentifier;
27 private final LogicalDatastoreType datastoreType;
29 public DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> rootIdentifier) {
30 this.datastoreType = Preconditions.checkNotNull(datastoreType);
31 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
35 * Return the logical data store type.
37 * @return Logical data store type. Guaranteed to be non-null.
39 public @Nonnull LogicalDatastoreType getDatastoreType() {
44 * Return the {@link InstanceIdentifier} of the root node.
46 * @return Instance identifier corresponding to the root node.
48 public @Nonnull InstanceIdentifier<T> getRootIdentifier() {
49 return rootIdentifier;
53 public boolean contains(final DataTreeIdentifier<?> other) {
54 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
58 public int hashCode() {
61 result = prime * result + datastoreType.hashCode();
62 result = prime * result + rootIdentifier.hashCode();
67 public boolean equals(final Object obj) {
71 if (!(obj instanceof DataTreeIdentifier)) {
74 final DataTreeIdentifier<?> other = (DataTreeIdentifier<?>) obj;
75 if (datastoreType != other.datastoreType) {
78 return rootIdentifier.equals(other.rootIdentifier);
82 public String toString() {
83 return getClass().getSimpleName() + "{datastoreType = " + datastoreType + ", rootIdentifier = "
84 + rootIdentifier + "}";