From c2a2819c8ec458300827ee238ed6939bc8f2c541 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 11 Sep 2024 20:51:47 -0400 Subject: [PATCH] Convert cascading if-else to switch --- .../collections4/map/AbstractReferenceMap.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java index b6863b4c28..86b4bfbcaa 100644 --- a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java +++ b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java @@ -356,14 +356,15 @@ public V setValue(final V value) { * @return the reference to the object */ protected Object toReference(final ReferenceStrength type, final T referent, final int hash) { - if (type == ReferenceStrength.HARD) { + switch (type) { + case HARD: return referent; - } - if (type == ReferenceStrength.SOFT) { + case SOFT: return new SoftRef<>(hash, referent, parent.queue); - } - if (type == ReferenceStrength.WEAK) { + case WEAK: return new WeakRef<>(hash, referent, parent.queue); + default: + break; } throw new Error(); }