2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.mdsal.binding.javav2.api;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import java.io.Serializable;
15 import java.util.Objects;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
18 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.concepts.Path;
24 * A unique identifier for a particular subtree. It's composed of the logical
25 * data store type and the instance identifier of the root node.
28 public final class DataTreeIdentifier<T extends TreeNode> implements Immutable,
29 Path<DataTreeIdentifier<?>>, Serializable {
31 private static final long serialVersionUID = 1L;
32 private final InstanceIdentifier<T> rootIdentifier;
33 private final LogicalDatastoreType datastoreType;
35 private DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> rootIdentifier) {
36 this.datastoreType = requireNonNull(datastoreType);
37 this.rootIdentifier = requireNonNull(rootIdentifier);
40 public static <T extends TreeNode> DataTreeIdentifier<T> create(final LogicalDatastoreType datastoreType,
41 final InstanceIdentifier<T> rootIdentifier) {
42 return new DataTreeIdentifier<>(datastoreType, rootIdentifier);
46 * Return the logical data store type.
48 * @return Logical data store type. Guaranteed to be non-null.
51 public LogicalDatastoreType getDatastoreType() {
56 * Return the {@link InstanceIdentifier} of the root node.
58 * @return Instance identifier corresponding to the root node.
61 public InstanceIdentifier<T> getRootIdentifier() {
62 return rootIdentifier;
66 * Checks whether this identifier contains some other.
67 * @param other Other path, may not be null.
71 public boolean contains(@Nonnull final DataTreeIdentifier<?> other) {
72 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
76 public boolean equals(final Object obj) {
80 if (!(obj instanceof DataTreeIdentifier)) {
83 final DataTreeIdentifier<?> other = (DataTreeIdentifier<?>) obj;
84 if (datastoreType != other.datastoreType) {
87 return rootIdentifier.equals(other.rootIdentifier);
91 public int hashCode() {
92 return Objects.hash(rootIdentifier, datastoreType);