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 static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
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 HierarchicalIdentifier<DataTreeIdentifier<?>> {
25 private static final long serialVersionUID = 1L;
27 private final @NonNull InstanceIdentifier<T> rootIdentifier;
28 private final @NonNull LogicalDatastoreType datastoreType;
30 private DataTreeIdentifier(final @NonNull LogicalDatastoreType datastoreType,
31 final @NonNull InstanceIdentifier<T> rootIdentifier) {
32 this.datastoreType = requireNonNull(datastoreType);
33 this.rootIdentifier = requireNonNull(rootIdentifier);
36 public static <T extends DataObject> @NonNull DataTreeIdentifier<T> create(
37 final @NonNull LogicalDatastoreType datastoreType, final @NonNull InstanceIdentifier<T> rootIdentifier) {
38 return new DataTreeIdentifier<>(datastoreType, rootIdentifier);
42 * Return the logical data store type.
44 * @return Logical data store type. Guaranteed to be non-null.
46 public @NonNull LogicalDatastoreType getDatastoreType() {
51 * Return the {@link InstanceIdentifier} of the root node.
53 * @return Instance identifier corresponding to the root node.
55 public @NonNull InstanceIdentifier<T> getRootIdentifier() {
56 return rootIdentifier;
60 public boolean contains(final DataTreeIdentifier<?> other) {
61 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
65 public int hashCode() {
66 return datastoreType.hashCode() * 31 + rootIdentifier.hashCode();
70 public boolean equals(final Object obj) {
71 return this == obj || obj instanceof DataTreeIdentifier<?> other && datastoreType == other.datastoreType
72 && rootIdentifier.equals(other.rootIdentifier);
76 public String toString() {
77 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();