Rework NormalizedNodeStreamWriter
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangInstanceIdentifier.java
index 6f2c49cfa3d28a8d8d8f54c10c0e3a56fdfaf135..bfbc5989253ade0e4be8a6d1f53c3f9509184726 100644 (file)
@@ -15,9 +15,11 @@ import com.google.common.annotations.Beta;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.Serializable;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
@@ -76,10 +78,15 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
  *
  * @see <a href="http://tools.ietf.org/html/rfc6020#section-9.13">RFC6020</a>
  */
+// FIXME: 3.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.
+     * An empty {@link YangInstanceIdentifier}. It corresponds to the path of the conceptual root of the YANG namespace.
      */
     public static final YangInstanceIdentifier EMPTY = FixedYangInstanceIdentifier.EMPTY_INSTANCE;
 
@@ -525,15 +532,29 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
 
         private final Map<QName, Object> keyValues;
 
+        public NodeIdentifierWithPredicates(final QName node) {
+            super(node);
+            this.keyValues = ImmutableMap.of();
+        }
+
         public NodeIdentifierWithPredicates(final QName node, final Map<QName, Object> keyValues) {
             super(node);
             // Retains ImmutableMap for empty maps. For larger sizes uses a shared key set.
             this.keyValues = ImmutableOffsetMap.unorderedCopyOf(keyValues);
         }
 
-        public NodeIdentifierWithPredicates(final QName node, final QName key, final Object value) {
+        public NodeIdentifierWithPredicates(final QName node, final ImmutableOffsetMap<QName, Object> keyValues) {
+            super(node);
+            this.keyValues = requireNonNull(keyValues);
+        }
+
+        public NodeIdentifierWithPredicates(final QName node, final SharedSingletonMap<QName, Object> keyValues) {
             super(node);
-            this.keyValues = SharedSingletonMap.unorderedOf(key, value);
+            this.keyValues = requireNonNull(keyValues);
+        }
+
+        public NodeIdentifierWithPredicates(final QName node, final QName key, final Object value) {
+            this(node, SharedSingletonMap.unorderedOf(key, value));
         }
 
         public Map<QName, Object> getKeyValues() {