* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.mdsal.dom.api;
-import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-import java.io.Serializable;
import java.util.Iterator;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.concepts.Path;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
- * A unique identifier for a particular subtree. It is composed of the logical
- * data store type and the instance identifier of the root node.
+ * A unique identifier for a particular subtree. It is composed of the logical data store type and the instance
+ * identifier of the root node.
*/
-public final class DOMDataTreeIdentifier implements Immutable, Path<DOMDataTreeIdentifier>, Serializable, Comparable<DOMDataTreeIdentifier> {
+@NonNullByDefault
+public final class DOMDataTreeIdentifier implements HierarchicalIdentifier<DOMDataTreeIdentifier>,
+ Comparable<DOMDataTreeIdentifier> {
private static final long serialVersionUID = 1L;
+
private final YangInstanceIdentifier rootIdentifier;
private final LogicalDatastoreType datastoreType;
- public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType, final YangInstanceIdentifier rootIdentifier) {
- this.datastoreType = Preconditions.checkNotNull(datastoreType);
- this.rootIdentifier = Preconditions.checkNotNull(rootIdentifier);
+ public DOMDataTreeIdentifier(final LogicalDatastoreType datastoreType,
+ final YangInstanceIdentifier rootIdentifier) {
+ this.datastoreType = requireNonNull(datastoreType);
+ this.rootIdentifier = requireNonNull(rootIdentifier);
}
/**
*
* @return Logical data store type. Guaranteed to be non-null.
*/
- public @Nonnull LogicalDatastoreType getDatastoreType() {
+ public LogicalDatastoreType getDatastoreType() {
return datastoreType;
}
*
* @return Instance identifier corresponding to the root node.
*/
- public @Nonnull YangInstanceIdentifier getRootIdentifier() {
+ public YangInstanceIdentifier getRootIdentifier() {
return rootIdentifier;
}
return datastoreType == other.datastoreType && rootIdentifier.contains(other.rootIdentifier);
}
+ public DOMDataTreeIdentifier toOptimized() {
+ final YangInstanceIdentifier opt = rootIdentifier.toOptimized();
+ return opt == rootIdentifier ? this : new DOMDataTreeIdentifier(datastoreType, opt);
+ }
+
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + datastoreType.hashCode();
- result = prime * result + rootIdentifier.hashCode();
- return result;
+ return datastoreType.hashCode() * 31 + rootIdentifier.hashCode();
}
@Override
- public boolean equals(final Object obj) {
+ public boolean equals(final @Nullable Object obj) {
if (this == obj) {
return true;
}
return false;
}
DOMDataTreeIdentifier other = (DOMDataTreeIdentifier) obj;
- if (datastoreType != other.datastoreType) {
- return false;
- }
- return rootIdentifier.equals(other.rootIdentifier);
+ return datastoreType == other.datastoreType && rootIdentifier.equals(other.rootIdentifier);
}
@Override
- public int compareTo(final DOMDataTreeIdentifier o) {
- int i = datastoreType.compareTo(o.datastoreType);
- if (i != 0) {
- return i;
+ public int compareTo(final DOMDataTreeIdentifier domDataTreeIdentifier) {
+ int cmp = datastoreType.compareTo(domDataTreeIdentifier.datastoreType);
+ if (cmp != 0) {
+ return cmp;
}
- final Iterator<PathArgument> mi = rootIdentifier.getPathArguments().iterator();
- final Iterator<PathArgument> oi = o.rootIdentifier.getPathArguments().iterator();
+ final Iterator<PathArgument> myIter = rootIdentifier.getPathArguments().iterator();
+ final Iterator<PathArgument> otherIter = domDataTreeIdentifier.rootIdentifier.getPathArguments().iterator();
- while (mi.hasNext()) {
- if (!oi.hasNext()) {
+ while (myIter.hasNext()) {
+ if (!otherIter.hasNext()) {
return 1;
}
- final PathArgument ma = mi.next();
- final PathArgument oa = oi.next();
- i = ma.compareTo(oa);
- if (i != 0) {
- return i;
+ final PathArgument myPathArg = myIter.next();
+ final PathArgument otherPathArg = otherIter.next();
+ cmp = myPathArg.compareTo(otherPathArg);
+ if (cmp != 0) {
+ return cmp;
}
}
- return oi.hasNext() ? -1 : 0;
+ return otherIter.hasNext() ? -1 : 0;
}
@Override