This is an automated email from the ASF dual-hosted git repository. tv pushed a commit to branch release-3.2 in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit dc4adae5fe1c9d4eaa78a98d3b59238105e0a51c Author: Thomas Vandahl <[email protected]> AuthorDate: Sun Jan 8 20:01:23 2023 +0100 Add missing hashCode()/equals() methods --- .../jcs3/auxiliary/disk/PurgatoryElement.java | 30 ++++++++++++++++++++++ .../jcs3/engine/CacheElementSerialized.java | 20 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/PurgatoryElement.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/PurgatoryElement.java index 593356eb..90142002 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/PurgatoryElement.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/PurgatoryElement.java @@ -19,6 +19,8 @@ package org.apache.commons.jcs3.auxiliary.disk; * under the License. */ +import java.util.Objects; + import org.apache.commons.jcs3.engine.CacheElement; import org.apache.commons.jcs3.engine.behavior.ICacheElement; import org.apache.commons.jcs3.engine.behavior.IElementAttributes; @@ -135,6 +137,34 @@ public class PurgatoryElement<K, V> cacheElement.setElementAttributes( attr ); } + /** + * @param obj other object + * @return true if this object key equals the key of obj + */ + @Override + public boolean equals(final Object obj) + { + if (this == obj) + { + return true; + } + if (!(obj instanceof PurgatoryElement)) + { + return false; + } + final PurgatoryElement<?,?> other = (PurgatoryElement<?,?>) obj; + return Objects.equals(getKey(), other.getKey()); + } + + /** + * @return a hash of the key only + */ + @Override + public int hashCode() + { + return getKey().hashCode(); + } + /** * @return debug string */ diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElementSerialized.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElementSerialized.java index 17788ba1..1964154e 100644 --- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElementSerialized.java +++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElementSerialized.java @@ -20,6 +20,7 @@ package org.apache.commons.jcs3.engine; */ import java.util.Arrays; +import java.util.Objects; import org.apache.commons.jcs3.engine.behavior.ICacheElementSerialized; import org.apache.commons.jcs3.engine.behavior.IElementAttributes; @@ -57,6 +58,25 @@ public class CacheElementSerialized<K, V> return this.serializedValue; } + /** + * @param obj other object + * @return true if this object key equals the key of obj + */ + @Override + public boolean equals(final Object obj) + { + if (this == obj) + { + return true; + } + if (!(obj instanceof CacheElementSerialized)) + { + return false; + } + final CacheElementSerialized<?,?> other = (CacheElementSerialized<?,?>) obj; + return Objects.equals(getKey(), other.getKey()); + } + /** * For debugging only. * <p>
