Add UnqualifiedQName.tryCreate()
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / UnqualifiedQName.java
index 0b6bffb54e2e65442683294a9e83ed23ffa412e3..821bc910a1711ea518154bd1dfb81da877d3d5e6 100644 (file)
@@ -44,6 +44,17 @@ public final class UnqualifiedQName extends AbstractQName implements Comparable<
         return new UnqualifiedQName(checkLocalName(localName));
     }
 
+    /**
+     * 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)}.