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.mdsal.binding.api;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.Preconditions;
12 import java.io.Serializable;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.concepts.Path;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 * A unique identifier for a particular subtree. It is composed of the logical
22 * data store type and the instance identifier of the root node.
24 public final class DataTreeIdentifier<T extends DataObject> implements Immutable,
25 Path<DataTreeIdentifier<?>>, Serializable {
26 private static final long serialVersionUID = 1L;
27 private final InstanceIdentifier<T> rootIdentifier;
28 private final LogicalDatastoreType datastoreType;
30 private DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> rootIdentifier) {
31 this.datastoreType = Preconditions.checkNotNull(datastoreType);
32 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
35 public static <T extends DataObject> DataTreeIdentifier<T> create(final LogicalDatastoreType datastoreType,
36 final InstanceIdentifier<T> rootIdentifier) {
37 return new DataTreeIdentifier<>(datastoreType, rootIdentifier);
41 * Return the logical data store type.
43 * @return Logical data store type. Guaranteed to be non-null.
45 public @NonNull LogicalDatastoreType getDatastoreType() {
50 * Return the {@link InstanceIdentifier} of the root node.
52 * @return Instance identifier corresponding to the root node.
54 public @NonNull InstanceIdentifier<T> getRootIdentifier() {
55 return rootIdentifier;
59 public boolean contains(final DataTreeIdentifier<?> other) {
60 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
64 public int hashCode() {
67 result = prime * result + datastoreType.hashCode();
68 result = prime * result + rootIdentifier.hashCode();
73 public boolean equals(final Object obj) {
77 if (!(obj instanceof DataTreeIdentifier)) {
80 final DataTreeIdentifier<?> other = (DataTreeIdentifier<?>) obj;
81 if (datastoreType != other.datastoreType) {
84 return rootIdentifier.equals(other.rootIdentifier);
88 public String toString() {
89 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();