Push out YangInstanceIdentifier FIXMEs
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangInstanceIdentifier.java
index 02dba8a71ad9e8618f5c3a9e9a195f0050a152ce..ffcf3f34670fd933e5530496f5ada13cbb347b1b 100644 (file)
@@ -83,21 +83,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
  *
  * @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;
@@ -128,7 +117,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
 
     /**
      * 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.
      */
@@ -147,7 +136,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
      * 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();
 
@@ -502,7 +491,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
         }
 
         protected int hashCodeImpl() {
-            return 31 + getNodeType().hashCode();
+            return nodeType.hashCode();
         }
 
         @Override
@@ -583,7 +572,8 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
      * 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;
@@ -597,7 +587,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
 
             @Override
             public SingletonSet<Entry<QName, Object>> entrySet() {
-                return SingletonSet.of(new SimpleImmutableEntry<>(key, value));
+                return SingletonSet.of(singleEntry());
             }
 
             @Override
@@ -605,6 +595,11 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
                 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);
@@ -620,6 +615,16 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
                 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;
@@ -652,6 +657,11 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
                 return keyValues.keySet();
             }
 
+            @Override
+            public boolean containsKey(final QName qname) {
+                return keyValues.containsKey(requireNonNull(qname));
+            }
+
             @Override
             public Collection<Object> values() {
                 return keyValues.values();
@@ -749,6 +759,16 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
         @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()}.
          *
@@ -786,7 +806,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
          */
         @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();
 
@@ -845,10 +865,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
 
         @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