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.controller.md.sal.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,
27 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,
33 final YangInstanceIdentifier rootIdentifier) {
34 this.datastoreType = Preconditions.checkNotNull(datastoreType);
35 this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
39 * Return the logical data store type.
41 * @return Logical data store type. Guaranteed to be non-null.
43 public @Nonnull LogicalDatastoreType getDatastoreType() {
48 * Return the {@link YangInstanceIdentifier} of the root node.
50 * @return Instance identifier corresponding to the root node.
52 public @Nonnull YangInstanceIdentifier getRootIdentifier() {
53 return rootIdentifier;
57 public boolean contains(final DOMDataTreeIdentifier other) {
58 return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
62 public int hashCode() {
65 result = prime * result + datastoreType.hashCode();
66 result = prime * result + rootIdentifier.hashCode();
71 public boolean equals(final Object obj) {
75 if (!(obj instanceof DOMDataTreeIdentifier)) {
78 DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
79 if (datastoreType != other.datastoreType) {
82 return rootIdentifier.equals(other.rootIdentifier);
86 public int compareTo(final DOMDataTreeIdentifier obj) {
87 int cmp = datastoreType.compareTo(obj.datastoreType);
92 final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
93 final Iterator<PathArgument> oi = obj.rootIdentifier.getPathArguments().iterator();
95 while (mi.hasNext()) {
100 final PathArgument ma = mi.next();
101 final PathArgument oa = oi.next();
102 cmp = ma.compareTo(oa);
108 return oi.hasNext() ? -1 : 0;
112 public String toString() {
113 return MoreObjects.toStringHelper(this).add("datastore", datastoreType).add("root", rootIdentifier).toString();