Promote Absolute.{last,first}NodeIdentifier 28/92928/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Oct 2020 00:09:52 +0000 (02:09 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Oct 2020 00:29:26 +0000 (02:29 +0200)
SchemaNodeIdentifier.Descendant has to have at least one
element just as Absolute. Promote utility methods to allow
users pick them.

Change-Id: I428213da7db699ea50a5e67b25feee21553c99f3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/SchemaNodeIdentifier.java

index 0801729c51ce1c667bceb4128a5de532d0986684..dd4c0cb624f3bb2f01c7c74c9a9b7e3fe9e9fb61 100644 (file)
@@ -86,22 +86,6 @@ public abstract class SchemaNodeIdentifier implements Immutable {
             return INTERNER.intern(this);
         }
 
-        /**
-         * Return the first node identifier. This method is equivalent to {@code getNodeIdentifiers().get(0)}, but is
-         * potentially more efficient.
-         *
-         * @return The first node identifier
-         */
-        public abstract @NonNull QName firstNodeIdentifier();
-
-        /**
-         * Return the last node identifier. This method is equivalent to {@code getNodeIdentifiers().get(size - 1)}, but
-         * is potentially more efficient.
-         *
-         * @return The last node identifier
-         */
-        public abstract @NonNull QName lastNodeIdentifier();
-
         @Override
         final SchemaPath implicitSchemaPathParent() {
             return SchemaPath.ROOT;
@@ -208,16 +192,6 @@ public abstract class SchemaNodeIdentifier implements Immutable {
             return qnames;
         }
 
-        @Override
-        public @NonNull QName firstNodeIdentifier() {
-            return qnames.get(0);
-        }
-
-        @Override
-        public @NonNull QName lastNodeIdentifier() {
-            return qnames.get(qnames.size() - 1);
-        }
-
         @Override
         Object pathObject() {
             return qnames;
@@ -236,6 +210,16 @@ public abstract class SchemaNodeIdentifier implements Immutable {
             return ImmutableList.of(qname);
         }
 
+        @Override
+        public QName firstNodeIdentifier() {
+            return qname;
+        }
+
+        @Override
+        public QName lastNodeIdentifier() {
+            return qname;
+        }
+
         @Override
         Object pathObject() {
             return qname;
@@ -279,6 +263,27 @@ public abstract class SchemaNodeIdentifier implements Immutable {
      */
     public abstract @NonNull List<QName> getNodeIdentifiers();
 
+    /**
+     * Return the first node identifier. This method is equivalent to {@code getNodeIdentifiers().get(0)}, but is
+     * potentially more efficient.
+     *
+     * @return The first node identifier
+     */
+    public @NonNull QName firstNodeIdentifier() {
+        return getNodeIdentifiers().get(0);
+    }
+
+    /**
+     * Return the last node identifier. This method is equivalent to {@code getNodeIdentifiers().get(size - 1)}, but
+     * is potentially more efficient.
+     *
+     * @return The last node identifier
+     */
+    public @NonNull QName lastNodeIdentifier() {
+        final List<QName> local = getNodeIdentifiers();
+        return local.get(local.size() - 1);
+    }
+
     /**
      * Create the {@link SchemaPath} equivalent of this identifier.
      *