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
9 package org.opendaylight.mdsal.dom.api;
11 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.Preconditions;
15 import java.io.Serializable;
16 import java.util.Iterator;
17 import javax.annotation.Nonnull;
18 import org.opendaylight.yangtools.concepts.Immutable;
19 import org.opendaylight.yangtools.concepts.Path;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
24 * A unique identifier for a particular subtree. It is composed of the logical
25 * data store type and the instance identifier of the root node.
27 public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeIdentifier>, Serializable,
28 Comparable<DOMDataTreeIdentifier> {
29 private static final long serialVersionUID = 1L;
31 private final YangInstanceIdentifier rootIdentifier;
32 private final LogicalDatastoreType datastoreType;
34 public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType, final YangInstanceIdentifier rootIdentifier) {
35 this.datastoreType = Preconditions.checkNotNull(datastoreType);
36 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
40 * Return the logical data store type.
42 * @return Logical data store type. Guaranteed to be non-null.
44 public @Nonnull LogicalDatastoreType getDatastoreType() {
49 * Return the {@link YangInstanceIdentifier} of the root node.
51 * @return Instance identifier corresponding to the root node.
53 public @Nonnull YangInstanceIdentifier getRootIdentifier() {
54 return rootIdentifier;
58 public boolean contains(final DOMDataTreeIdentifier other) {
59 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
62 public DOMDataTreeIdentifier toOptimized() {
63 final YangInstanceIdentifier opt = rootIdentifier.toOptimized();
64 return opt == rootIdentifier ? this : new DOMDataTreeIdentifier(datastoreType, opt);
68 public int hashCode() {
71 result = prime * result + datastoreType.hashCode();
72 result = prime * result + rootIdentifier.hashCode();
77 public boolean equals(final Object obj) {
81 if (!(obj instanceof DOMDataTreeIdentifier)) {
84 DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
85 if (datastoreType != other.datastoreType) {
88 return rootIdentifier.equals(other.rootIdentifier);
92 public int compareTo(final DOMDataTreeIdentifier o) {
93 int i = datastoreType.compareTo(o.datastoreType);
98 final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
99 final Iterator<PathArgument> oi = o.rootIdentifier.getPathArguments().iterator();
101 while (mi.hasNext()) {
106 final PathArgument ma = mi.next();
107 final PathArgument oa = oi.next();
108 i = ma.compareTo(oa);
114 return oi.hasNext() ? -1 : 0;
118 public String toString() {
119 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();