*
* @see <a href="http://tools.ietf.org/html/rfc6020#section-9.13">RFC6020</a>
*/
-// FIXME: 4.0.0: this concept needs to be moved to yang-common, as parser components need the ability to refer
+// FIXME: 6.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.
-// FIXME: FixedYangInstanceIdentifier needs YangInstanceIdentifier initialized, but that includes initializing
-// this field. Figure out a way out of this pickle.
-@SuppressFBWarnings("IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION")
public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentifier>, Immutable, Serializable {
- /**
- * An empty {@link YangInstanceIdentifier}. It corresponds to the path of the conceptual root of the YANG namespace.
- *
- * @deprecated Use {@link #empty()} instead.
- */
- @Deprecated(forRemoval = true)
- public static final @NonNull YangInstanceIdentifier EMPTY = FixedYangInstanceIdentifier.EMPTY_INSTANCE;
-
private static final AtomicReferenceFieldUpdater<YangInstanceIdentifier, String> TOSTRINGCACHE_UPDATER =
AtomicReferenceFieldUpdater.newUpdater(YangInstanceIdentifier.class, String.class, "toStringCache");
private static final long serialVersionUID = 4L;
/**
* Check if this instance identifier has empty path arguments, e.g. it is
- * empty and corresponds to {@link #EMPTY}.
+ * empty and corresponds to {@link #empty()}.
*
* @return True if this instance identifier is empty, false otherwise.
*/
* Return the conceptual parent {@link YangInstanceIdentifier}, which has
* one item less in {@link #getPathArguments()}.
*
- * @return Parent {@link YangInstanceIdentifier}, or null if this object is {@link #EMPTY}.
+ * @return Parent {@link YangInstanceIdentifier}, or null if this object is {@link #empty()}.
*/
public abstract @Nullable YangInstanceIdentifier getParent();
}
protected int hashCodeImpl() {
- return 31 + getNodeType().hashCode();
+ return nodeType.hashCode();
}
@Override
* overall data tree.
*/
public abstract static class NodeIdentifierWithPredicates extends AbstractPathArgument {
- private static final class Singleton extends NodeIdentifierWithPredicates {
+ @Beta
+ public static final class Singleton extends NodeIdentifierWithPredicates {
private static final long serialVersionUID = 1L;
private final @NonNull QName key;
@Override
public SingletonSet<Entry<QName, Object>> entrySet() {
- return SingletonSet.of(new SimpleImmutableEntry<>(key, value));
+ return SingletonSet.of(singleEntry());
}
@Override
return SingletonSet.of(key);
}
+ @Override
+ public boolean containsKey(final QName qname) {
+ return key.equals(requireNonNull(qname));
+ }
+
@Override
public SingletonSet<Object> values() {
return SingletonSet.of(value);
return ImmutableMap.of(key, value);
}
+ /**
+ * Return the single entry contained in this object. This is equivalent to
+ * {@code entrySet().iterator().next()}.
+ *
+ * @return A single entry.
+ */
+ public @NonNull Entry<QName, Object> singleEntry() {
+ return new SimpleImmutableEntry<>(key, value);
+ }
+
@Override
boolean equalMapping(final NodeIdentifierWithPredicates other) {
final Singleton single = (Singleton) other;
return keyValues.keySet();
}
+ @Override
+ public boolean containsKey(final QName qname) {
+ return keyValues.containsKey(requireNonNull(qname));
+ }
+
@Override
public Collection<Object> values() {
return keyValues.values();
@Beta
public abstract @NonNull Set<QName> 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
+ */
+ @Beta
+ public abstract boolean containsKey(QName key);
+
/**
* Return the predicate values in the iteration order of {@link #entrySet()}.
*
*/
@Beta
@Deprecated
- // FIXME: 4.0.0: evaluate the real usefulness of this. The problem here is Map.hashCode() and Map.equals(),
+ // FIXME: 6.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<QName, Object> asMap();
@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