* <li>{@link Qualified}, which also holds a string prefix available via {@link Qualified#getPrefix()}.</li>
* </ol>
*/
-// FIXME: sealed to allow Qualified and Unqualified only when we have JDK17+
@NonNullByDefault
-public abstract class UnresolvedQName extends AbstractQName {
+public abstract sealed class UnresolvedQName extends AbstractQName {
/**
* An unresolved, qualified {@link QName}. It is guaranteed to hold a valid {@link #getLocalName()} bound to a
* namespace identified through a prefix string, but remains unresolved. A resolved {@link QName} can be obtained
return INTERNER.intern(template);
}
+ @Override
+ public Qualified withPrefix(final String newPrefix) {
+ return prefix.equals(newPrefix) ? this : new Qualified(newPrefix, getLocalName());
+ }
+
@Override
@SuppressWarnings("checkstyle:parameterName")
public int compareTo(final Qualified o) {
@Override
public boolean equals(final @Nullable Object obj) {
- return this == obj || obj instanceof Qualified && getLocalName().equals(((Qualified) obj).getLocalName());
+ return this == obj || obj instanceof Qualified other && getLocalName().equals(other.getLocalName());
}
@Override
return null;
}
+ @Override
+ public Qualified withPrefix(final String newPrefix) {
+ return new Qualified(newPrefix, getLocalName());
+ }
+
@Override
@SuppressWarnings("checkstyle:parameterName")
public int compareTo(final Unqualified o) {
@Override
public boolean equals(final @Nullable Object obj) {
- return this == obj || obj instanceof Unqualified
- && getLocalName().equals(((AbstractQName) obj).getLocalName());
+ return this == obj || obj instanceof Unqualified other && getLocalName().equals(other.getLocalName());
}
@Override
* @return This QName's prefix
*/
public abstract @Nullable String getPrefix();
+
+ /**
+ * Return a {@link Qualified} object bound to specified {@code prefix}.
+ *
+ * @return a {@link Qualified} object bound to specified {@code prefix}
+ * @throws NullPointerException if {@code newPrefix} is null
+ */
+ public abstract Qualified withPrefix(String newPrefix);
}