* @throws IOException if I/O error occurs
*/
public static @NonNull QName readFrom(final DataInput in) throws IOException {
- if (in instanceof QNameAwareDataInput) {
- return ((QNameAwareDataInput) in).readQName();
+ if (in instanceof QNameAwareDataInput aware) {
+ return aware.readQName();
}
final QNameModule module = QNameModule.readFrom(in);
*/
@Override
public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof QName)) {
- return false;
- }
- final QName other = (QName) obj;
- return Objects.equals(getLocalName(), other.getLocalName()) && module.equals(other.module);
+ return this == obj || obj instanceof QName other && getLocalName().equals(other.getLocalName())
+ && module.equals(other.module);
}
@Override
return getLocalName().equals(other.getLocalName()) && Objects.equals(getNamespace(), other.getNamespace());
}
- // FIXME: this comparison function looks odd. We are sorting first by local name and then by module? What is
- // the impact on iteration order of SortedMap<QName, ?>?
@Override
@SuppressWarnings("checkstyle:parameterName")
public int compareTo(final QName o) {
- // compare mandatory localName parameter
- int result = getLocalName().compareTo(o.getLocalName());
- if (result != 0) {
- return result;
- }
- return module.compareTo(o.module);
+ final int result = module.compareTo(o.module);
+ return result != 0 ? result : getLocalName().compareTo(o.getLocalName());
}
@Override
public void writeTo(final DataOutput out) throws IOException {
- if (out instanceof QNameAwareDataOutput) {
- ((QNameAwareDataOutput) out).writeQName(this);
+ if (out instanceof QNameAwareDataOutput aware) {
+ aware.writeQName(this);
} else {
module.writeTo(out);
out.writeUTF(getLocalName());