Allow rebinding the prefix of an UnresolvedQName 71/98171/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 27 Oct 2021 21:12:14 +0000 (23:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 28 Oct 2021 11:26:19 +0000 (13:26 +0200)
There are callers who are dealing with prefix being optional, possibly
added (or changed) in a later context. Add the ability to do that
without re-validating the local name.

JIRA: YANGTOOLS-1359
Change-Id: I099589d8a579f854dcc0ae1740027e7af24470bf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 840bcc965c8eeb566d8cebd870f35e1be85cc617)

common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QualifiedQName.java
common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/UnqualifiedQName.java

index 1c12ecb4cf51ab8025eb411b00c014721d393609..a003ce92b581fd726a13383f4c09edff352c6d54 100644 (file)
@@ -34,7 +34,7 @@ public final class QualifiedQName extends AbstractQName implements Comparable<Qu
 
     private final String prefix;
 
-    private QualifiedQName(final String prefix, final String localName) {
+    QualifiedQName(final String prefix, final String localName) {
         super(localName);
         this.prefix = requireNonNull(prefix);
     }
index 821bc910a1711ea518154bd1dfb81da877d3d5e6..54a14c1dd706e2757cf51d719e5b964f0d645465 100644 (file)
@@ -55,6 +55,16 @@ public final class UnqualifiedQName extends AbstractQName implements Comparable<
         return isValidLocalName(localName) ? new UnqualifiedQName(localName) : null;
     }
 
+    /**
+     * Return a {@link QualifiedQName} object bound to specified {@code prefix}.
+     *
+     * @return a {@link QualifiedQName} object bound to specified {@code prefix}
+     * @throws NullPointerException if {@code newPrefix} is null
+     */
+    public QualifiedQName withPrefix(final String newPrefix) {
+        return new QualifiedQName(newPrefix, getLocalName());
+    }
+
     /**
      * Read an UnqualifiedQName from a DataInput. The format is expected to match the output format of
      * {@link #writeTo(DataOutput)}.