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, Comparable<DOMDataTreeIdentifier> {
28 private static final long serialVersionUID = 1L;
29 private final YangInstanceIdentifier rootIdentifier;
30 private final LogicalDatastoreType datastoreType;
32 public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType, final YangInstanceIdentifier rootIdentifier) {
33 this.datastoreType = Preconditions.checkNotNull(datastoreType);
34 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
38 * Return the logical data store type.
40 * @return Logical data store type. Guaranteed to be non-null.
42 public @Nonnull LogicalDatastoreType getDatastoreType() {
47 * Return the {@link YangInstanceIdentifier} of the root node.
49 * @return Instance identifier corresponding to the root node.
51 public @Nonnull YangInstanceIdentifier getRootIdentifier() {
52 return rootIdentifier;
56 public boolean contains(final DOMDataTreeIdentifier other) {
57 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
61 public int hashCode() {
64 result = prime * result + datastoreType.hashCode();
65 result = prime * result + rootIdentifier.hashCode();
70 public boolean equals(final Object obj) {
74 if (!(obj instanceof DOMDataTreeIdentifier)) {
77 DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
78 if (datastoreType != other.datastoreType) {
81 return rootIdentifier.equals(other.rootIdentifier);
85 public int compareTo(final DOMDataTreeIdentifier o) {
86 int i = datastoreType.compareTo(o.datastoreType);
91 final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
92 final Iterator<PathArgument> oi = o.rootIdentifier.getPathArguments().iterator();
94 while (mi.hasNext()) {
99 final PathArgument ma = mi.next();
100 final PathArgument oa = oi.next();
101 i = ma.compareTo(oa);
107 return oi.hasNext() ? -1 : 0;
111 public String toString() {
112 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();