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 com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import java.io.Serializable;
14 import java.util.Objects;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
17 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yangtools.concepts.Immutable;
20 import org.opendaylight.yangtools.concepts.Path;
23 * A unique identifier for a particular subtree. It's composed of the logical
24 * data store type and the instance identifier of the root node.
27 public final class DataTreeIdentifier<T extends TreeNode> implements Immutable,
28 Path<DataTreeIdentifier<?>>, Serializable {
30 private static final long serialVersionUID = 1L;
31 private final InstanceIdentifier<T> rootIdentifier;
32 private final LogicalDatastoreType datastoreType;
34 private DataTreeIdentifier(final LogicalDatastoreType datastoreType, final InstanceIdentifier<T> rootIdentifier) {
35 this.datastoreType = Preconditions.checkNotNull(datastoreType);
36 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
39 public static <T extends TreeNode> DataTreeIdentifier<T> create(final LogicalDatastoreType datastoreType,
40 final InstanceIdentifier<T> rootIdentifier) {
41 return new DataTreeIdentifier<>(datastoreType, rootIdentifier);
45 * Return the logical data store type.
47 * @return Logical data store type. Guaranteed to be non-null.
50 public LogicalDatastoreType getDatastoreType() {
55 * Return the {@link InstanceIdentifier} of the root node.
57 * @return Instance identifier corresponding to the root node.
60 public InstanceIdentifier<T> getRootIdentifier() {
61 return rootIdentifier;
65 * Checks whether this identifier contains some other.
66 * @param other Other path, may not be null.
70 public boolean contains(@Nonnull final DataTreeIdentifier<?> other) {
71 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
75 public boolean equals(final Object obj) {
79 if (!(obj instanceof DataTreeIdentifier)) {
82 final DataTreeIdentifier<?> other = (DataTreeIdentifier<?>) obj;
83 if (datastoreType != other.datastoreType) {
86 return rootIdentifier.equals(other.rootIdentifier);
90 public int hashCode() {
91 return Objects.hash(rootIdentifier, datastoreType);