Add UnqualifiedQName.tryCreate()
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / UnqualifiedQName.java
index 5fb343815a4f5267fd218f1a1a5a56c5bb986618..821bc910a1711ea518154bd1dfb81da877d3d5e6 100644 (file)
@@ -32,26 +32,41 @@ public final class UnqualifiedQName extends AbstractQName implements Comparable<
         super(localName);
     }
 
+    /**
+     * Create a new unqualified QName.
+     *
+     * @param localName The local name of this unqualified QName
+     * @return An UnqualifiedQName instance
+     * @throws NullPointerException if localName is null
+     * @throws IllegalArgumentException if localName is not a valid YANG identifier
+     */
     public static UnqualifiedQName of(final String localName) {
         return new UnqualifiedQName(checkLocalName(localName));
     }
 
     /**
-     * Read an UnboundQName from a DataInput. The format is expected to match the output format of
+     * Create a new unqualified QName.
+     *
+     * @param localName The local name of this unqualified QName
+     * @return An UnqualifiedQName instance, or null if localName is not valid
+     */
+    @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "Non-grok of @Nullable")
+    public static @Nullable UnqualifiedQName tryCreate(final String localName) {
+        return isValidLocalName(localName) ? new UnqualifiedQName(localName) : null;
+    }
+
+    /**
+     * Read an UnqualifiedQName from a DataInput. The format is expected to match the output format of
      * {@link #writeTo(DataOutput)}.
      *
      * @param in DataInput to read
-     * @return An UnboundQName instance
+     * @return An UnqualifiedQName instance
      * @throws IOException if I/O error occurs
      */
     public static UnqualifiedQName readFrom(final DataInput in) throws IOException {
         return of(in.readUTF());
     }
 
-    public QName bindTo(final QNameModule namespace) {
-        return new QName(namespace, getLocalName());
-    }
-
     @Override
     @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "Interning identity check")
     public UnqualifiedQName intern() {