This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 3d0b4ecd1cd2ae963e8dde25e19264efd4c1f586 Author: Thomas Vandahl <[email protected]> AuthorDate: Sat Sep 5 12:22:09 2026 +0200 Move payload to derived classes --- .../memory/util/MemoryElementDescriptor.java | 8 ++++--- .../commons/jcs4/utils/struct/AbstractLRUMap.java | 28 ++++++++++------------ .../jcs4/utils/struct/DoubleLinkedListNode.java | 25 +++---------------- .../jcs4/utils/struct/LRUElementDescriptor.java | 21 ++++++++++++---- 4 files changed, 38 insertions(+), 44 deletions(-) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/util/MemoryElementDescriptor.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/util/MemoryElementDescriptor.java index ad0ae973..13c6fe29 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/util/MemoryElementDescriptor.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/util/MemoryElementDescriptor.java @@ -26,11 +26,13 @@ import org.apache.commons.jcs4.utils.struct.DoubleLinkedListNode; * This wrapper is needed for double linked lists. */ public class MemoryElementDescriptor<K, V> - extends DoubleLinkedListNode<ICacheElement<K, V>> + extends DoubleLinkedListNode { /** Don't change */ private static final long serialVersionUID = -1905161209035522460L; + private ICacheElement<K, V> cacheElement; + /** * Constructs a usable MemoryElementDescriptor. * @@ -38,7 +40,7 @@ public class MemoryElementDescriptor<K, V> */ public MemoryElementDescriptor( final ICacheElement<K, V> ce ) { - super( ce ); + this.cacheElement = ce; } /** @@ -48,6 +50,6 @@ public class MemoryElementDescriptor<K, V> */ public ICacheElement<K, V> getCacheElement() { - return getPayload(); + return cacheElement; } } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/AbstractLRUMap.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/AbstractLRUMap.java index a76095ee..78c3fcdd 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/AbstractLRUMap.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/AbstractLRUMap.java @@ -130,15 +130,14 @@ public abstract class AbstractLRUMap<K, V> /** * Dump the cache entries from first to list for debugging. */ - @SuppressWarnings("unchecked") // No generics for public fields private void dumpCacheEntries() { if (log.isTraceEnabled()) { log.trace("dumpingCacheEntries"); - for (LRUElementDescriptor<K, V> me = list.getFirst(); me != null; me = (LRUElementDescriptor<K, V>) me.next) + for (LRUElementDescriptor<K, V> me : list) { - log.trace("dumpCacheEntries> key={0}, val={1}", me.getKey(), me.getPayload()); + log.trace("dumpCacheEntries> key={0}, val={1}", me.getKey(), me.getValue()); } } } @@ -151,7 +150,7 @@ public abstract class AbstractLRUMap<K, V> if (log.isTraceEnabled()) { log.trace("dumpingMap"); - map.forEach((key, value) -> log.trace("dumpMap> key={0}, val={1}", key, value.getPayload())); + map.forEach((key, value) -> log.trace("dumpMap> key={0}, val={1}", key, value.getValue())); } } @@ -173,7 +172,7 @@ public abstract class AbstractLRUMap<K, V> { return map.entrySet().stream() .map(entry -> new AbstractMap.SimpleEntry<>( - entry.getKey(), entry.getValue().getPayload())) + entry.getKey(), entry.getValue().getValue())) .collect(Collectors.toSet()); } finally @@ -206,7 +205,7 @@ public abstract class AbstractLRUMap<K, V> else { hitCnt++; - retVal = me.getPayload(); + retVal = me.getValue(); list.makeFirst( me ); } @@ -243,7 +242,7 @@ public abstract class AbstractLRUMap<K, V> if ( me != null ) { - ce = me.getPayload(); + ce = me.getValue(); } if ( me == null ) @@ -357,7 +356,7 @@ public abstract class AbstractLRUMap<K, V> verifyCache(); throw new Error("update: last is null!"); } - processRemovedLRU(last.getKey(), last.getPayload()); + processRemovedLRU(last.getKey(), last.getValue()); if (map.remove(last.getKey()) == null) { log.warn("update: remove failed for key: {0}", @@ -383,7 +382,7 @@ public abstract class AbstractLRUMap<K, V> if ( old != null ) { - return old.getPayload(); + return old.getValue(); } return null; } @@ -418,7 +417,7 @@ public abstract class AbstractLRUMap<K, V> if (me != null) { list.remove(me); - return me.getPayload(); + return me.getValue(); } } finally @@ -449,7 +448,7 @@ public abstract class AbstractLRUMap<K, V> public Collection<V> values() { return map.values().stream() - .map(LRUElementDescriptor::getPayload) + .map(LRUElementDescriptor::getValue) .collect(Collectors.toList()); } @@ -458,7 +457,6 @@ public abstract class AbstractLRUMap<K, V> * Checks to see if all the items that should be in the cache are. Checks consistency between * List and map. */ - @SuppressWarnings("unchecked") // No generics for public fields protected void verifyCache() { if ( !log.isTraceEnabled() ) @@ -469,7 +467,7 @@ public abstract class AbstractLRUMap<K, V> log.trace( "verifycache: mapContains {0} elements, linked list " + "contains {1} elements", map.size(), list.size() ); log.trace( "verifycache: checking linked list by key" ); - for (LRUElementDescriptor<K, V> li = list.getFirst(); li != null; li = (LRUElementDescriptor<K, V>) li.next ) + for (LRUElementDescriptor<K, V> li : list) { final K key = li.getKey(); if ( !map.containsKey( key ) ) @@ -496,7 +494,7 @@ public abstract class AbstractLRUMap<K, V> } log.trace( "verifycache: checking linked list by value " ); - for (LRUElementDescriptor<K, V> li3 = list.getFirst(); li3 != null; li3 = (LRUElementDescriptor<K, V>) li3.next ) + for (LRUElementDescriptor<K, V> li3 : list) { if (!map.containsValue(li3)) { @@ -508,7 +506,7 @@ public abstract class AbstractLRUMap<K, V> log.trace( "verifycache: checking via keysets!" ); map.keySet().stream() .filter(key -> { - for (LRUElementDescriptor<K, V> li2 = list.getFirst(); li2 != null; li2 = (LRUElementDescriptor<K, V>) li2.next ) + for (LRUElementDescriptor<K, V> li2 : list) { if ( key.equals( li2.getKey() ) ) { diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/DoubleLinkedListNode.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/DoubleLinkedListNode.java index 1595e339..2aafc938 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/DoubleLinkedListNode.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/DoubleLinkedListNode.java @@ -26,34 +26,15 @@ import java.io.Serializable; * add functionality. This allows you to remove in constant time from a linked * list. * <p> - * It simply holds the payload and a reference to the items before and after it + * It simply holds the reference to the items before and after it * in the list. */ -public class DoubleLinkedListNode<T> +public class DoubleLinkedListNode implements Serializable { /** Don't change. */ private static final long serialVersionUID = -1114934407695836097L; - /** The object in the node. */ - private final T payload; - /** Double Linked list references */ - public DoubleLinkedListNode<T> prev, next; - - /** - * @param payloadP - */ - public DoubleLinkedListNode(final T payloadP) - { - payload = payloadP; - } - - /** - * @return Object - */ - public T getPayload() - { - return payload; - } + public DoubleLinkedListNode prev, next; } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/LRUElementDescriptor.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/LRUElementDescriptor.java index 27a4eb2c..4a02710a 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/LRUElementDescriptor.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/struct/LRUElementDescriptor.java @@ -24,7 +24,7 @@ package org.apache.commons.jcs4.utils.struct; * the LRUMap class. */ public class LRUElementDescriptor<K, V> - extends DoubleLinkedListNode<V> + extends DoubleLinkedListNode { /** Don't change. */ private static final long serialVersionUID = 8249555756363020156L; @@ -32,14 +32,19 @@ public class LRUElementDescriptor<K, V> /** The key value */ private K key; + /** The value value */ + private V value; + /** + * Constructs a LRUElementDescriptor + * * @param key - * @param payloadP + * @param value */ - public LRUElementDescriptor(final K key, final V payloadP) + public LRUElementDescriptor(final K key, final V value) { - super(payloadP); this.key = key; + this.value = value; } /** @@ -49,4 +54,12 @@ public class LRUElementDescriptor<K, V> { return key; } + + /** + * @return The value. + */ + public V getValue() + { + return value; + } }
