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.dom.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.common.api.LogicalDatastorePath;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 * A DOM version of {@link LogicalDatastorePath}. Uses {@link YangInstanceIdentifier} for path addressing.
23 public final class DOMDataTreeIdentifier implements LogicalDatastorePath<DOMDataTreeIdentifier, YangInstanceIdentifier>,
24 Comparable<DOMDataTreeIdentifier> {
26 private static final long serialVersionUID = 1L;
28 private final YangInstanceIdentifier rootIdentifier;
29 private final LogicalDatastoreType datastoreType;
32 * Default constructor.
34 * @param datastore {@link LogicalDatastoreType} of this identifier
35 * @param path {@link YangInstanceIdentifier} path of this identifier
36 * @throws NullPointerException if any argument is {@code null}
37 * @deprecated Use {@link #of(LogicalDatastoreType, YangInstanceIdentifier)} instead
39 @Deprecated(since = "13.0.0", forRemoval = true)
40 public DOMDataTreeIdentifier(final LogicalDatastoreType datastore, final YangInstanceIdentifier path) {
41 datastoreType = requireNonNull(datastore);
42 rootIdentifier = requireNonNull(path);
46 * Create a new {@link DOMDataTreeIdentifier} with specified datastore and path.
48 * @param datastore {@link LogicalDatastoreType} of this identifier
49 * @param path {@link YangInstanceIdentifier} path of this identifier
50 * @throws NullPointerException if any argument is {@code null}
52 public static DOMDataTreeIdentifier of(final LogicalDatastoreType datastore, final YangInstanceIdentifier path) {
53 return new DOMDataTreeIdentifier(datastore, path);
57 public LogicalDatastoreType datastore() {
62 * Return the logical data store type.
64 * @return Logical data store type. Guaranteed to be non-null.
65 * @deprecated Use {@link #datastore()} instead
67 @Deprecated(since = "13.0.0", forRemoval = true)
68 public LogicalDatastoreType getDatastoreType() {
73 public YangInstanceIdentifier path() {
74 return rootIdentifier;
78 * Return the {@link YangInstanceIdentifier} of the root node.
80 * @return Instance identifier corresponding to the root node.
81 * @deprecated Use {@link #path()} instead
83 @Deprecated(since = "13.0.0", forRemoval = true)
84 public YangInstanceIdentifier getRootIdentifier() {
88 public DOMDataTreeIdentifier toOptimized() {
89 final var opt = rootIdentifier.toOptimized();
90 return opt == rootIdentifier ? this : DOMDataTreeIdentifier.of(datastoreType, opt);
94 public int compareTo(final DOMDataTreeIdentifier domDataTreeIdentifier) {
95 int cmp = datastoreType.compareTo(domDataTreeIdentifier.datastoreType);
100 final var myIter = rootIdentifier.getPathArguments().iterator();
101 final var otherIter = domDataTreeIdentifier.rootIdentifier.getPathArguments().iterator();
103 while (myIter.hasNext()) {
104 if (!otherIter.hasNext()) {
108 final var myPathArg = myIter.next();
109 final var otherPathArg = otherIter.next();
110 cmp = myPathArg.compareTo(otherPathArg);
116 return otherIter.hasNext() ? -1 : 0;
120 public int hashCode() {
121 return datastoreType.hashCode() * 31 + rootIdentifier.hashCode();
125 public boolean equals(final @Nullable Object obj) {
126 return this == obj || obj instanceof DOMDataTreeIdentifier other && datastoreType == other.datastoreType
127 && rootIdentifier.equals(other.rootIdentifier);
131 public String toString() {
132 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();
136 Object writeReplace() {
137 return new DTIv1(this);