You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2026/02/17 21:33:08 UTC
(commons-jcs) 03/04: Reduce code
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 743ad360cf73dfd402f1c8f970e3027b052a1183
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Tue Feb 17 20:11:58 2026 +0100
Reduce code
---
.../jcs4/engine/AbstractCacheEventQueue.java | 78 +++++++---------------
1 file changed, 24 insertions(+), 54 deletions(-)
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/AbstractCacheEventQueue.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/AbstractCacheEventQueue.java
index 6995f454..ad558b45 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/AbstractCacheEventQueue.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/AbstractCacheEventQueue.java
@@ -39,17 +39,20 @@ public abstract class AbstractCacheEventQueue<K, V>
*/
protected class AbstractCacheEvent<T> implements Runnable
{
- protected final T eventData;
+ private final String eventName;
+ private final T eventData;
private final IOExConsumer<T> eventRun;
/**
* Constructs a new instance.
*
+ * @param eventName name of the event
* @param eventData data of the event
* @param eventRun operation to apply on the event
*/
- protected AbstractCacheEvent(final T eventData, final IOExConsumer<T> eventRun)
+ protected AbstractCacheEvent(final String eventName, final T eventData, final IOExConsumer<T> eventRun)
{
+ this.eventName = eventName;
this.eventData = eventData;
this.eventRun = eventRun;
}
@@ -89,30 +92,16 @@ public abstract class AbstractCacheEventQueue<K, V>
+ "non-functional.", this );
destroy();
}
- }
-
- /**
- * The cache should be disposed when this event is processed.
- */
- protected class DisposeEvent extends AbstractCacheEvent<String>
- {
- /**
- * Constructor for the DisposeEvent object.
- */
- protected DisposeEvent()
- {
- super(cacheName, listener::handleDispose);
- }
/**
* For debugging.
*
- * @return The name of the event.
+ * @return Info on the key and value.
*/
@Override
public String toString()
{
- return "DisposeEvent";
+ return eventName + ": " + eventData.toString();
}
}
@@ -137,29 +126,32 @@ public abstract class AbstractCacheEventQueue<K, V>
}
/**
- * An element should be put in the cache.
+ * The cache should be disposed when this event is processed.
*/
- protected class PutEvent extends AbstractCacheEvent<ICacheElement<K, V>>
+ protected class DisposeEvent extends AbstractCacheEvent<String>
{
/**
- * Constructor for the PutEvent object.
- *
- * @param ice a cache element
+ * Constructor for the DisposeEvent object.
*/
- PutEvent( final ICacheElement<K, V> ice )
+ protected DisposeEvent()
{
- super(ice, listener::handlePut);
+ super("DisposeEvent", cacheName, listener::handleDispose);
}
+ }
+ /**
+ * An element should be put in the cache.
+ */
+ protected class PutEvent extends AbstractCacheEvent<ICacheElement<K, V>>
+ {
/**
- * For debugging.
+ * Constructor for the PutEvent object.
*
- * @return Info on the key and value.
+ * @param ice a cache element
*/
- @Override
- public String toString()
+ PutEvent( final ICacheElement<K, V> ice )
{
- return "PutEvent for key: " + eventData.key() + " value: " + eventData.value();
+ super("PutEvent", ice, listener::handlePut);
}
}
@@ -173,18 +165,7 @@ public abstract class AbstractCacheEventQueue<K, V>
*/
protected RemoveAllEvent()
{
- super(cacheName, listener::handleRemoveAll);
- }
-
- /**
- * For debugging.
- *
- * @return The name of the event.
- */
- @Override
- public String toString()
- {
- return "RemoveAllEvent";
+ super("RemoveAllEvent", cacheName, listener::handleRemoveAll);
}
}
@@ -200,18 +181,7 @@ public abstract class AbstractCacheEventQueue<K, V>
*/
RemoveEvent( final K key )
{
- super(key, AbstractCacheEventQueue.this::remove);
- }
-
- /**
- * For debugging.
- *
- * @return Info on the key to remove.
- */
- @Override
- public String toString()
- {
- return "RemoveEvent for " + eventData;
+ super("RemoveEvent", key, AbstractCacheEventQueue.this::remove);
}
}