Modernize BinaryValue/UniqueValues 98/106098/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 21 May 2023 11:42:47 +0000 (13:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 21 May 2023 11:42:47 +0000 (13:42 +0200)
Use instanceof patterns to reduce explicit casts.

Change-Id: Icb287b18c62839f5e94951befffb2d20ac038bae
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/BinaryValue.java
data/yang-data-tree-ri/src/main/java/org/opendaylight/yangtools/yang/data/tree/impl/UniqueValues.java

index cd62e1bc585819505e9ce5b1a1a8d2df0d18f089..574add78593807a7f138f7ee66338362af55c569 100644 (file)
@@ -21,11 +21,11 @@ final class BinaryValue implements Immutable {
     }
 
     static Object wrap(final Object value) {
-        return value instanceof byte[] ? new BinaryValue((byte[]) value) : value;
+        return value instanceof byte[] bytes ? new BinaryValue(bytes) : value;
     }
 
     static Object wrapToString(final Object value) {
-        return value instanceof byte[] ? toString((byte[]) value) : value;
+        return value instanceof byte[] bytes ? toString(bytes) : value;
     }
 
     @Override
@@ -35,7 +35,7 @@ final class BinaryValue implements Immutable {
 
     @Override
     public boolean equals(final Object obj) {
-        return obj == this || obj instanceof BinaryValue && Arrays.equals(value, ((BinaryValue) obj).value);
+        return obj == this || obj instanceof BinaryValue other && Arrays.equals(value, other.value);
     }
 
     @Override
index 14dbe54c81747ef914b4c335c2da7bb49145ca95..281b8459c08fee50e526ecaffd7c0594ca813f39 100644 (file)
@@ -35,7 +35,7 @@ final class UniqueValues implements Immutable, Iterable<Object> {
     private UniqueValues(final Object[] objects) {
         verify(objects.length != 0);
         this.objects = objects;
-        this.hashCode = Arrays.deepHashCode(objects);
+        hashCode = Arrays.deepHashCode(objects);
     }
 
     @Override
@@ -50,7 +50,7 @@ final class UniqueValues implements Immutable, Iterable<Object> {
 
     @Override
     public boolean equals(final Object obj) {
-        return this == obj || obj instanceof UniqueValues && Arrays.deepEquals(objects, ((UniqueValues) obj).objects);
+        return this == obj || obj instanceof UniqueValues other && Arrays.deepEquals(objects, other.objects);
     }
 
     @Override