X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fapi%2FYangInstanceIdentifier.java;h=a7539e9167f08cb0917ba2b532e12f22e925194e;hb=ce2dacd877878d47df97c524f2307f0d2b393163;hp=4632acbf67ef4ef600187bf535f59ffb860c192a;hpb=4dfeef142234a90f7656d1102a3eca1a476e9b14;p=yangtools.git diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java index 4632acbf67..a7539e9167 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java @@ -12,6 +12,7 @@ import static com.google.common.base.Verify.verify; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; +import com.google.common.base.VerifyException; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -44,7 +45,6 @@ import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.concepts.Path; import org.opendaylight.yangtools.util.HashCodeBuilder; import org.opendaylight.yangtools.util.ImmutableOffsetMap; -import org.opendaylight.yangtools.util.SharedSingletonMap; import org.opendaylight.yangtools.util.SingletonSet; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -54,36 +54,29 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; * Unique identifier of a particular node instance in the data tree. * *

- * Java representation of YANG Built-in type instance-identifier, - * which conceptually is XPath expression minimized to uniquely identify element - * in data tree which conforms to constraints maintained by YANG Model, + * Java representation of YANG Built-in type {@code instance-identifier}, which conceptually is XPath expression + * minimized to uniquely identify element in data tree which conforms to constraints maintained by YANG Model, * effectively this makes Instance Identifier a path to element in data tree. * *

- * Constraints put in YANG specification on instance-identifier allowed it to be - * effectively represented in Java and it's evaluation does not require - * full-blown XPath processor. + * Constraints put in YANG specification on instance-identifier allowed it to be effectively represented in Java and its + * evaluation does not require a full-blown XPath processor. * - *

- *

Path Arguments

- * Path to the node represented in instance identifier consists of - * {@link PathArgument} which carries necessary information to uniquely identify - * node on particular level in the subtree. + *

Path Arguments

+ * Path to the node represented in instance identifier consists of {@link PathArgument} which carries necessary + * information to uniquely identify node on particular level in the subtree. * * * * @see RFC6020 */ -// FIXME: 4.0.0: this concept needs to be moved to yang-common, as parser components need the ability to refer +// FIXME: 7.0.0: this concept needs to be moved to yang-common, as parser components need the ability to refer // to data nodes -- most notably XPath expressions and {@code default} statement arguments need to be able // to represent these. public abstract class YangInstanceIdentifier implements Path, Immutable, Serializable { @@ -129,7 +122,6 @@ public abstract class YangInstanceIdentifier implements Path values() { return SingletonSet.of(value); @@ -652,6 +663,11 @@ public abstract class YangInstanceIdentifier implements Path values() { return keyValues.values(); @@ -723,12 +739,6 @@ public abstract class YangInstanceIdentifier implements Path keyValues) { - return of(node, keyValues.getEntry()); - } - private static @NonNull NodeIdentifierWithPredicates of(final Map keyValues, final QName node) { return of(node, keyValues.entrySet().iterator().next()); } @@ -738,7 +748,6 @@ public abstract class YangInstanceIdentifier implements Path> entrySet(); /** @@ -746,15 +755,22 @@ public abstract class YangInstanceIdentifier implements Path keySet(); + /** + * Determine whether a particular predicate key is present. + * + * @param key Predicate key + * @return True if the predicate is present, false otherwise + * @throws NullPointerException if {@code key} is null + */ + public abstract boolean containsKey(QName key); + /** * Return the predicate values in the iteration order of {@link #entrySet()}. * * @return Predicate values. */ - @Beta public abstract @NonNull Collection values(); @Beta @@ -772,22 +788,14 @@ public abstract class YangInstanceIdentifier implements Pathyangtools-dev for migration - * guidelines. Callers are strongly encouraged to explore {@link #entrySet()}, {@link #size()}, - * {@link #values()} and {@link #keySet()} as an alternative. */ @Beta - @Deprecated - // FIXME: 4.0.0: evaluate the real usefulness of this. The problem here is Map.hashCode() and Map.equals(), - // which limits our options. public abstract @NonNull Map asMap(); @Override @@ -832,23 +840,20 @@ public abstract class YangInstanceIdentifier implements Path extends AbstractPathArgument { private static final long serialVersionUID = -3637456085341738431L; - private final T value; + private final @NonNull T value; public NodeWithValue(final QName node, final T value) { super(node); - this.value = value; + this.value = requireNonNull(value); } - public T getValue() { + public @NonNull T getValue() { return value; } @Override protected int hashCodeImpl() { - final int prime = 31; - int result = super.hashCodeImpl(); - result = prime * result + YangInstanceIdentifier.hashCode(value); - return result; + return 31 * super.hashCodeImpl() + YangInstanceIdentifier.hashCode(value); } @Override @@ -1075,7 +1080,6 @@ public abstract class YangInstanceIdentifier implements Path args); /** @@ -1085,7 +1089,6 @@ public abstract class YangInstanceIdentifier implements Path