Use instanceof pattern in SingletonSet 03/102103/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 17 Aug 2022 06:45:54 +0000 (08:45 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 17 Aug 2022 06:46:20 +0000 (08:46 +0200)
We can simplify our equals() implementation a bit, let's do that.

Change-Id: I6b0d18ca1be2762cf5709857975a58a68ace6599
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/SingletonSet.java

index 79fb914156c9908222268ce557e28741255f7258..7097ec29d09a5efc71eaae02e977c76a365825f2 100644 (file)
@@ -162,15 +162,7 @@ public abstract class SingletonSet<E> implements Set<E>, Immutable, Serializable
     @Override
     @SuppressWarnings("checkstyle:equalsHashCode")
     public final boolean equals(final Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof Set)) {
-            return false;
-        }
-
-        final Set<?> s = (Set<?>)obj;
-        return s.size() == 1 && otherContains(s);
+        return obj == this || obj instanceof Set<?> other && other.size() == 1 && otherContains(other);
     }
 
     @SuppressFBWarnings(value = "DCN_NULLPOINTER_EXCEPTION",