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 com.google.common.base.MoreObjects;
12 import com.google.common.base.Preconditions;
13 import java.io.Serializable;
14 import java.util.Iterator;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.yangtools.concepts.Immutable;
18 import org.opendaylight.yangtools.concepts.Path;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
23 * A unique identifier for a particular subtree. It is composed of the logical
24 * data store type and the instance identifier of the root node.
26 public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeIdentifier>, Serializable, Comparable<DOMDataTreeIdentifier> {
27 private static final long serialVersionUID = 1L;
28 private final YangInstanceIdentifier rootIdentifier;
29 private final LogicalDatastoreType datastoreType;
31 public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType, final YangInstanceIdentifier rootIdentifier) {
32 this.datastoreType = Preconditions.checkNotNull(datastoreType);
33 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
37 * Return the logical data store type.
39 * @return Logical data store type. Guaranteed to be non-null.
41 public @Nonnull LogicalDatastoreType getDatastoreType() {
46 * Return the {@link YangInstanceIdentifier} of the root node.
48 * @return Instance identifier corresponding to the root node.
50 public @Nonnull YangInstanceIdentifier getRootIdentifier() {
51 return rootIdentifier;
55 public boolean contains(final DOMDataTreeIdentifier other) {
56 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
60 public int hashCode() {
63 result = prime * result + datastoreType.hashCode();
64 result = prime * result + rootIdentifier.hashCode();
69 public boolean equals(final Object obj) {
73 if (!(obj instanceof DOMDataTreeIdentifier)) {
76 DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
77 if (datastoreType != other.datastoreType) {
80 return rootIdentifier.equals(other.rootIdentifier);
84 public int compareTo(final DOMDataTreeIdentifier o) {
85 int i = datastoreType.compareTo(o.datastoreType);
90 final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
91 final Iterator<PathArgument> oi = o.rootIdentifier.getPathArguments().iterator();
93 while (mi.hasNext()) {
98 final PathArgument ma = mi.next();
99 final PathArgument oa = oi.next();
100 i = ma.compareTo(oa);
106 return oi.hasNext() ? -1 : 0;
110 public String toString() {
111 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();