From f9d6b127e6eb77ceb95c72d9f2b9e35d863338d5 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 7 Feb 2023 23:07:31 +0100 Subject: [PATCH] Use Pattern Matching for instanceof in PropertyKeySet (#2086) --- .../core/registry/state/PropertyKeySet.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKeySet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKeySet.java index 334692c88..2a1d4258d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKeySet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/registry/state/PropertyKeySet.java @@ -18,9 +18,9 @@ public class PropertyKeySet implements Set { public static PropertyKeySet ofCollection(Collection collection) { PropertyKeySet set = new PropertyKeySet(); - if (collection instanceof PropertyKeySet) { + if (collection instanceof PropertyKeySet pks) { // simple copy - set.bits.or(((PropertyKeySet) collection).bits); + set.bits.or(pks.bits); return set; } for (PropertyKey key : collection) { @@ -51,10 +51,10 @@ public class PropertyKeySet implements Set { @Override public boolean contains(Object o) { - if (!(o instanceof PropertyKey)) { + if (!(o instanceof PropertyKey pk)) { return false; } - return this.bits.get(((PropertyKey) o).getId()); + return this.bits.get(pk.getId()); } @Nonnull @@ -92,26 +92,26 @@ public class PropertyKeySet implements Set { @Override public boolean remove(Object o) { - if (!(o instanceof PropertyKey)) { + if (!(o instanceof PropertyKey pk)) { return false; } - if (!this.bits.get(((PropertyKey) o).getId())) { + if (!this.bits.get(pk.getId())) { return false; } - this.bits.clear(((PropertyKey) o).getId()); + this.bits.clear(pk.getId()); return true; } @Override public boolean containsAll(@Nonnull Collection c) { - if (c instanceof PropertyKeySet) { - return ((PropertyKeySet) c).bits.intersects(this.bits); + if (c instanceof PropertyKeySet pks) { + return pks.bits.intersects(this.bits); } for (Object o : c) { - if (!(o instanceof PropertyKey)) { + if (!(o instanceof PropertyKey pk)) { return false; } - if (!this.bits.get(((PropertyKey) o).getId())) { + if (!this.bits.get(pk.getId())) { return false; } } @@ -121,8 +121,8 @@ public class PropertyKeySet implements Set { @Override public boolean addAll(@Nonnull Collection c) { int cardinality = this.bits.cardinality(); - if (c instanceof PropertyKeySet) { - this.bits.or(((PropertyKeySet) c).bits); + if (c instanceof PropertyKeySet pks) { + this.bits.or(pks.bits); } else { for (PropertyKey key : c) { this.bits.set(key.getId()); @@ -135,8 +135,8 @@ public class PropertyKeySet implements Set { public boolean retainAll(@Nonnull Collection c) { int cardinality = this.bits.cardinality(); BitSet removal; - if (c instanceof PropertyKeySet) { - removal = ((PropertyKeySet) c).bits; + if (c instanceof PropertyKeySet pks) { + removal = pks.bits; } else { removal = new BitSet(this.bits.length()); for (PropertyKey key : this) { @@ -152,12 +152,12 @@ public class PropertyKeySet implements Set { @Override public boolean removeAll(@Nonnull Collection c) { int cardinality = this.bits.cardinality(); - if (c instanceof PropertyKeySet) { - this.bits.andNot(((PropertyKeySet) c).bits); + if (c instanceof PropertyKeySet pks) { + this.bits.andNot(pks.bits); } else { for (Object o : c) { // mh - if (o instanceof PropertyKey) { - this.bits.clear(((PropertyKey) o).getId()); + if (o instanceof PropertyKey pk) { + this.bits.clear(pk.getId()); } } }