Modernize yang-data-codec-binfmt 12/101312/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 26 May 2022 21:06:16 +0000 (23:06 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 27 May 2022 13:17:50 +0000 (15:17 +0200)
Use JDK17 features to make the code a bit more less verbose and more
resilient.

Change-Id: I8219ca1a6507940b6d2e24800ff29c1d350469e2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractLithiumDataInput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractMagnesiumDataInput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractMagnesiumDataOutput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractNormalizedNodeDataOutput.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/NeonSR2NormalizedNodeInputStreamReader.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/QNameFactory.java
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/VersionedNormalizedNodeDataInput.java

index bb362e7de7c93191eed25faf27016638ded17da8..a23137d6bdd37e79dffa01ed4269d84456a99927 100644 (file)
@@ -66,47 +66,20 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
 
     private void streamNormalizedNode(final NormalizedNodeStreamWriter writer, final byte nodeType) throws IOException {
         switch (nodeType) {
-            case LithiumNode.ANY_XML_NODE:
-                streamAnyxml(writer);
-                break;
-            case LithiumNode.AUGMENTATION_NODE:
-                streamAugmentation(writer);
-                break;
-            case LithiumNode.CHOICE_NODE:
-                streamChoice(writer);
-                break;
-            case LithiumNode.CONTAINER_NODE:
-                streamContainer(writer);
-                break;
-            case LithiumNode.LEAF_NODE:
-                streamLeaf(writer);
-                break;
-            case LithiumNode.LEAF_SET:
-                streamLeafSet(writer);
-                break;
-            case LithiumNode.ORDERED_LEAF_SET:
-                streamOrderedLeafSet(writer);
-                break;
-            case LithiumNode.LEAF_SET_ENTRY_NODE:
-                streamLeafSetEntry(writer);
-                break;
-            case LithiumNode.MAP_ENTRY_NODE:
-                streamMapEntry(writer);
-                break;
-            case LithiumNode.MAP_NODE:
-                streamMap(writer);
-                break;
-            case LithiumNode.ORDERED_MAP_NODE:
-                streamOrderedMap(writer);
-                break;
-            case LithiumNode.UNKEYED_LIST:
-                streamUnkeyedList(writer);
-                break;
-            case LithiumNode.UNKEYED_LIST_ITEM:
-                streamUnkeyedListItem(writer);
-                break;
-            default:
-                throw new InvalidNormalizedNodeStreamException("Unexpected node " + nodeType);
+            case LithiumNode.ANY_XML_NODE -> streamAnyxml(writer);
+            case LithiumNode.AUGMENTATION_NODE -> streamAugmentation(writer);
+            case LithiumNode.CHOICE_NODE -> streamChoice(writer);
+            case LithiumNode.CONTAINER_NODE -> streamContainer(writer);
+            case LithiumNode.LEAF_NODE -> streamLeaf(writer);
+            case LithiumNode.LEAF_SET -> streamLeafSet(writer);
+            case LithiumNode.ORDERED_LEAF_SET -> streamOrderedLeafSet(writer);
+            case LithiumNode.LEAF_SET_ENTRY_NODE -> streamLeafSetEntry(writer);
+            case LithiumNode.MAP_ENTRY_NODE -> streamMapEntry(writer);
+            case LithiumNode.MAP_NODE -> streamMap(writer);
+            case LithiumNode.ORDERED_MAP_NODE -> streamOrderedMap(writer);
+            case LithiumNode.UNKEYED_LIST -> streamUnkeyedList(writer);
+            case LithiumNode.UNKEYED_LIST_ITEM -> streamUnkeyedListItem(writer);
+            default -> throw new InvalidNormalizedNodeStreamException("Unexpected node " + nodeType);
         }
     }
 
@@ -279,23 +252,23 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
 
     final String readCodedString() throws IOException {
         final byte valueType = input.readByte();
-        switch (valueType) {
-            case LithiumTokens.IS_NULL_VALUE:
-                return null;
-            case LithiumTokens.IS_CODE_VALUE:
+        return switch (valueType) {
+            case LithiumTokens.IS_NULL_VALUE -> null;
+            case LithiumTokens.IS_CODE_VALUE -> {
                 final int code = input.readInt();
                 try {
-                    return codedStringMap.get(code);
+                    yield codedStringMap.get(code);
                 } catch (IndexOutOfBoundsException e) {
                     throw new IOException("String code " + code + " was not found", e);
                 }
-            case LithiumTokens.IS_STRING_VALUE:
+            }
+            case LithiumTokens.IS_STRING_VALUE -> {
                 final String value = input.readUTF().intern();
                 codedStringMap.add(value);
-                return value;
-            default:
-                throw new IOException("Unhandled string value type " + valueType);
-        }
+                yield value;
+            }
+            default -> throw new IOException("Unhandled string value type " + valueType);
+        };
     }
 
     private Set<QName> readQNameSet() throws IOException {
@@ -340,60 +313,33 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
 
     private Object readObject() throws IOException {
         byte objectType = input.readByte();
-        switch (objectType) {
-            case LithiumValue.BITS_TYPE:
-                return readObjSet();
-
-            case LithiumValue.BOOL_TYPE:
-                return input.readBoolean();
-
-            case LithiumValue.BYTE_TYPE:
-                return input.readByte();
-
-            case LithiumValue.INT_TYPE:
-                return input.readInt();
-
-            case LithiumValue.LONG_TYPE:
-                return input.readLong();
-
-            case LithiumValue.QNAME_TYPE:
-                return readQName();
-
-            case LithiumValue.SHORT_TYPE:
-                return input.readShort();
-
-            case LithiumValue.STRING_TYPE:
-                return input.readUTF();
-
-            case LithiumValue.STRING_BYTES_TYPE:
-                return readStringBytes();
-
-            case LithiumValue.BIG_DECIMAL_TYPE:
-                return Decimal64.valueOf(input.readUTF());
-
-            case LithiumValue.BIG_INTEGER_TYPE:
-                return new BigInteger(input.readUTF());
-
-            case LithiumValue.BINARY_TYPE:
+        return switch (objectType) {
+            case LithiumValue.BITS_TYPE -> readObjSet();
+            case LithiumValue.BOOL_TYPE -> input.readBoolean();
+            case LithiumValue.BYTE_TYPE -> input.readByte();
+            case LithiumValue.INT_TYPE -> input.readInt();
+            case LithiumValue.LONG_TYPE -> input.readLong();
+            case LithiumValue.QNAME_TYPE -> readQName();
+            case LithiumValue.SHORT_TYPE -> input.readShort();
+            case LithiumValue.STRING_TYPE -> input.readUTF();
+            case LithiumValue.STRING_BYTES_TYPE -> readStringBytes();
+            case LithiumValue.BIG_DECIMAL_TYPE -> Decimal64.valueOf(input.readUTF());
+            case LithiumValue.BIG_INTEGER_TYPE -> new BigInteger(input.readUTF());
+            case LithiumValue.BINARY_TYPE -> {
                 byte[] bytes = new byte[input.readInt()];
                 input.readFully(bytes);
-                return bytes;
-
-            case LithiumValue.YANG_IDENTIFIER_TYPE:
-                return readYangInstanceIdentifierInternal();
-
-            case LithiumValue.EMPTY_TYPE:
+                yield bytes;
+            }
+            case LithiumValue.YANG_IDENTIFIER_TYPE -> readYangInstanceIdentifierInternal();
+            case LithiumValue.EMPTY_TYPE, LithiumValue.NULL_TYPE ->
             // Leaf nodes no longer allow null values and thus we no longer emit null values. Previously, the "empty"
             // yang type was represented as null so we translate an incoming null value to Empty. It was possible for
             // a BI user to set a string leaf to null and we're rolling the dice here but the chances for that are
             // very low. We'd have to know the yang type but, even if we did, we can't let a null value pass upstream
             // so we'd have to drop the leaf which might cause other issues.
-            case LithiumValue.NULL_TYPE:
-                return Empty.value();
-
-            default:
-                return null;
-        }
+                Empty.value();
+            default -> null;
+        };
     }
 
     private String readStringBytes() throws IOException {
@@ -429,19 +375,14 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
     public final PathArgument readPathArgument() throws IOException {
         // read Type
         int type = input.readByte();
-
-        switch (type) {
-            case LithiumPathArgument.AUGMENTATION_IDENTIFIER:
-                return readAugmentationIdentifier();
-            case LithiumPathArgument.NODE_IDENTIFIER:
-                return readNodeIdentifier();
-            case LithiumPathArgument.NODE_IDENTIFIER_WITH_PREDICATES:
-                return readNormalizedNodeWithPredicates();
-            case LithiumPathArgument.NODE_IDENTIFIER_WITH_VALUE:
-                return new NodeWithValue<>(readQName(), readObject());
-            default:
+        return  switch (type) {
+            case LithiumPathArgument.AUGMENTATION_IDENTIFIER -> readAugmentationIdentifier();
+            case LithiumPathArgument.NODE_IDENTIFIER -> readNodeIdentifier();
+            case LithiumPathArgument.NODE_IDENTIFIER_WITH_PREDICATES -> readNormalizedNodeWithPredicates();
+            case LithiumPathArgument.NODE_IDENTIFIER_WITH_VALUE -> new NodeWithValue<>(readQName(), readObject());
+            default ->
                 // FIXME: throw hard error
-                return null;
-        }
+                null;
+        };
     }
 }
index 84e01af84550670e6ab7844e3a8971ad0fd028c3..343853cdd760babcb1bcbe9c65f84af1f4a69e38 100644 (file)
@@ -164,12 +164,12 @@ abstract class AbstractMagnesiumDataInput extends AbstractNormalizedNodeDataInpu
 
         final Object value;
         if ((nodeHeader & MagnesiumNode.PREDICATE_ONE) == MagnesiumNode.PREDICATE_ONE) {
-            if (!(parent instanceof NodeIdentifierWithPredicates)) {
+            if (!(parent instanceof NodeIdentifierWithPredicates nip)) {
                 throw new InvalidNormalizedNodeStreamException("Invalid predicate leaf " + identifier + " in parent "
                         + parent);
             }
 
-            value = ((NodeIdentifierWithPredicates) parent).getValue(identifier.getNodeType());
+            value = nip.getValue(identifier.getNodeType());
             if (value == null) {
                 throw new InvalidNormalizedNodeStreamException("Failed to find predicate leaf " + identifier
                     + " in parent " + parent);
@@ -241,26 +241,16 @@ abstract class AbstractMagnesiumDataInput extends AbstractNormalizedNodeDataInpu
             final byte nodeHeader) throws IOException {
         final NodeIdentifier nodeId = decodeNodeIdentifier(nodeHeader, parent);
 
-        final int size;
-        switch (mask(nodeHeader, MagnesiumNode.PREDICATE_MASK)) {
-            case MagnesiumNode.PREDICATE_ZERO:
-                size = 0;
-                break;
-            case MagnesiumNode.PREDICATE_ONE:
-                size = 1;
-                break;
-            case MagnesiumNode.PREDICATE_1B:
-                size = input.readUnsignedByte();
-                break;
-            case MagnesiumNode.PREDICATE_4B:
-                size = input.readInt();
-                break;
-            default:
+        final int size = switch (mask(nodeHeader, MagnesiumNode.PREDICATE_MASK)) {
+            case MagnesiumNode.PREDICATE_ZERO -> 0;
+            case MagnesiumNode.PREDICATE_ONE -> 1;
+            case MagnesiumNode.PREDICATE_1B -> input.readUnsignedByte();
+            case MagnesiumNode.PREDICATE_4B -> input.readInt();
+            default ->
                 // ISE on purpose: this should never ever happen
                 throw new IllegalStateException("Failed to decode NodeIdentifierWithPredicates size from header "
-                        + nodeHeader);
-        }
-
+                    + nodeHeader);
+        };
         final NodeIdentifierWithPredicates identifier = readNodeIdentifierWithPredicates(nodeId.getNodeType(), size);
         LOG.trace("Streaming map entry node {}", identifier);
         writer.startMapEntryNode(identifier, UNKNOWN_SIZE);
@@ -306,8 +296,8 @@ abstract class AbstractMagnesiumDataInput extends AbstractNormalizedNodeDataInpu
                 index = input.readInt();
                 break;
             case MagnesiumNode.ADDR_PARENT:
-                if (parent instanceof NodeIdentifier) {
-                    return (NodeIdentifier) parent;
+                if (parent instanceof NodeIdentifier nid) {
+                    return nid;
                 }
                 throw new InvalidNormalizedNodeStreamException("Invalid node identifier reference to parent " + parent);
             default:
index 659cae5d883afe84225c6663d5ae5b9512e95267..ddc76d8ef756a4c72149d7265725b752ae10ad56 100644 (file)
@@ -82,9 +82,9 @@ abstract class AbstractMagnesiumDataOutput extends AbstractNormalizedNodeDataOut
     @Override
     public final void startLeafNode(final NodeIdentifier name) throws IOException {
         final Object current = stack.peek();
-        if (current instanceof NodeIdentifierWithPredicates) {
+        if (current instanceof NodeIdentifierWithPredicates nip) {
             final QName qname = name.getNodeType();
-            if (((NodeIdentifierWithPredicates) current).containsKey(qname)) {
+            if (nip.containsKey(qname)) {
                 writeQNameNode(MagnesiumNode.NODE_LEAF | MagnesiumNode.PREDICATE_ONE, qname);
                 stack.push(KEY_LEAF_STATE);
                 return;
@@ -229,16 +229,16 @@ abstract class AbstractMagnesiumDataOutput extends AbstractNormalizedNodeDataOut
 
     @Override
     final void writePathArgumentInternal(final PathArgument pathArgument) throws IOException {
-        if (pathArgument instanceof NodeIdentifier) {
-            writeNodeIdentifier((NodeIdentifier) pathArgument);
-        } else if (pathArgument instanceof NodeIdentifierWithPredicates) {
-            writeNodeIdentifierWithPredicates((NodeIdentifierWithPredicates) pathArgument);
-        } else if (pathArgument instanceof AugmentationIdentifier) {
-            writeAugmentationIdentifier((AugmentationIdentifier) pathArgument);
-        } else if (pathArgument instanceof NodeWithValue) {
-            writeNodeWithValue((NodeWithValue<?>) pathArgument);
-        } else if (pathArgument instanceof MountPointIdentifier) {
-            writeMountPointIdentifier((MountPointIdentifier) pathArgument);
+        if (pathArgument instanceof NodeIdentifier nid) {
+            writeNodeIdentifier(nid);
+        } else if (pathArgument instanceof NodeIdentifierWithPredicates nip) {
+            writeNodeIdentifierWithPredicates(nip);
+        } else if (pathArgument instanceof AugmentationIdentifier augid) {
+            writeAugmentationIdentifier(augid);
+        } else if (pathArgument instanceof NodeWithValue<?> niv) {
+            writeNodeWithValue(niv);
+        } else if (pathArgument instanceof MountPointIdentifier mpid) {
+            writeMountPointIdentifier(mpid);
         } else {
             throw new IOException("Unhandled PathArgument " + pathArgument);
         }
@@ -336,41 +336,41 @@ abstract class AbstractMagnesiumDataOutput extends AbstractNormalizedNodeDataOut
     }
 
     private void writeObject(final @NonNull Object value) throws IOException {
-        if (value instanceof String) {
-            writeValue((String) value);
-        } else if (value instanceof Boolean) {
-            writeValue((Boolean) value);
-        } else if (value instanceof Byte) {
-            writeValue((Byte) value);
-        } else if (value instanceof Short) {
-            writeValue((Short) value);
-        } else if (value instanceof Integer) {
-            writeValue((Integer) value);
-        } else if (value instanceof Long) {
-            writeValue((Long) value);
-        } else if (value instanceof Uint8) {
-            writeValue((Uint8) value);
-        } else if (value instanceof Uint16) {
-            writeValue((Uint16) value);
-        } else if (value instanceof Uint32) {
-            writeValue((Uint32) value);
-        } else if (value instanceof Uint64) {
-            writeValue((Uint64) value);
-        } else if (value instanceof QName) {
-            writeQNameInternal((QName) value);
-        } else if (value instanceof YangInstanceIdentifier) {
-            writeValue((YangInstanceIdentifier) value);
-        } else if (value instanceof byte[]) {
-            writeValue((byte[]) value);
+        if (value instanceof String str) {
+            writeValue(str);
+        } else if (value instanceof Boolean bool) {
+            writeValue(bool);
+        } else if (value instanceof Byte byteVal) {
+            writeValue(byteVal);
+        } else if (value instanceof Short shortVal) {
+            writeValue(shortVal);
+        } else if (value instanceof Integer intVal) {
+            writeValue(intVal);
+        } else if (value instanceof Long longVal) {
+            writeValue(longVal);
+        } else if (value instanceof Uint8 uint8) {
+            writeValue(uint8);
+        } else if (value instanceof Uint16 uint16) {
+            writeValue(uint16);
+        } else if (value instanceof Uint32 uint32) {
+            writeValue(uint32);
+        } else if (value instanceof Uint64 uint64) {
+            writeValue(uint64);
+        } else if (value instanceof QName qname) {
+            writeQNameInternal(qname);
+        } else if (value instanceof YangInstanceIdentifier id) {
+            writeValue(id);
+        } else if (value instanceof byte[] bytes) {
+            writeValue(bytes);
         } else if (value instanceof Empty) {
             output.writeByte(MagnesiumValue.EMPTY);
-        } else if (value instanceof Set) {
-            writeValue((Set<?>) value);
+        } else if (value instanceof Set<?> set) {
+            writeValue(set);
         } else if (value instanceof BigDecimal || value instanceof Decimal64) {
             output.writeByte(MagnesiumValue.BIGDECIMAL);
             output.writeUTF(value.toString());
-        } else if (value instanceof BigInteger) {
-            writeValue((BigInteger) value);
+        } else if (value instanceof BigInteger val) {
+            writeValue(val);
         } else {
             throw new IOException("Unhandled value type " + value.getClass());
         }
@@ -548,7 +548,7 @@ abstract class AbstractMagnesiumDataOutput extends AbstractNormalizedNodeDataOut
     // NodeIdentifier -- which is typically true
     private boolean matchesParentQName(final QName qname) {
         final Object current = stack.peek();
-        return current instanceof NodeIdentifier && qname.equals(((NodeIdentifier) current).getNodeType());
+        return current instanceof NodeIdentifier nid && qname.equals(nid.getNodeType());
     }
 
     // Start an END_NODE-terminated node, which typically has a QName matching the parent. If that is the case we emit
index c487dab5425de77c03c2cc3b8584f68bbcde2c72..e03cb8655863c6f67e8f9fcd179aea8146bd1313 100755 (executable)
@@ -193,8 +193,8 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
 
     @Override
     public void flush() throws IOException {
-        if (output instanceof OutputStream) {
-            ((OutputStream)output).flush();
+        if (output instanceof OutputStream out) {
+            out.flush();
         }
     }
 
index 0120efb1f93f4ce9d277fea035dec75368b7a76c..f689fff59bab1a3c2ff27af25733fdcf25a31966 100644 (file)
@@ -40,27 +40,21 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
     @Override
     public QName readQName() throws IOException {
         final byte valueType = readByte();
-        switch (valueType) {
-            case NeonSR2Tokens.IS_QNAME_CODE:
-                return codedQName(readInt());
-            case NeonSR2Tokens.IS_QNAME_VALUE:
-                return rawQName();
-            default:
-                throw new IOException("Unhandled QName value type " + valueType);
-        }
+        return switch (valueType) {
+            case NeonSR2Tokens.IS_QNAME_CODE -> codedQName(readInt());
+            case NeonSR2Tokens.IS_QNAME_VALUE -> rawQName();
+            default -> throw new IOException("Unhandled QName value type " + valueType);
+        };
     }
 
     @Override
     AugmentationIdentifier readAugmentationIdentifier() throws IOException {
         final byte valueType = readByte();
-        switch (valueType) {
-            case NeonSR2Tokens.IS_AUGMENT_CODE:
-                return codedAugmentId(readInt());
-            case NeonSR2Tokens.IS_AUGMENT_VALUE:
-                return rawAugmentId();
-            default:
-                throw new IOException("Unhandled AugmentationIdentifier value type " + valueType);
-        }
+        return switch (valueType) {
+            case NeonSR2Tokens.IS_AUGMENT_CODE -> codedAugmentId(readInt());
+            case NeonSR2Tokens.IS_AUGMENT_VALUE -> rawAugmentId();
+            default -> throw new IOException("Unhandled AugmentationIdentifier value type " + valueType);
+        };
     }
 
     @Override
@@ -68,26 +62,20 @@ final class NeonSR2NormalizedNodeInputStreamReader extends AbstractLithiumDataIn
         // NodeIdentifier rides on top of QName, with this method really saying 'interpret next QName as NodeIdentifier'
         // to do that we inter-mingle with readQName()
         final byte valueType = readByte();
-        switch (valueType) {
-            case NeonSR2Tokens.IS_QNAME_CODE:
-                return codedNodeIdentifier(readInt());
-            case NeonSR2Tokens.IS_QNAME_VALUE:
-                return rawNodeIdentifier();
-            default:
-                throw new IOException("Unhandled NodeIdentifier value type " + valueType);
-        }
+        return switch (valueType) {
+            case NeonSR2Tokens.IS_QNAME_CODE -> codedNodeIdentifier(readInt());
+            case NeonSR2Tokens.IS_QNAME_VALUE -> rawNodeIdentifier();
+            default -> throw new IOException("Unhandled NodeIdentifier value type " + valueType);
+        };
     }
 
     private QNameModule readModule() throws IOException {
         final byte valueType = readByte();
-        switch (valueType) {
-            case NeonSR2Tokens.IS_MODULE_CODE:
-                return codedModule(readInt());
-            case NeonSR2Tokens.IS_MODULE_VALUE:
-                return rawModule();
-            default:
-                throw new IOException("Unhandled QNameModule value type " + valueType);
-        }
+        return switch (valueType) {
+            case NeonSR2Tokens.IS_MODULE_CODE -> codedModule(readInt());
+            case NeonSR2Tokens.IS_MODULE_VALUE -> rawModule();
+            default -> throw new IOException("Unhandled QNameModule value type " + valueType);
+        };
     }
 
     private NodeIdentifier codedNodeIdentifier(final int code) throws IOException {
index 13680b494b3a901dba8f3bbf5db58d6a6d4844d8..174199d6a88cdd7d380603467aa50107883ec211 100644 (file)
@@ -42,15 +42,8 @@ final class QNameFactory {
 
         @Override
         public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (!(obj instanceof StringQName)) {
-                return false;
-            }
-            final StringQName other = (StringQName) obj;
-            return localName.equals(other.localName) && namespace.equals(other.namespace)
-                    && Objects.equals(revision, other.revision);
+            return this == obj || obj instanceof StringQName other && localName.equals(other.localName)
+                && namespace.equals(other.namespace) && Objects.equals(revision, other.revision);
         }
 
         QName toQName() {
@@ -74,14 +67,8 @@ final class QNameFactory {
 
         @Override
         public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (!(obj instanceof ModuleQName)) {
-                return false;
-            }
-            final ModuleQName other = (ModuleQName) obj;
-            return localName.equals(other.localName) && module.equals(other.module);
+            return this == obj || obj instanceof ModuleQName other && localName.equals(other.localName)
+                && module.equals(other.module);
         }
 
         QName toQName() {
@@ -105,14 +92,8 @@ final class QNameFactory {
 
         @Override
         public boolean equals(final Object obj) {
-            if (this == obj) {
-                return true;
-            }
-            if (!(obj instanceof StringModule)) {
-                return false;
-            }
-            final StringModule other = (StringModule) obj;
-            return namespace.equals(other.namespace) && Objects.equals(revision, other.revision);
+            return this == obj || obj instanceof StringModule other && namespace.equals(other.namespace)
+                && Objects.equals(revision, other.revision);
         }
 
         QNameModule toQNameModule() {
index 099f56d5ab41275f57ad25d21d614a753b43521c..a1b992bc1009fa20dd787084b0669cf2950dbd8a 100644 (file)
@@ -32,23 +32,13 @@ final class VersionedNormalizedNodeDataInput extends ForwardingNormalizedNodeDat
         }
 
         final short version = input.readShort();
-        final NormalizedNodeDataInput ret;
-        switch (version) {
-            case TokenTypes.LITHIUM_VERSION:
-                ret = new LithiumNormalizedNodeInputStreamReader(input);
-                break;
-            case TokenTypes.NEON_SR2_VERSION:
-                ret = new NeonSR2NormalizedNodeInputStreamReader(input);
-                break;
-            case TokenTypes.SODIUM_SR1_VERSION:
-                ret = new SodiumSR1DataInput(input);
-                break;
-            case TokenTypes.MAGNESIUM_VERSION:
-                ret = new MagnesiumDataInput(input);
-                break;
-            default:
-                throw defunct("Unhandled stream version %s", version);
-        }
+        final NormalizedNodeDataInput ret = switch (version) {
+            case TokenTypes.LITHIUM_VERSION -> new LithiumNormalizedNodeInputStreamReader(input);
+            case TokenTypes.NEON_SR2_VERSION -> new NeonSR2NormalizedNodeInputStreamReader(input);
+            case TokenTypes.SODIUM_SR1_VERSION -> new SodiumSR1DataInput(input);
+            case TokenTypes.MAGNESIUM_VERSION -> new MagnesiumDataInput(input);
+            default -> throw defunct("Unhandled stream version %s", version);
+        };
 
         setDelegate(ret);
         return ret;