*
* @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.
public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentifier>, Immutable, Serializable {
}
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