Add YangInstanceIdentifier.create(PathArgument) 08/90708/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Jun 2020 14:26:39 +0000 (16:26 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 25 Jun 2020 18:09:05 +0000 (20:09 +0200)
This is a short-circuit version of the varargs create(), which is
slighly faster.

Change-Id: Id6b6ae327cd8e5d63108c766532dd8ab91188637
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 224b2fe77f786ac4c524ee2ec4d581b3914af92b)

yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/FixedYangInstanceIdentifier.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java

index 7614b96ead5cbed9d8c3eb98e1777976f9f10d9d..bf6ba5a41310ca4b1c4467aac8325c4bfc0d16a9 100644 (file)
@@ -25,7 +25,7 @@ final class FixedYangInstanceIdentifier extends YangInstanceIdentifier implement
     private final ImmutableList<PathArgument> path;
     private transient volatile YangInstanceIdentifier parent;
 
-    private FixedYangInstanceIdentifier(final ImmutableList<PathArgument> path, final int hash) {
+    FixedYangInstanceIdentifier(final ImmutableList<PathArgument> path, final int hash) {
         super(hash);
         this.path = requireNonNull(path, "path must not be null.");
     }
index 44f29d779f191e56250fbc16fd2d13356398d796..624a8067697e13ddc1f2c97319a0279b6eda33c3 100644 (file)
@@ -204,6 +204,12 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
         return FixedYangInstanceIdentifier.create(path, hash.build());
     }
 
+    @Beta
+    public static @NonNull YangInstanceIdentifier create(final PathArgument pathArgument) {
+        return new FixedYangInstanceIdentifier(ImmutableList.of(pathArgument),
+            HashCodeBuilder.nextHashCode(1, pathArgument));
+    }
+
     public static @NonNull YangInstanceIdentifier create(final PathArgument... path) {
         // We are forcing a copy, since we cannot trust the user
         return create(Arrays.asList(path));