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.LogicalDatastorePath;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 * A Binding version of {@link LogicalDatastorePath}. Uses {@link InstanceIdentifier} for path addressing.
22 public final class DataTreeIdentifier<T extends DataObject>
23 implements LogicalDatastorePath<@NonNull DataTreeIdentifier<?>, @NonNull InstanceIdentifier<?>> {
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 datastore,
31 final @NonNull InstanceIdentifier<T> path) {
32 datastoreType = requireNonNull(datastore);
33 rootIdentifier = requireNonNull(path);
37 * Create a new {@link DataTreeIdentifier} with specified datastore and path.
39 * @param <T> target {@link DataObject} type
40 * @param datastore {@link LogicalDatastoreType} of this identifier
41 * @param path {@link InstanceIdentifier} path of this identifier
42 * @throws NullPointerException if any argument is {@code null}
44 public static <T extends DataObject> @NonNull DataTreeIdentifier<T> of(
45 final @NonNull LogicalDatastoreType datastore, final @NonNull InstanceIdentifier<T> path) {
46 return new DataTreeIdentifier<>(datastore, path);
50 * Create a new {@link DataTreeIdentifier} with specified datastore and path.
52 * @param <T> target {@link DataObject} type
53 * @param datastore {@link LogicalDatastoreType} of this identifier
54 * @param path {@link InstanceIdentifier} path of this identifier
55 * @throws NullPointerException if any argument is {@code null}
56 * @deprecated Use {@link #of(LogicalDatastoreType, InstanceIdentifier)} instead
58 @Deprecated(since = "13.0.0", forRemoval = true)
59 public static <T extends DataObject> @NonNull DataTreeIdentifier<T> create(
60 final @NonNull LogicalDatastoreType datastore, final @NonNull InstanceIdentifier<T> path) {
61 return of(datastore, path);
65 public LogicalDatastoreType datastore() {
70 * Return the logical data store type.
72 * @return Logical data store type. Guaranteed to be non-null.
73 * @deprecated Use {@link #datastore()} instead
75 @Deprecated(since = "13.0.0", forRemoval = true)
76 public @NonNull LogicalDatastoreType getDatastoreType() {
81 public InstanceIdentifier<T> path() {
82 return rootIdentifier;
86 * Return the {@link InstanceIdentifier} of the root node.
88 * @return Instance identifier corresponding to the root node.
89 * @deprecated Use {@link #path()} instead
91 @Deprecated(since = "13.0.0", forRemoval = true)
92 public @NonNull InstanceIdentifier<T> getRootIdentifier() {
97 public int hashCode() {
98 return datastoreType.hashCode() * 31 + rootIdentifier.hashCode();
102 public boolean equals(final Object obj) {
103 return this == obj || obj instanceof DataTreeIdentifier<?> other && datastoreType == other.datastoreType
104 && rootIdentifier.equals(other.rootIdentifier);
108 public String toString() {
109 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();
113 Object writeReplace() {
114 return new DTIv1(this);