You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/07/10 01:23:33 UTC
(commons-jcs) 31/31: Use final
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit fd9b5de4705e091f77fc4a5f7b5d133792f5f794
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 9 19:53:22 2024 -0400
Use final
Use blocks
Remove useless or redundant parens
Use diamonds
Remove redundant keywords
Use else if
Add @Override
Use a for each loop instead of an iterator
Remove trailing whitespace
Use a switch instead of a cascading if else
---
.../jcs3/auxiliary/disk/jdbc/ShrinkerThread.java | 4 +-
.../jcs3/auxiliary/disk/jdbc/TableState.java | 2 +-
.../auxiliary/disk/jdbc/mysql/MySQLDiskCache.java | 8 +-
.../disk/jdbc/mysql/MySQLDiskCacheFactory.java | 2 +-
.../disk/jdbc/mysql/MySQLTableOptimizer.java | 10 +-
.../disk/jdbc/mysql/util/ScheduleParser.java | 2 +-
.../socket/tcp/TCPLateralCacheAttributes.java | 2 +-
.../commons/jcs3/auxiliary/remote/RemoteCache.java | 6 +-
.../jcs3/auxiliary/remote/RemoteCacheFactory.java | 6 +-
.../jcs3/auxiliary/remote/RemoteCacheManager.java | 14 +-
.../jcs3/auxiliary/remote/RemoteCacheMonitor.java | 4 +-
.../commons/jcs3/auxiliary/remote/RemoteUtils.java | 2 +-
.../remote/http/server/RemoteHttpCacheServlet.java | 2 +-
.../auxiliary/remote/server/RemoteCacheServer.java | 2 +-
.../remote/server/RemoteCacheServerAttributes.java | 16 +-
.../remote/server/RemoteCacheServerFactory.java | 6 +-
.../commons/jcs3/engine/PooledCacheEventQueue.java | 6 +-
.../jcs3/io/ObjectInputStreamClassLoaderAware.java | 8 +-
.../commons/jcs3/utils/config/OptionConverter.java | 42 ++--
.../commons/jcs3/utils/config/PropertySetter.java | 2 +-
.../utils/discovery/UDPDiscoveryAttributes.java | 14 +-
.../jcs3/utils/discovery/UDPDiscoveryReceiver.java | 22 +-
.../jcs3/utils/discovery/UDPDiscoverySender.java | 2 +-
.../jcs3/utils/discovery/UDPDiscoveryService.java | 28 ++-
.../commons/jcs3/access/TestCacheAccess.java | 59 +++---
.../lateral/socket/tcp/TestTCPLateralUnitTest.java | 6 +-
.../remote/RemoteCacheNoWaitFacadeUnitTest.java | 2 +-
.../auxiliary/remote/TestRemoteCacheFactory.java | 6 +-
.../engine/control/MockCompositeCacheManager.java | 2 +-
.../jcs3/engine/memory/MockMemoryCache.java | 8 +-
.../UDPDiscoverySenderEncryptedUnitTest.java | 8 +-
.../discovery/UDPDiscoverySenderUnitTest.java | 6 +-
.../jcs3/utils/discovery/UDPDiscoveryUnitTest.java | 2 +-
.../commons/jcs3/utils/props/PropertyLoader.java | 2 +-
.../serialization/StandardSerializerUnitTest.java | 6 +-
.../jcs/yajcache/config/PerCacheConfig.java | 4 +-
.../jcs/yajcache/config/YajCacheConfig.java | 2 +-
.../jcs/yajcache/core/SafeCacheWrapper.java | 79 ++++---
.../commons/jcs/yajcache/soft/SoftRefCache.java | 139 ++++++++-----
.../jcs/yajcache/soft/SoftRefFileCache.java | 228 ++++++++++++---------
.../jcs/yajcache/core/SafeCacheManagerTest.java | 30 +--
.../jcs/yajcache/soft/SoftRefCacheTest.java | 4 +-
.../yajcache/soft/SoftRefFileCacheSafeTest.java | 4 +-
.../jcs/yajcache/util/SerializeUtilsTest.java | 32 +--
.../jcs/yajcache/util/TestSerializable.java | 8 +-
45 files changed, 458 insertions(+), 391 deletions(-)
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/ShrinkerThread.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/ShrinkerThread.java
index 10a24624..a41fef73 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/ShrinkerThread.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/ShrinkerThread.java
@@ -92,11 +92,11 @@ public class ShrinkerThread
if ( i.hasNext() )
{
log.info( "Pausing for [{0}] ms before shrinking the next region.",
- this.getPauseBetweenRegionCallsMillis() );
+ getPauseBetweenRegionCallsMillis() );
try
{
- Thread.sleep( this.getPauseBetweenRegionCallsMillis() );
+ Thread.sleep( getPauseBetweenRegionCallsMillis() );
}
catch ( final InterruptedException e )
{
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/TableState.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/TableState.java
index ce7ef413..3f4cc77e 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/TableState.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/TableState.java
@@ -58,7 +58,7 @@ public class TableState
*/
public TableState( final String tableName )
{
- this.setTableName( tableName );
+ setTableName( tableName );
}
/**
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
index ec1668f8..838a0cb0 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
@@ -76,7 +76,7 @@ public class MySQLDiskCache<K, V>
@Override
protected int deleteExpired()
{
- if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
+ if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return -1;
@@ -94,7 +94,7 @@ public class MySQLDiskCache<K, V>
@Override
protected ICacheElement<K, V> processGet( final K key )
{
- if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
+ if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return null;
@@ -112,7 +112,7 @@ public class MySQLDiskCache<K, V>
@Override
protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern )
{
- if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
+ if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return null;
@@ -129,7 +129,7 @@ public class MySQLDiskCache<K, V>
@Override
protected void processUpdate( final ICacheElement<K, V> element )
{
- if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
+ if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return;
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
index 0a22e591..c0c2fc1c 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
@@ -136,7 +136,7 @@ public class MySQLDiskCacheFactory
// can“t be null, otherwise ScheduleParser.createDatesForSchedule will throw ParseException
final Date[] dates = ScheduleParser.createDatesForSchedule( attributes.getOptimizationSchedule() );
for (final Date date : dates) {
- this.scheduleOptimization( date, optimizer );
+ scheduleOptimization( date, optimizer );
}
}
catch ( final ParseException e )
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
index 57eb91b8..a608e762 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
@@ -165,14 +165,14 @@ public class MySQLTableOptimizer
try
{
tableState.setState( TableState.OPTIMIZATION_RUNNING );
- log.info( "Optimizing table [{0}]", this.getTableName());
+ log.info( "Optimizing table [{0}]", getTableName());
try (Connection con = dataSource.getConnection())
{
// TEST
try (Statement sStatement = con.createStatement())
{
- try (ResultSet rs = sStatement.executeQuery( "optimize table " + this.getTableName() ))
+ try (ResultSet rs = sStatement.executeQuery( "optimize table " + getTableName() ))
{
// first row is error, then status
// if there is only one row in the result set, everything
@@ -204,12 +204,12 @@ public class MySQLTableOptimizer
// log the table status
final String statusString = getTableStatus( sStatement );
log.info( "Table status after optimizing table [{0}]: {1}",
- this.getTableName(), statusString );
+ getTableName(), statusString );
}
catch ( final SQLException e )
{
log.error( "Problem optimizing table [{0}]",
- this.getTableName(), e );
+ getTableName(), e );
return false;
}
}
@@ -246,7 +246,7 @@ public class MySQLTableOptimizer
// if( message != null && message.indexOf( ) )
final StringBuilder repairString = new StringBuilder();
- try (ResultSet repairResult = sStatement.executeQuery( "repair table " + this.getTableName()))
+ try (ResultSet repairResult = sStatement.executeQuery( "repair table " + getTableName()))
{
final int numColumns = repairResult.getMetaData().getColumnCount();
while ( repairResult.next() )
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/util/ScheduleParser.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/util/ScheduleParser.java
index a7453824..6a93c069 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/util/ScheduleParser.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/util/ScheduleParser.java
@@ -48,7 +48,7 @@ public class ScheduleParser
final String[] timeStrings = schedule.split("\\s*,\\s*");
final Date[] dates = new Date[timeStrings.length];
int cnt = 0;
- for (String time : timeStrings)
+ for (final String time : timeStrings)
{
dates[cnt++] = getDateForSchedule(time);
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
index c5f4ed9b..4d850f67 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java
@@ -429,6 +429,6 @@ public class TCPLateralCacheAttributes
@Override
public String toString()
{
- return this.getTcpServer() + ":" + this.getTcpListenerPort();
+ return getTcpServer() + ":" + getTcpListenerPort();
}
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCache.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCache.java
index 0b21d4d9..3c9ed8c9 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCache.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCache.java
@@ -105,9 +105,9 @@ public class RemoteCache<K, V>
protected String getIPAddressForService()
{
String ipAddress = "(null)";
- if (this.getRemoteCacheAttributes().getRemoteLocation() != null)
+ if (getRemoteCacheAttributes().getRemoteLocation() != null)
{
- ipAddress = this.getRemoteCacheAttributes().getRemoteLocation().toString();
+ ipAddress = getRemoteCacheAttributes().getRemoteLocation().toString();
}
return ipAddress;
}
@@ -124,7 +124,7 @@ public class RemoteCache<K, V>
final ArrayList<IStatElement<?>> elems = new ArrayList<>();
elems.add(new StatElement<>( "Remote Host:Port", getIPAddressForService() ) );
- elems.add(new StatElement<>( "Remote Type", this.getRemoteCacheAttributes().getRemoteTypeName() ) );
+ elems.add(new StatElement<>( "Remote Type", getRemoteCacheAttributes().getRemoteTypeName() ) );
// if ( this.getRemoteCacheAttributes().getRemoteType() == RemoteType.CLUSTER )
// {
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
index b5bef665..260e7f3c 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
@@ -91,7 +91,7 @@ public class RemoteCacheFactory
if (failoverList != null && !failoverList.isEmpty())
{
final String[] failoverServers = failoverList.split("\\s*,\\s*");
- for (String server : failoverServers)
+ for (final String server : failoverServers)
{
final RemoteLocation location = RemoteLocation.parseServerAndPort(server);
@@ -121,7 +121,7 @@ public class RemoteCacheFactory
case CLUSTER:
// REGISTER LISTENERS FOR EACH SYSTEM CLUSTERED CACHEs
final String[] clusterServers = rca.getClusterServers().split("\\s*,\\s*");
- for (String server: clusterServers)
+ for (final String server: clusterServers)
{
if (server.isEmpty())
{
@@ -220,7 +220,7 @@ public class RemoteCacheFactory
return managers.computeIfAbsent(rca.getRemoteLocation(), key -> {
- RemoteCacheManager manager = new RemoteCacheManager(rca, cacheMgr, monitor, cacheEventLogger, elementSerializer);
+ final RemoteCacheManager manager = new RemoteCacheManager(rca, cacheMgr, monitor, cacheEventLogger, elementSerializer);
monitor.addManager(manager);
return manager;
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheManager.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheManager.java
index 25a1af8d..5e2eeb13 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheManager.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheManager.java
@@ -320,18 +320,14 @@ public class RemoteCacheManager
if ( cache != null )
{
removeListenerFromCache(cache);
+ } else if ( cattr.isReceive() )
+ {
+ log.warn( "Trying to deregister Cache Listener that was never registered." );
}
else
{
- if ( cattr.isReceive() )
- {
- log.warn( "Trying to deregister Cache Listener that was never registered." );
- }
- else
- {
- log.debug( "Since the remote cache is configured to not receive, "
- + "there is no listener to deregister." );
- }
+ log.debug( "Since the remote cache is configured to not receive, "
+ + "there is no listener to deregister." );
}
}
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheMonitor.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheMonitor.java
index 807bebec..fee54aba 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheMonitor.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheMonitor.java
@@ -58,9 +58,9 @@ public class RemoteCacheMonitor extends AbstractAuxiliaryCacheMonitor
this.managers.put(manager, manager);
// if not yet started, go ahead
- if (this.getState() == Thread.State.NEW)
+ if (getState() == Thread.State.NEW)
{
- this.start();
+ start();
}
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteUtils.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteUtils.java
index 223a472a..c56cc058 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteUtils.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteUtils.java
@@ -211,7 +211,7 @@ public class RemoteUtils
if (null == is) // not found in class path
{
- Path propPath = Paths.get(propFile);
+ final Path propPath = Paths.get(propFile);
if (Files.exists(propPath))
{
// file found
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheServlet.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
index 17eeb470..61339e04 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
@@ -153,7 +153,7 @@ public class RemoteHttpCacheServlet
{
// not thread safe, but it doesn't have to be accurate
serviceCalls++;
- if ( log.isInfoEnabled() && (serviceCalls % logInterval == 0) )
+ if ( log.isInfoEnabled() && serviceCalls % logInterval == 0 )
{
log.info( "serviceCalls = {0}", serviceCalls );
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
index 74228d07..ecc58922 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
@@ -821,7 +821,7 @@ public class RemoteCacheServer<K, V>
// not thread safe, but it doesn't have to be 100% accurate
puts++;
- if ( log.isInfoEnabled() && (puts % logInterval == 0) )
+ if ( log.isInfoEnabled() && puts % logInterval == 0 )
{
log.info( "puts = {0}", puts );
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
index c2437a56..0f3e8ef2 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
@@ -168,14 +168,14 @@ public class RemoteCacheServerAttributes
public String toString()
{
final StringBuilder buf = new StringBuilder(super.toString());
- buf.append( "\n servicePort = [" + this.getServicePort() + "]" );
- buf.append( "\n allowClusterGet = [" + this.isAllowClusterGet() + "]" );
- buf.append( "\n configFileName = [" + this.getConfigFileName() + "]" );
- buf.append( "\n rmiSocketFactoryTimeoutMillis = [" + this.getRmiSocketFactoryTimeoutMillis() + "]" );
- buf.append( "\n useRegistryKeepAlive = [" + this.isUseRegistryKeepAlive() + "]" );
- buf.append( "\n registryKeepAliveDelayMillis = [" + this.getRegistryKeepAliveDelayMillis() + "]" );
- buf.append( "\n eventQueueType = [" + this.getEventQueueType() + "]" );
- buf.append( "\n eventQueuePoolName = [" + this.getEventQueuePoolName() + "]" );
+ buf.append( "\n servicePort = [" + getServicePort() + "]" );
+ buf.append( "\n allowClusterGet = [" + isAllowClusterGet() + "]" );
+ buf.append( "\n configFileName = [" + getConfigFileName() + "]" );
+ buf.append( "\n rmiSocketFactoryTimeoutMillis = [" + getRmiSocketFactoryTimeoutMillis() + "]" );
+ buf.append( "\n useRegistryKeepAlive = [" + isUseRegistryKeepAlive() + "]" );
+ buf.append( "\n registryKeepAliveDelayMillis = [" + getRegistryKeepAliveDelayMillis() + "]" );
+ buf.append( "\n eventQueueType = [" + getEventQueueType() + "]" );
+ buf.append( "\n eventQueuePoolName = [" + getEventQueuePoolName() + "]" );
return buf.toString();
}
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
index 6add75eb..3d8b7ddb 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
@@ -155,9 +155,9 @@ public class RemoteCacheServerFactory
* @param cacheEventLogger the event logger for error messages
* @since 3.1
*/
- protected static void keepAlive(String registryHost, int registryPort, ICacheEventLogger cacheEventLogger)
+ protected static void keepAlive(final String registryHost, final int registryPort, final ICacheEventLogger cacheEventLogger)
{
- String namingURL = RemoteUtils.getNamingURL(registryHost, registryPort, serviceName);
+ final String namingURL = RemoteUtils.getNamingURL(registryHost, registryPort, serviceName);
log.debug( "looking up server {0}", namingURL );
try
@@ -422,7 +422,7 @@ public class RemoteCacheServerFactory
* @param props
* @throws IOException
*/
- public static void startup( String host, final int port, final Properties props)
+ public static void startup( final String host, final int port, final Properties props)
throws IOException
{
if ( remoteCacheServer != null )
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java
index 6652194c..e258dbf2 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/PooledCacheEventQueue.java
@@ -82,7 +82,7 @@ public class PooledCacheEventQueue<K, V>
{
// this will share the same pool with other event queues by default.
return ThreadPoolManager.getInstance().getExecutorService(
- (threadPoolName == null) ? "cache_event_queue" : threadPoolName );
+ threadPoolName == null ? "cache_event_queue" : threadPoolName );
}
/**
@@ -91,7 +91,7 @@ public class PooledCacheEventQueue<K, V>
* @param waitSeconds number of seconds to wait for the queue to drain
*/
@Override
- public synchronized void destroy(int waitSeconds)
+ public synchronized void destroy(final int waitSeconds)
{
if ( isWorking() )
{
@@ -108,7 +108,7 @@ public class PooledCacheEventQueue<K, V>
this::getStatistics);
}
}
- catch (InterruptedException e)
+ catch (final InterruptedException e)
{
// ignore
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
index afc11ea8..33151640 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
@@ -26,15 +26,15 @@ import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy;
/**
- * ObjectInputStream implementation that allows to specify a class loader for deserializing
+ * ObjectInputStream implementation that allows to specify a class loader for deserializing
* objects
- *
+ *
* The class also evaluates the system property <code>jcs.serialization.class.filter</code>
* to define a list of classes that are allowed to be de-serialized. The filter value
* is directly fed into {@link java.io.ObjectInputFilter.Config#createFilter(String)}
* See the syntax documentation there.
*/
-public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
+public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
{
public static final String SYSTEM_PROPERTY_SERIALIZATION_FILTER = "jcs.serialization.class.filter";
@@ -44,7 +44,7 @@ public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
private final ClassLoader classLoader;
- public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
+ public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
{
super(in);
setObjectInputFilter(ObjectInputFilter.Config.createFilter(filter));
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
index 9b0171cb..bce0504e 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
@@ -82,37 +82,33 @@ public class OptionConverter
if ( c == '\\' )
{
c = s.charAt( i++ );
- if ( c == 'n' )
- {
+ switch (c) {
+ case 'n':
c = '\n';
- }
- else if ( c == 'r' )
- {
+ break;
+ case 'r':
c = '\r';
- }
- else if ( c == 't' )
- {
+ break;
+ case 't':
c = '\t';
- }
- else if ( c == 'f' )
- {
+ break;
+ case 'f':
c = '\f';
- }
- else if ( c == '\b' )
- {
+ break;
+ case '\b':
c = '\b';
- }
- else if ( c == '\"' )
- {
+ break;
+ case '\"':
c = '\"';
- }
- else if ( c == '\'' )
- {
+ break;
+ case '\'':
c = '\'';
- }
- else if ( c == '\\' )
- {
+ break;
+ case '\\':
c = '\\';
+ break;
+ default:
+ break;
}
}
sb.append( c );
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java
index aa571b45..dddf7b03 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/config/PropertySetter.java
@@ -124,7 +124,7 @@ public class PropertySetter
}
else if( type.isEnum() )
{
- Enum<?> valueOf = Enum.valueOf(type.asSubclass(Enum.class), v);
+ final Enum<?> valueOf = Enum.valueOf(type.asSubclass(Enum.class), v);
return valueOf;
}
else if ( File.class.isAssignableFrom( type ) )
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryAttributes.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryAttributes.java
index f1927598..e0443496 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryAttributes.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryAttributes.java
@@ -77,13 +77,13 @@ public final class UDPDiscoveryAttributes
public UDPDiscoveryAttributes clone()
{
final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes();
- attributes.setSendDelaySec( this.getSendDelaySec() );
- attributes.setMaxIdleTimeSec( this.getMaxIdleTimeSec() );
- attributes.setServiceName( this.getServiceName() );
- attributes.setServicePort( this.getServicePort() );
- attributes.setUdpDiscoveryAddr( this.getUdpDiscoveryAddr() );
- attributes.setUdpDiscoveryPort( this.getUdpDiscoveryPort() );
- attributes.setDark( this.isDark() );
+ attributes.setSendDelaySec( getSendDelaySec() );
+ attributes.setMaxIdleTimeSec( getMaxIdleTimeSec() );
+ attributes.setServiceName( getServiceName() );
+ attributes.setServicePort( getServicePort() );
+ attributes.setUdpDiscoveryAddr( getUdpDiscoveryAddr() );
+ attributes.setUdpDiscoveryPort( getUdpDiscoveryPort() );
+ attributes.setDark( isDark() );
return attributes;
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryReceiver.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryReceiver.java
index b003822c..91bfd416 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryReceiver.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryReceiver.java
@@ -198,7 +198,7 @@ public class UDPDiscoveryReceiver
/**
* Separate thread run when a command comes into the UDPDiscoveryReceiver.
*/
- private void handleMessage(UDPDiscoveryMessage message)
+ private void handleMessage(final UDPDiscoveryMessage message)
{
// consider comparing ports here instead.
if ( message.getRequesterId() == CacheInfo.listenerId )
@@ -233,20 +233,20 @@ public class UDPDiscoveryReceiver
while (!shutdown.get())
{
- int activeKeys = selector.select();
+ final int activeKeys = selector.select();
if (activeKeys == 0)
{
continue;
}
- for (Iterator<SelectionKey> i = selector.selectedKeys().iterator(); i.hasNext();)
+ for (final Iterator<SelectionKey> i = selector.selectedKeys().iterator(); i.hasNext();)
{
if (shutdown.get())
{
break;
}
- SelectionKey key = i.next();
+ final SelectionKey key = i.next();
i.remove();
if (!key.isValid())
@@ -259,19 +259,19 @@ public class UDPDiscoveryReceiver
cnt.incrementAndGet();
log.debug( "{0} messages received.", this::getCnt );
- DatagramChannel mc = (DatagramChannel) key.channel();
+ final DatagramChannel mc = (DatagramChannel) key.channel();
- ByteBuffer byteBuffer = ByteBuffer.allocate(65536);
- InetSocketAddress sourceAddress =
+ final ByteBuffer byteBuffer = ByteBuffer.allocate(65536);
+ final InetSocketAddress sourceAddress =
(InetSocketAddress) mc.receive(byteBuffer);
byteBuffer.flip();
try
{
log.debug("Received packet from address [{0}]", sourceAddress);
- byte[] bytes = new byte[byteBuffer.limit()];
+ final byte[] bytes = new byte[byteBuffer.limit()];
byteBuffer.get(bytes);
- Object obj = serializer.deSerialize(bytes, null);
+ final Object obj = serializer.deSerialize(bytes, null);
if (obj instanceof UDPDiscoveryMessage)
{
@@ -316,7 +316,7 @@ public class UDPDiscoveryReceiver
* @param serializer the serializer to set
* @since 3.1
*/
- protected void setSerializer(IElementSerializer serializer)
+ protected void setSerializer(final IElementSerializer serializer)
{
this.serializer = serializer;
}
@@ -327,7 +327,7 @@ public class UDPDiscoveryReceiver
* @param service the service to set
* @since 4.0
*/
- protected void setService(Consumer<UDPDiscoveryMessage> service)
+ protected void setService(final Consumer<UDPDiscoveryMessage> service)
{
this.service = service;
}
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySender.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySender.java
index e13d4874..4db09469 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySender.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySender.java
@@ -69,7 +69,7 @@ public class UDPDiscoverySender implements AutoCloseable
* @since 3.1
*/
public UDPDiscoverySender(final String mcastInterface, final String host,
- final int port, final int udpTTL, IElementSerializer serializer)
+ final int port, final int udpTTL, final IElementSerializer serializer)
throws IOException
{
try
diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
index 7a1862d9..8279f5bf 100644
--- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
+++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
@@ -98,14 +98,14 @@ public class UDPDiscoveryService
* @param serializer the serializer to use to send and receive messages
* @since 3.1
*/
- public UDPDiscoveryService(final UDPDiscoveryAttributes attributes, IElementSerializer serializer)
+ public UDPDiscoveryService(final UDPDiscoveryAttributes attributes, final IElementSerializer serializer)
{
this.udpDiscoveryAttributes = attributes.clone();
this.serializer = serializer;
try
{
- InetAddress multicastAddress = InetAddress.getByName(
+ final InetAddress multicastAddress = InetAddress.getByName(
getUdpDiscoveryAttributes().getUdpDiscoveryAddr());
// Set service address if still empty
@@ -128,7 +128,7 @@ public class UDPDiscoveryService
{
InetAddress serviceAddress = null;
- for (Enumeration<InetAddress> addresses = serviceInterface.getInetAddresses();
+ for (final Enumeration<InetAddress> addresses = serviceInterface.getInetAddresses();
addresses.hasMoreElements();)
{
serviceAddress = addresses.nextElement();
@@ -143,17 +143,13 @@ public class UDPDiscoveryService
// if Multicast uses IPv6, try to publish our IPv6 address
break;
}
- }
- else
+ } else if (serviceAddress instanceof Inet4Address &&
+ !serviceAddress.isLoopbackAddress() &&
+ !serviceAddress.isMulticastAddress() &&
+ serviceAddress.isSiteLocalAddress())
{
- if (serviceAddress instanceof Inet4Address &&
- !serviceAddress.isLoopbackAddress() &&
- !serviceAddress.isMulticastAddress() &&
- serviceAddress.isSiteLocalAddress())
- {
- // if Multicast uses IPv4, try to publish our IPv4 address
- break;
- }
+ // if Multicast uses IPv4, try to publish our IPv4 address
+ break;
}
}
@@ -386,7 +382,7 @@ public class UDPDiscoveryService
/**
* Process the incoming message.
*/
- protected void processMessage(UDPDiscoveryMessage message)
+ protected void processMessage(final UDPDiscoveryMessage message)
{
final DiscoveredService discoveredService = new DiscoveredService(message);
@@ -426,7 +422,7 @@ public class UDPDiscoveryService
sender.passiveBroadcast(
getUdpDiscoveryAttributes().getServiceAddress(),
getUdpDiscoveryAttributes().getServicePort(),
- this.getCacheNames() );
+ getCacheNames() );
log.debug( "Called sender to issue a passive broadcast" );
}
@@ -515,7 +511,7 @@ public class UDPDiscoveryService
sender.removeBroadcast(
getUdpDiscoveryAttributes().getServiceAddress(),
getUdpDiscoveryAttributes().getServicePort(),
- this.getCacheNames() );
+ getCacheNames() );
log.debug( "Called sender to issue a remove broadcast in shutdown." );
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/access/TestCacheAccess.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/access/TestCacheAccess.java
index 588b6e02..bb962f20 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/access/TestCacheAccess.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/access/TestCacheAccess.java
@@ -104,13 +104,9 @@ public class TestCacheAccess
if ( isSysOut )
{
System.out.println( s );
- }
- else
+ } else if ( log.isDebugEnabled() )
{
- if ( log.isDebugEnabled() )
- {
- log.debug( s );
- }
+ log.debug( s );
}
}
@@ -259,17 +255,18 @@ public class TestCacheAccess
{
tcnt++;
final String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
+ switch (tcnt) {
+ case 2:
num = Integer.parseInt( t.trim() );
- }
- else if ( tcnt == 3 )
- {
+ break;
+ case 3:
group = t.trim();
- }
- else if ( tcnt == 4 )
- {
+ break;
+ case 4:
show = Boolean.parseBoolean(t);
+ break;
+ default:
+ break;
}
}
@@ -315,17 +312,18 @@ public class TestCacheAccess
{
tcnt++;
final String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
+ switch (tcnt) {
+ case 2:
key = t.trim();
- }
- else if ( tcnt == 3 )
- {
+ break;
+ case 3:
group = t.trim();
- }
- else if ( tcnt == 4 )
- {
+ break;
+ case 4:
show = Boolean.parseBoolean(t);
+ break;
+ default:
+ break;
}
}
@@ -581,17 +579,18 @@ public class TestCacheAccess
{
tcnt++;
final String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
+ switch (tcnt) {
+ case 2:
rangeS = t.trim();
- }
- else if ( tcnt == 3 )
- {
+ break;
+ case 3:
numOpsS = t.trim();
- }
- else if ( tcnt == 4 )
- {
+ break;
+ case 4:
show = Boolean.parseBoolean(t);
+ break;
+ default:
+ break;
}
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
index 09da431a..e87c9ad0 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
@@ -52,7 +52,7 @@ public class TestTCPLateralUnitTest
{
private final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- private <K,V> CompositeCache<K, V> createCache(int port)
+ private <K,V> CompositeCache<K, V> createCache(final int port)
{
final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
lattr.setTcpListenerPort(port);
@@ -68,7 +68,7 @@ public class TestTCPLateralUnitTest
return cache;
}
- private <K, V> LateralTCPService<K, V> createService(int listenerPort, int serverPort, long listenerId) throws IOException
+ private <K, V> LateralTCPService<K, V> createService(final int listenerPort, final int serverPort, final long listenerId) throws IOException
{
final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
lattr2.setTcpListenerPort(listenerPort);
@@ -319,7 +319,7 @@ public class TestTCPLateralUnitTest
public void testSimpleEncryptedSend()
throws Exception
{
- EncryptingSerializer serializer = new EncryptingSerializer();
+ final EncryptingSerializer serializer = new EncryptingSerializer();
serializer.setPreSharedKey("my_key");
simpleSend(serializer, 8112);
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java
index 9349ec0e..1e9b958a 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheNoWaitFacadeUnitTest.java
@@ -81,7 +81,7 @@ public class RemoteCacheNoWaitFacadeUnitTest
assertEquals("Should have two failovers.", 2, cattr.getFailovers().size());
assertEquals("Should have two managers.", 2, factory.managers.size());
assertEquals("Should have primary server.", 0, cattr.getFailoverIndex());
- RemoteCacheNoWait<String, String> primary = facade.getPrimaryServer();
+ final RemoteCacheNoWait<String, String> primary = facade.getPrimaryServer();
assertEquals("Should be ALIVE", CacheStatus.ALIVE, primary.getStatus());
// Make primary unusable
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/TestRemoteCacheFactory.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/TestRemoteCacheFactory.java
index 9b31939b..9c6fc7da 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/TestRemoteCacheFactory.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/remote/TestRemoteCacheFactory.java
@@ -36,8 +36,8 @@ public class TestRemoteCacheFactory extends RemoteCacheFactory
// Mock
public class TestRemoteCacheManager extends RemoteCacheManager
{
- protected TestRemoteCacheManager(IRemoteCacheAttributes cattr, ICompositeCacheManager cacheMgr, RemoteCacheMonitor monitor, ICacheEventLogger cacheEventLogger,
- IElementSerializer elementSerializer)
+ protected TestRemoteCacheManager(final IRemoteCacheAttributes cattr, final ICompositeCacheManager cacheMgr, final RemoteCacheMonitor monitor, final ICacheEventLogger cacheEventLogger,
+ final IElementSerializer elementSerializer)
{
super(cattr, cacheMgr, monitor, cacheEventLogger, elementSerializer);
}
@@ -49,7 +49,7 @@ public class TestRemoteCacheFactory extends RemoteCacheFactory
}
@Override
- public void removeRemoteCacheListener(IRemoteCacheAttributes cattr) throws IOException
+ public void removeRemoteCacheListener(final IRemoteCacheAttributes cattr) throws IOException
{
// Skip
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/control/MockCompositeCacheManager.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/control/MockCompositeCacheManager.java
index 1252bf28..38b1c4fb 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/control/MockCompositeCacheManager.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/control/MockCompositeCacheManager.java
@@ -73,7 +73,7 @@ public class MockCompositeCacheManager
// System.out.println( "Creating mock cache" );
final CompositeCache<K, V> newCache =
new CompositeCache<>( new CompositeCacheAttributes(), new ElementAttributes() );
- this.setCache( newCache );
+ setCache( newCache );
}
return (CompositeCache<K, V>)cache;
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/memory/MockMemoryCache.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/memory/MockMemoryCache.java
index 33ce9fc3..5b1ee227 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/memory/MockMemoryCache.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/memory/MockMemoryCache.java
@@ -21,7 +21,6 @@ package org.apache.commons.jcs3.engine.memory;
import java.io.IOException;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -141,12 +140,7 @@ public class MockMemoryCache<K, V>
if ( keys != null && !keys.isEmpty() )
{
- final Iterator<K> iterator = keys.iterator();
-
- while ( iterator.hasNext() )
- {
- final K key = iterator.next();
-
+ for (K key : keys) {
final ICacheElement<K, V> element = get( key );
if ( element != null )
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderEncryptedUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderEncryptedUnitTest.java
index bb586b2c..7eca1bb7 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderEncryptedUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderEncryptedUnitTest.java
@@ -72,7 +72,7 @@ public class UDPDiscoverySenderEncryptedUnitTest
{
assumeNotNull("This machine does not support multicast", HostNameUtil.getMulticastNetworkInterface());
- EncryptingSerializer serializer = new EncryptingSerializer();
+ final EncryptingSerializer serializer = new EncryptingSerializer();
serializer.setPreSharedKey("my_key");
futureMsg = new CompletableFuture<>();
@@ -122,7 +122,7 @@ public class UDPDiscoverySenderEncryptedUnitTest
sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L );
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong port", SENDING_PORT, msg.getPort() );
assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() );
@@ -145,7 +145,7 @@ public class UDPDiscoverySenderEncryptedUnitTest
sender.removeBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L );
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong port", SENDING_PORT, msg.getPort() );
assertEquals( "wrong message type", BroadcastType.REMOVE, msg.getMessageType() );
@@ -164,7 +164,7 @@ public class UDPDiscoverySenderEncryptedUnitTest
sender.requestBroadcast(1L);
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() );
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderUnitTest.java
index a343ffde..9c1816e7 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoverySenderUnitTest.java
@@ -119,7 +119,7 @@ public class UDPDiscoverySenderUnitTest
sender.passiveBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L );
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong port", SENDING_PORT, msg.getPort() );
assertEquals( "wrong message type", BroadcastType.PASSIVE, msg.getMessageType() );
@@ -142,7 +142,7 @@ public class UDPDiscoverySenderUnitTest
sender.removeBroadcast( SENDING_HOST, SENDING_PORT, cacheNames, 1L );
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong port", SENDING_PORT, msg.getPort() );
assertEquals( "wrong message type", BroadcastType.REMOVE, msg.getMessageType() );
@@ -161,7 +161,7 @@ public class UDPDiscoverySenderUnitTest
sender.requestBroadcast(1L);
// VERIFY
- UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
+ final UDPDiscoveryMessage msg = futureMsg.get(3, TimeUnit.SECONDS);
assertNotNull("message not received", msg);
assertEquals( "wrong message type", BroadcastType.REQUEST, msg.getMessageType() );
}
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryUnitTest.java
index 1af70837..a243ba7f 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryUnitTest.java
@@ -38,7 +38,7 @@ public class UDPDiscoveryUnitTest
* <p>
* @throws Exception
*/
- private void simpleUDPDiscovery(String discoveryAddress)
+ private void simpleUDPDiscovery(final String discoveryAddress)
throws Exception
{
final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes();
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/props/PropertyLoader.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/props/PropertyLoader.java
index bf93f6a6..c9a631ee 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/props/PropertyLoader.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/props/PropertyLoader.java
@@ -103,7 +103,7 @@ public abstract class PropertyLoader
throw new IllegalArgumentException( "null input: name" );
}
- final ClassLoader classLoader = ( loader == null ) ? ClassLoader.getSystemClassLoader() : loader;
+ final ClassLoader classLoader = loader == null ? ClassLoader.getSystemClassLoader() : loader;
String fileName = name.startsWith( "/" ) ? name.substring( 1 ) : name;
diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/StandardSerializerUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/StandardSerializerUnitTest.java
index 31327919..4c45f3d8 100644
--- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/StandardSerializerUnitTest.java
+++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/StandardSerializerUnitTest.java
@@ -37,7 +37,7 @@ import org.junit.Test;
public class StandardSerializerUnitTest
{
private StandardSerializer serializer;
-
+
/**
* Test setup
* <p>
@@ -48,7 +48,7 @@ public class StandardSerializerUnitTest
throws Exception
{
// Override filter expression for ObjectInputFilter
- System.setProperty(ObjectInputStreamClassLoaderAware.SYSTEM_PROPERTY_SERIALIZATION_FILTER,
+ System.setProperty(ObjectInputStreamClassLoaderAware.SYSTEM_PROPERTY_SERIALIZATION_FILTER,
"!org.apache.commons.collections4.**");
this.serializer = new StandardSerializer();
}
@@ -117,7 +117,7 @@ public class StandardSerializerUnitTest
// VERIFY
assertEquals( "Before and after should be the same.", before, after );
}
-
+
/**
* Verify that we can filter classes to be deserialized
*<p>
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/PerCacheConfig.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/PerCacheConfig.java
index ebc888de..bcd1827e 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/PerCacheConfig.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/PerCacheConfig.java
@@ -29,8 +29,8 @@ import org.apache.commons.jcs.yajcache.lang.annotation.*;
public class PerCacheConfig {
private boolean isCacheFileEnabled = true;
- public boolean setCacheFileEnabled(boolean isCacheFileEnabled) {
- boolean ret = this.isCacheFileEnabled;
+ public boolean setCacheFileEnabled(final boolean isCacheFileEnabled) {
+ final boolean ret = this.isCacheFileEnabled;
this.isCacheFileEnabled = isCacheFileEnabled;
return ret;
}
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/YajCacheConfig.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/YajCacheConfig.java
index 4466bddd..a3a020aa 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/YajCacheConfig.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/config/YajCacheConfig.java
@@ -41,7 +41,7 @@ public enum YajCacheConfig {
public @NonNullable File getCacheDir() {
return cacheDir;
}
- void setCacheDir(File cacheDir) {
+ void setCacheDir(final File cacheDir) {
this.cacheDir = cacheDir;
this.cacheDir.mkdirs();
}
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/SafeCacheWrapper.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/SafeCacheWrapper.java
index cc5217ab..0d002d73 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/SafeCacheWrapper.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/SafeCacheWrapper.java
@@ -44,7 +44,7 @@ public class SafeCacheWrapper<V> implements ICacheSafe<V>
* Constructs a safe cache by wrapping an underlying cache.
* @param cache underlying cache.
*/
- public SafeCacheWrapper(@NonNullable ICache<V> cache)
+ public SafeCacheWrapper(@NonNullable final ICache<V> cache)
{
this.cache = cache;
@@ -62,94 +62,123 @@ public class SafeCacheWrapper<V> implements ICacheSafe<V>
// ICache implementation by delegating to the underlying cache.
+ @Override
public String getName() {
return this.cache.getName();
}
+ @Override
public Class<V> getValueType() {
return this.cache.getValueType();
}
- public V get(String key) {
+ @Override
+ public V get(final String key) {
return this.cache.get(key);
}
+ @Override
public int size() {
return this.cache.size();
}
+ @Override
public boolean isEmpty() {
return this.cache.isEmpty();
}
- public boolean containsKey(Object key) {
+ @Override
+ public boolean containsKey(final Object key) {
return this.cache.containsKey(key);
}
- public boolean containsValue(Object value) {
+ @Override
+ public boolean containsValue(final Object value) {
return this.cache.containsValue(value);
}
- public V get(Object key) {
+ @Override
+ public V get(final Object key) {
return this.cache.get(key);
}
- public V put(String key, V value) {
+ @Override
+ public V put(final String key, final V value) {
return this.cache.put(key, value);
}
- public V remove(Object key) {
+ @Override
+ public V remove(final Object key) {
return this.cache.remove(key);
}
+ @Override
public void clear() {
this.cache.clear();
}
+ @Override
public Set<String> keySet() {
return this.cache.keySet();
}
+ @Override
public Collection<V> values() {
return this.cache.values();
}
+ @Override
public Set<Map.Entry<String, V>> entrySet() {
return this.cache.entrySet();
}
// ICacheSafe implementation
- public V getCopy(@NonNullable String key) {
- V val = this.cache.get(key);
+ @Override
+ public V getCopy(@NonNullable final String key) {
+ final V val = this.cache.get(key);
return this.dup(val);
}
- public V putCopy(@NonNullable String key, @NonNullable V value) {
+ @Override
+ public V putCopy(@NonNullable final String key, @NonNullable final V value) {
return this.cache.put(key, this.dup(value));
}
- public void putAll(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAll(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.cache.put(e.getKey(), e.getValue());
+ }
}
- public void putAllCopies(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAllCopies(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.cache.put(e.getKey(), this.dup(e.getValue()));
+ }
}
- public V getBeanCopy(@NonNullable String key) {
- V val = this.cache.get(key);
+ @Override
+ public V getBeanCopy(@NonNullable final String key) {
+ final V val = this.cache.get(key);
return BeanUtils.inst.cloneDeep(val);
}
- public V putBeanCopy(@NonNullable String key, @NonNullable V value) {
+ @Override
+ public V putBeanCopy(@NonNullable final String key, @NonNullable final V value) {
return this.cache.put(key, BeanUtils.inst.cloneDeep(value));
}
- public void putAllBeanCopies(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAllBeanCopies(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.cache.put(e.getKey(), BeanUtils.inst.cloneDeep(e.getValue()));
+ }
}
- public V getBeanClone(@NonNullable String key) {
- V val = this.cache.get(key);
+ @Override
+ public V getBeanClone(@NonNullable final String key) {
+ final V val = this.cache.get(key);
return BeanUtils.inst.cloneShallow(val);
}
- public V putBeanClone(@NonNullable String key, @NonNullable V value) {
+ @Override
+ public V putBeanClone(@NonNullable final String key, @NonNullable final V value) {
return this.cache.put(key, BeanUtils.inst.cloneShallow(value));
}
- public void putAllBeanClones(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAllBeanClones(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.cache.put(e.getKey(), BeanUtils.inst.cloneShallow(e.getValue()));
+ }
}
- private V dup(V val) {
+ private V dup(final V val) {
if (val instanceof Serializable) {
return (V)SerializeUtils.inst.dup((Serializable)val);
}
return val;
}
+ @Override
@Implements(ICache.class)
public CacheType getCacheType() {
return this.cacheType;
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefCache.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefCache.java
index 5cae12ad..99b1f066 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefCache.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefCache.java
@@ -50,107 +50,120 @@ import java.util.concurrent.atomic.AtomicInteger;
@TODO("Annotate the thread-safetyness of the methods")
public class SoftRefCache<V> implements ICache<V> {
private static final boolean debug = true;
- private Log log = debug ? LogFactory.getLog(this.getClass()) : null;
- private final @NonNullable ReferenceQueue<V> refq = new ReferenceQueue<V>();
+ private final Log log = debug ? LogFactory.getLog(this.getClass()) : null;
+ private final @NonNullable ReferenceQueue<V> refq = new ReferenceQueue<>();
private final @NonNullable String name;
private final @NonNullable Class<V> valueType;
private final @NonNullable ConcurrentMap<String,KeyedSoftReference<String,V>> map;
private final @NonNullable KeyedRefCollector<String> collector;
private @NonNullable PerCacheConfig config;
- private AtomicInteger countGet = new AtomicInteger();
- private AtomicInteger countGetHitMemory = new AtomicInteger();
- private AtomicInteger countGetMiss = new AtomicInteger();
- private AtomicInteger countGetEmptyRef = new AtomicInteger();
+ private final AtomicInteger countGet = new AtomicInteger();
+ private final AtomicInteger countGetHitMemory = new AtomicInteger();
+ private final AtomicInteger countGetMiss = new AtomicInteger();
+ private final AtomicInteger countGetEmptyRef = new AtomicInteger();
- private AtomicInteger countPut = new AtomicInteger();
- private AtomicInteger countRemove = new AtomicInteger();
+ private final AtomicInteger countPut = new AtomicInteger();
+ private final AtomicInteger countRemove = new AtomicInteger();
/** Returns the cache name. */
+ @Override
public @NonNullable String getName() {
return this.name;
}
/** Returns the value type of the cache. */
+ @Override
public @NonNullable Class<V> getValueType() {
return this.valueType;
}
- public SoftRefCache(@NonNullable String name, @NonNullable Class<V> valueType,
- int initialCapacity, float loadFactor, int concurrencyLevel)
+ public SoftRefCache(@NonNullable final String name, @NonNullable final Class<V> valueType,
+ final int initialCapacity, final float loadFactor, final int concurrencyLevel)
{
this.map = CollectionUtils.inst.newConcurrentHashMap(initialCapacity, loadFactor, concurrencyLevel);
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
}
public SoftRefCache(
- @NonNullable String name,
- @NonNullable Class<V> valueType,
- int initialCapacity)
+ @NonNullable final String name,
+ @NonNullable final Class<V> valueType,
+ final int initialCapacity)
{
this.map = CollectionUtils.inst.newConcurrentHashMap(initialCapacity);
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
}
public SoftRefCache(
- @NonNullable String name,
- @NonNullable Class<V> valueType)
+ @NonNullable final String name,
+ @NonNullable final Class<V> valueType)
{
this.map = CollectionUtils.inst.newConcurrentHashMap();
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
}
+ @Override
public boolean isEmpty() {
this.collector.run();
return map.isEmpty();
}
+ @Override
public int size() {
this.collector.run();
return map.size();
}
- public V get(@NonNullable String key) {
- if (debug)
+ @Override
+ public V get(@NonNullable final String key) {
+ if (debug) {
this.countGet.incrementAndGet();
+ }
this.collector.run();
- KeyedSoftReference<String,V> ref = map.get(key);
+ final KeyedSoftReference<String,V> ref = map.get(key);
if (ref == null) {
- if (debug)
+ if (debug) {
this.countGetMiss.incrementAndGet();
+ }
return null;
}
- V val = ref.get();
+ final V val = ref.get();
if (val == null) {
// Rarely gets here, if ever.
// already garbage collected. So try to clean up the key.
- if (debug)
+ if (debug) {
this.countGetEmptyRef.incrementAndGet();
+ }
this.map.remove(key, ref);
}
// cache value exists.
// try to refresh the soft reference.
- if (debug)
+ if (debug) {
this.countGetHitMemory.incrementAndGet();
+ }
return val;
}
- public V get(@NonNullable Object key) {
+ @Override
+ public V get(@NonNullable final Object key) {
return key == null ? null : this.get(key.toString());
}
- public V put(@NonNullable String key, @NonNullable V value) {
- if (debug)
+ @Override
+ public V put(@NonNullable final String key, @NonNullable final V value) {
+ if (debug) {
this.countPut.incrementAndGet();
+ }
this.collector.run();
- KeyedSoftReference<String,V> oldRef =
- map.put(key, new KeyedSoftReference<String,V>(key, value, refq));
+ final KeyedSoftReference<String,V> oldRef =
+ map.put(key, new KeyedSoftReference<>(key, value, refq));
- if (oldRef == null)
+ if (oldRef == null) {
return null;
- V ret = oldRef.get();
+ }
+ final V ret = oldRef.get();
oldRef.clear();
if (!EqualsUtils.inst.equals(value, ret)) {
@@ -164,60 +177,69 @@ public class SoftRefCache<V> implements ICache<V> {
value="Queue up a flush event for the key.",
details="This is useful for synchronizing caches in a cluster environment."
)
- private void publishFlushKey(@NonNullable String key) {
+ private void publishFlushKey(@NonNullable final String key) {
}
- public void putAll(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAll(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.put(e.getKey(), e.getValue());
+ }
}
- public V remove(@NonNullable String key) {
- if (debug)
+ public V remove(@NonNullable final String key) {
+ if (debug) {
this.countRemove.incrementAndGet();
+ }
this.collector.run();
- KeyedSoftReference<String,V> oldRef = map.remove(key);
+ final KeyedSoftReference<String,V> oldRef = map.remove(key);
- if (oldRef == null)
+ if (oldRef == null) {
return null;
+ }
this.publishFlushKey(key);
- V ret = oldRef.get();
+ final V ret = oldRef.get();
oldRef.clear();
return ret;
}
- public V remove(@NonNullable Object key) {
+ @Override
+ public V remove(@NonNullable final Object key) {
return key == null ? null : this.remove(key.toString());
}
+ @Override
public void clear() {
this.collector.run();
map.clear();
}
+ @Override
public @NonNullable Set<String> keySet() {
this.collector.run();
return map.keySet();
}
+ @Override
public @NonNullable Set<Map.Entry<String,V>> entrySet() {
this.collector.run();
- Set<Map.Entry<String,KeyedSoftReference<String,V>>> fromSet = map.entrySet();
- Set<Map.Entry<String,V>> toSet = new HashSet<Map.Entry<String,V>>();
+ final Set<Map.Entry<String,KeyedSoftReference<String,V>>> fromSet = map.entrySet();
+ final Set<Map.Entry<String,V>> toSet = new HashSet<>();
for (final Map.Entry<String,KeyedSoftReference<String,V>> item : fromSet) {
- KeyedSoftReference<String,V> ref = item.getValue();
- V val = ref.get();
+ final KeyedSoftReference<String,V> ref = item.getValue();
+ final V val = ref.get();
if (val != null) {
- Map.Entry<String,V> e = new CacheEntry<V>(item.getKey(), val);
+ final Map.Entry<String,V> e = new CacheEntry<>(item.getKey(), val);
toSet.add(e);
}
}
return toSet;
}
+ @Override
public @NonNullable Collection<V> values() {
this.collector.run();
- Collection<KeyedSoftReference<String,V>> fromSet = map.values();
- List<V> toCol = new ArrayList<V>(fromSet.size());
+ final Collection<KeyedSoftReference<String,V>> fromSet = map.values();
+ final List<V> toCol = new ArrayList<>(fromSet.size());
for (final KeyedSoftReference<String,V> ref : fromSet) {
- V val = ref.get();
+ final V val = ref.get();
if (val != null) {
toCol.add(val);
@@ -225,20 +247,24 @@ public class SoftRefCache<V> implements ICache<V> {
}
return toCol;
}
- public boolean containsKey(@NonNullable Object key) {
- if (key == null)
+ @Override
+ public boolean containsKey(@NonNullable final Object key) {
+ if (key == null) {
return false;
+ }
return this.get(key.toString()) != null;
}
- public boolean containsValue(@NonNullable Object value) {
+ @Override
+ public boolean containsValue(@NonNullable final Object value) {
this.collector.run();
- Collection<KeyedSoftReference<String,V>> fromSet = map.values();
+ final Collection<KeyedSoftReference<String,V>> fromSet = map.values();
for (final KeyedSoftReference<String,V> ref : fromSet) {
- V val = ref.get();
+ final V val = ref.get();
- if (EqualsUtils.inst.equals(value, val))
+ if (EqualsUtils.inst.equals(value, val)) {
return true;
+ }
}
return false;
}
@@ -251,9 +277,10 @@ public class SoftRefCache<V> implements ICache<V> {
return config;
}
- void setConfig(@NonNullable PerCacheConfig config) {
+ void setConfig(@NonNullable final PerCacheConfig config) {
this.config = config;
}
+ @Override
@Implements(ICache.class)
public CacheType getCacheType() {
return CacheType.SOFT_REFERENCE;
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCache.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCache.java
index 96bd2cb1..c35f08e2 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCache.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCache.java
@@ -63,77 +63,80 @@ import java.util.concurrent.locks.Lock;
public class SoftRefFileCache<V> implements ICache<V>
{
private static final boolean debug = true;
- private Log log = debug ? LogFactory.getLog(this.getClass()) : null;
- private final @NonNullable ReferenceQueue<V> refq = new ReferenceQueue<V>();
+ private final Log log = debug ? LogFactory.getLog(this.getClass()) : null;
+ private final @NonNullable ReferenceQueue<V> refq = new ReferenceQueue<>();
private final @NonNullable String name;
private final @NonNullable Class<V> valueType;
private final @NonNullable ConcurrentMap<String,KeyedSoftReference<String,V>> map;
private PerCacheConfig config;
private final @NonNullable KeyedRefCollector<String> collector;
- private final IKeyedReadWriteLock<String> keyedRWLock = new KeyedReadWriteLock<String>();
+ private final IKeyedReadWriteLock<String> keyedRWLock = new KeyedReadWriteLock<>();
private final @NonNullable CacheChangeSupport<V> cacheChangeSupport =
- new CacheChangeSupport<V>(this);
+ new CacheChangeSupport<>(this);
- private AtomicInteger countGet = new AtomicInteger();
+ private final AtomicInteger countGet = new AtomicInteger();
- private AtomicInteger countGetHitMemory = new AtomicInteger();
- private AtomicInteger countGetHitFile = new AtomicInteger();
+ private final AtomicInteger countGetHitMemory = new AtomicInteger();
+ private final AtomicInteger countGetHitFile = new AtomicInteger();
- private AtomicInteger countGetMissMemory = new AtomicInteger();
- private AtomicInteger countGetMiss = new AtomicInteger();
- private AtomicInteger countGetCorruptedFile = new AtomicInteger();
- private AtomicInteger countGetEmptyRef = new AtomicInteger();
+ private final AtomicInteger countGetMissMemory = new AtomicInteger();
+ private final AtomicInteger countGetMiss = new AtomicInteger();
+ private final AtomicInteger countGetCorruptedFile = new AtomicInteger();
+ private final AtomicInteger countGetEmptyRef = new AtomicInteger();
- private AtomicInteger countPut = new AtomicInteger();
- private AtomicInteger countPutClearRef = new AtomicInteger();
- private AtomicInteger countPutMissMemory = new AtomicInteger();
- private AtomicInteger countPutNewMemoryValue = new AtomicInteger();
- private AtomicInteger countPutNewFileValue = new AtomicInteger();
- private AtomicInteger countPutSerializable = new AtomicInteger();
- private AtomicInteger countPutReadFile = new AtomicInteger();
- private AtomicInteger countPutWriteFile = new AtomicInteger();
+ private final AtomicInteger countPut = new AtomicInteger();
+ private final AtomicInteger countPutClearRef = new AtomicInteger();
+ private final AtomicInteger countPutMissMemory = new AtomicInteger();
+ private final AtomicInteger countPutNewMemoryValue = new AtomicInteger();
+ private final AtomicInteger countPutNewFileValue = new AtomicInteger();
+ private final AtomicInteger countPutSerializable = new AtomicInteger();
+ private final AtomicInteger countPutReadFile = new AtomicInteger();
+ private final AtomicInteger countPutWriteFile = new AtomicInteger();
- private AtomicInteger countRemove = new AtomicInteger();
+ private final AtomicInteger countRemove = new AtomicInteger();
+ @Override
public @NonNullable String getName() {
return this.name;
}
+ @Override
public @NonNullable Class<V> getValueType() {
return this.valueType;
}
public SoftRefFileCache(
- @NonNullable String name, @NonNullable Class<V> valueType,
- int initialCapacity, float loadFactor, int concurrencyLevel)
+ @NonNullable final String name, @NonNullable final Class<V> valueType,
+ final int initialCapacity, final float loadFactor, final int concurrencyLevel)
{
this.map = CollectionUtils.inst.newConcurrentHashMap(initialCapacity, loadFactor, concurrencyLevel);
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
CacheFileUtils.inst.mkCacheDirs(this.name);
}
public SoftRefFileCache(
- @NonNullable String name, @NonNullable Class<V> valueType,
- int initialCapacity)
+ @NonNullable final String name, @NonNullable final Class<V> valueType,
+ final int initialCapacity)
{
this.map = CollectionUtils.inst.newConcurrentHashMap(initialCapacity);
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
CacheFileUtils.inst.mkCacheDirs(this.name);
}
- public SoftRefFileCache(@NonNullable String name,
- @NonNullable Class<V> valueType)
+ public SoftRefFileCache(@NonNullable final String name,
+ @NonNullable final Class<V> valueType)
{
this.map = CollectionUtils.inst.newConcurrentHashMap();
- this.collector = new KeyedRefCollector<String>(refq, map);
+ this.collector = new KeyedRefCollector<>(refq, map);
this.name = name;
this.valueType = valueType;
CacheFileUtils.inst.mkCacheDirs(this.name);
}
/** Only an approximation. */
+ @Override
public boolean isEmpty() {
return this.isMemoryCacheEmpty() && this.isCacheDirEmpty();
}
@@ -142,7 +145,7 @@ public class SoftRefFileCache<V> implements ICache<V>
return this.map.isEmpty();
}
public boolean isCacheDirEmpty() {
- Lock cacheLock = CacheManager.inst.readLock(this);
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
return CacheFileUtils.inst.isCacheDirEmpty(this.name);
@@ -150,6 +153,7 @@ public class SoftRefFileCache<V> implements ICache<V>
cacheLock.unlock();
}
}
+ @Override
public int size() {
return Math.max(this.getMemoryCacheSize(), this.getCacheDirSize());
}
@@ -158,7 +162,7 @@ public class SoftRefFileCache<V> implements ICache<V>
return this.map.size();
}
public int getCacheDirSize() {
- Lock cacheLock = CacheManager.inst.readLock(this);
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
return CacheFileUtils.inst.getCacheDirSize(this.name);
@@ -170,14 +174,16 @@ public class SoftRefFileCache<V> implements ICache<V>
// @tothink: SoftReference.get() doesn't seem to be thread-safe.
// But do we really want to synchronize upon invoking get() ?
// It's not thread-safe, but what's the worst consequence ?
- public V get(@NonNullable String key) {
+ @Override
+ public V get(@NonNullable final String key) {
collector.run();
- if (debug)
+ if (debug) {
this.countGet.incrementAndGet();
- Lock cacheLock = CacheManager.inst.readLock(this);
+ }
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
- Lock lock = this.keyedRWLock.readLock(key);
+ final Lock lock = this.keyedRWLock.readLock(key);
lock.lock();
try {
return doGet(key);
@@ -188,21 +194,18 @@ public class SoftRefFileCache<V> implements ICache<V>
cacheLock.unlock();
}
}
- private V doGet(String key) {
- KeyedSoftReference<String,V> ref = map.get(key);
+ private V doGet(final String key) {
+ final KeyedSoftReference<String,V> ref = map.get(key);
V val = null;
if (ref != null) {
val = ref.get();
- if (debug) {
- if (val == null)
- this.countGetEmptyRef.incrementAndGet();
+ if (debug && (val == null)) {
+ this.countGetEmptyRef.incrementAndGet();
}
- }
- else {
- if (debug)
- this.countGetMissMemory.incrementAndGet();
+ } else if (debug) {
+ this.countGetMissMemory.incrementAndGet();
}
if (val == null) {
// Not in memory.
@@ -211,34 +214,35 @@ public class SoftRefFileCache<V> implements ICache<V>
// GC'd. So try to clean up the key/ref pair.
this.map.remove(key, ref);
}
- CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
+ final CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
if (cfc == null) {
// Not in file system.
- if (debug)
+ if (debug) {
this.countGetMiss.incrementAndGet();
+ }
return null;
}
// Found in file system.
- if (debug)
+ if (debug) {
this.countGetHitFile.incrementAndGet();
+ }
val = (V)cfc.deserialize();
if (val == null) {
// Corrupted file. Try remove it from file system.
- if (debug)
+ if (debug) {
this.countGetCorruptedFile.incrementAndGet();
+ }
// Don't think I need to put a read lock on the cache for removal.
CacheFileDAO.inst.removeCacheItem(this.name, key);
return null;
}
// Resurrect item back to memory.
map.putIfAbsent(key,
- new KeyedSoftReference<String,V>(key, val, refq));
- }
- else {
- if (debug)
- this.countGetHitMemory.incrementAndGet();
+ new KeyedSoftReference<>(key, val, refq));
+ } else if (debug) {
+ this.countGetHitMemory.incrementAndGet();
}
// cache value exists.
return val;
@@ -283,18 +287,21 @@ public class SoftRefFileCache<V> implements ICache<V>
// return;
// }
- public V get(@NonNullable Object key) {
+ @Override
+ public V get(@NonNullable final Object key) {
return this.get(key.toString());
}
- public V put(@NonNullable String key, @NonNullable V value) {
+ @Override
+ public V put(@NonNullable final String key, @NonNullable final V value) {
this.collector.run();
- if (debug)
+ if (debug) {
this.countPut.incrementAndGet();
- Lock cacheLock = CacheManager.inst.readLock(this);
+ }
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
- Lock lock = this.keyedRWLock.writeLock(key);
+ final Lock lock = this.keyedRWLock.writeLock(key);
lock.lock();
try {
return doPut(key, value);
@@ -305,31 +312,35 @@ public class SoftRefFileCache<V> implements ICache<V>
cacheLock.unlock();
}
}
- private V doPut(@NonNullable String key, @NonNullable V value) {
- KeyedSoftReference<String,V> oldRef =
- map.put(key, new KeyedSoftReference<String,V>(key, value, refq));
+ private V doPut(@NonNullable final String key, @NonNullable final V value) {
+ final KeyedSoftReference<String,V> oldRef =
+ map.put(key, new KeyedSoftReference<>(key, value, refq));
V ret = null;
if (oldRef != null) {
ret = oldRef.get();
oldRef.clear();
- if (debug)
+ if (debug) {
this.countPutClearRef.incrementAndGet();
+ }
}
if (ret == null) {
// Not in memory.
- if (debug)
+ if (debug) {
this.countPutMissMemory.incrementAndGet();
+ }
if (value instanceof Serializable) {
// Try the file system.
- if (debug)
+ if (debug) {
this.countPutSerializable.incrementAndGet();
- CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
+ }
+ final CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
if (cfc != null) {
- if (debug)
+ if (debug) {
this.countPutReadFile.incrementAndGet();
+ }
ret = (V)cfc.deserialize();
}
if (!EqualsUtils.inst.equals(value, ret)) {
@@ -339,7 +350,7 @@ public class SoftRefFileCache<V> implements ICache<V>
this.countPutNewFileValue.incrementAndGet();
this.countPutWriteFile.incrementAndGet();
}
- byte[] ba = SerializationUtils.serialize((Serializable)value);
+ final byte[] ba = SerializationUtils.serialize((Serializable)value);
CacheFileDAO.inst.writeCacheItem(
this.name, CacheFileContentType.JAVA_SERIALIZATION, key, ba);
}
@@ -349,8 +360,9 @@ public class SoftRefFileCache<V> implements ICache<V>
// ret must be non-null.
// Found in memory
if (!EqualsUtils.inst.equals(value, ret)) {
- if (debug)
+ if (debug) {
this.countPutNewMemoryValue.incrementAndGet();
+ }
// Different value being put to memory.
if (value instanceof Serializable) {
// Persist to file system.
@@ -358,7 +370,7 @@ public class SoftRefFileCache<V> implements ICache<V>
this.countPutSerializable.incrementAndGet();
this.countPutWriteFile.incrementAndGet();
}
- byte[] ba = SerializationUtils.serialize((Serializable)value);
+ final byte[] ba = SerializationUtils.serialize((Serializable)value);
CacheFileDAO.inst.writeCacheItem(
this.name, CacheFileContentType.JAVA_SERIALIZATION, key, ba);
}
@@ -370,22 +382,25 @@ public class SoftRefFileCache<V> implements ICache<V>
value="Queue up a flush beans for the key.",
details="This is useful for synchronizing caches in a cluster environment."
)
- private void publishFlushKey(@NonNullable String key) {
+ private void publishFlushKey(@NonNullable final String key) {
}
- public void putAll(@NonNullable Map<? extends String, ? extends V> map) {
- for (final Map.Entry<? extends String, ? extends V> e : map.entrySet())
+ @Override
+ public void putAll(@NonNullable final Map<? extends String, ? extends V> map) {
+ for (final Map.Entry<? extends String, ? extends V> e : map.entrySet()) {
this.put(e.getKey(), e.getValue());
+ }
}
- public V remove(@NonNullable String key) {
+ public V remove(@NonNullable final String key) {
this.collector.run();
- if (debug)
+ if (debug) {
this.countRemove.incrementAndGet();
- Lock cacheLock = CacheManager.inst.readLock(this);
+ }
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
- Lock lock = this.keyedRWLock.writeLock(key);
+ final Lock lock = this.keyedRWLock.writeLock(key);
lock.lock();
try {
return doRemove(key);
@@ -396,8 +411,8 @@ public class SoftRefFileCache<V> implements ICache<V>
cacheLock.unlock();
}
}
- private V doRemove(@NonNullable String key) {
- KeyedSoftReference<String,V> oldRef = map.remove(key);
+ private V doRemove(@NonNullable final String key) {
+ final KeyedSoftReference<String,V> oldRef = map.remove(key);
V ret = null;
if (oldRef != null) {
@@ -408,7 +423,7 @@ public class SoftRefFileCache<V> implements ICache<V>
if (ret == null) {
// not exist or no longer exist in memory;
// so check the file system.
- CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
+ final CacheFileContent cfc = CacheFileDAO.inst.readCacheItem(this.name, key);
if (cfc == null) {
// not exist in file system.
@@ -424,57 +439,64 @@ public class SoftRefFileCache<V> implements ICache<V>
CacheFileDAO.inst.removeCacheItem(this.name, key);
return ret;
}
- public V remove(@NonNullable Object key) {
+ @Override
+ public V remove(@NonNullable final Object key) {
return key == null ? null : this.remove(key.toString());
}
+ @Override
public void clear() {
- for (String key : this.map.keySet())
+ for (final String key : this.map.keySet()) {
this.remove(key);
+ }
}
+ @Override
public @NonNullable Set<String> keySet() {
- Set<String> kset = map.keySet();
+ final Set<String> kset = map.keySet();
String[] list = null;
- Lock cacheLock = CacheManager.inst.readLock(this);
+ final Lock cacheLock = CacheManager.inst.readLock(this);
cacheLock.lock();
try {
list = CacheFileUtils.inst.getCacheDirList(this.name);
} finally {
cacheLock.unlock();
}
- if (list != null)
+ if (list != null) {
kset.addAll(Arrays.asList(list));
+ }
return kset;
}
+ @Override
@UnsupportedOperation
public Set<Map.Entry<String,V>> entrySet() {
throw new UnsupportedOperationException("Only memoryEntrySet and keySet are supported.");
}
public @NonNullable Set<Map.Entry<String,V>> memoryEntrySet() {
// this.collector.run();
- Set<Map.Entry<String,KeyedSoftReference<String,V>>> fromSet = map.entrySet();
- Set<Map.Entry<String,V>> toSet = new HashSet<Map.Entry<String,V>>();
+ final Set<Map.Entry<String,KeyedSoftReference<String,V>>> fromSet = map.entrySet();
+ final Set<Map.Entry<String,V>> toSet = new HashSet<>();
for (final Map.Entry<String, KeyedSoftReference<String,V>> item : fromSet) {
- KeyedSoftReference<String,V> ref = item.getValue();
- V val = ref.get();
+ final KeyedSoftReference<String,V> ref = item.getValue();
+ final V val = ref.get();
if (val != null) {
- Map.Entry<String,V> e = new CacheEntry<V>(item.getKey(), val);
+ final Map.Entry<String,V> e = new CacheEntry<>(item.getKey(), val);
toSet.add(e);
}
}
return toSet;
}
+ @Override
@UnsupportedOperation
public @NonNullable Collection<V> values() {
throw new UnsupportedOperationException("Only memoryValues and keySet are supported.");
}
public @NonNullable Collection<V> memoryValues() {
- Collection<KeyedSoftReference<String,V>> fromSet = map.values();
- List<V> toCol = new ArrayList<V>(fromSet.size());
+ final Collection<KeyedSoftReference<String,V>> fromSet = map.values();
+ final List<V> toCol = new ArrayList<>(fromSet.size());
for (final KeyedSoftReference<String,V> ref : fromSet) {
- V val = ref.get();
+ final V val = ref.get();
if (val != null) {
toCol.add(val);
@@ -482,21 +504,24 @@ public class SoftRefFileCache<V> implements ICache<V>
}
return toCol;
}
- public boolean containsKey(@NonNullable Object key) {
+ @Override
+ public boolean containsKey(@NonNullable final Object key) {
return this.get(key.toString()) != null;
}
+ @Override
@UnsupportedOperation
- public boolean containsValue(@NonNullable Object value) {
+ public boolean containsValue(@NonNullable final Object value) {
throw new UnsupportedOperationException("Only memoryContainsValue is supported.");
}
- public boolean memoryContainsValue(@NonNullable Object value) {
- Collection<KeyedSoftReference<String,V>> fromSet = map.values();
+ public boolean memoryContainsValue(@NonNullable final Object value) {
+ final Collection<KeyedSoftReference<String,V>> fromSet = map.values();
for (final KeyedSoftReference<String,V> ref : fromSet) {
- V val = ref.get();
+ final V val = ref.get();
- if (EqualsUtils.inst.equals(value, val))
+ if (EqualsUtils.inst.equals(value, val)) {
return true;
+ }
}
return false;
}
@@ -504,11 +529,11 @@ public class SoftRefFileCache<V> implements ICache<V>
// public int getCollectorCount() {
// return this.collector.getCount();
// }
- public void addCacheChangeListener(@NonNullable ICacheChangeListener<V> listener)
+ public void addCacheChangeListener(@NonNullable final ICacheChangeListener<V> listener)
{
this.cacheChangeSupport.addCacheChangeListener(listener);
}
- public void removeCacheChangeListener(@NonNullable ICacheChangeListener<V> listener)
+ public void removeCacheChangeListener(@NonNullable final ICacheChangeListener<V> listener)
{
this.cacheChangeSupport.removeCacheChangeListener(listener);
}
@@ -517,9 +542,10 @@ public class SoftRefFileCache<V> implements ICache<V>
return config;
}
- public void setConfig(PerCacheConfig config) {
+ public void setConfig(final PerCacheConfig config) {
this.config = config;
}
+ @Override
@Implements(ICache.class)
public CacheType getCacheType() {
return CacheType.SOFT_REFERENCE_FILE;
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/core/SafeCacheManagerTest.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/core/SafeCacheManagerTest.java
index 3b79027f..26fc1fab 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/core/SafeCacheManagerTest.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/core/SafeCacheManagerTest.java
@@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFactory;
@CopyRightApache
@TestOnly
public class SafeCacheManagerTest extends TestCase {
- private Log log = LogFactory.getLog(this.getClass());
+ private final Log log = LogFactory.getLog(this.getClass());
public void testGetCache() {
log.debug("Test getCache and get");
@@ -62,13 +62,13 @@ public class SafeCacheManagerTest extends TestCase {
assertTrue(null == c.get("2"));
assertTrue(null == c.get("1"));
log.debug("Test getCache and getValueType");
- ICacheSafe c1 = CacheManager.inst.getSafeCache("myCache");
+ final ICacheSafe c1 = CacheManager.inst.getSafeCache("myCache");
assertTrue(c1.getValueType() == String.class);
log.debug("Test checking of cache value type");
try {
- ICacheSafe<Integer> c2 = CacheManager.inst.getSafeCache("myCache", Integer.class);
+ final ICacheSafe<Integer> c2 = CacheManager.inst.getSafeCache("myCache", Integer.class);
assert false : "Bug: Cache for string cannot be used for Integer.";
- } catch (ClassCastException ex) {
+ } catch (final ClassCastException ex) {
// should go here.
}
log.debug(CacheManager.inst);
@@ -76,17 +76,17 @@ public class SafeCacheManagerTest extends TestCase {
public void testGetCacheRaceCondition() {
log.debug("Test simulation of race condition in creating cache");
- ICache intCache = CacheManager.inst.testCreateCacheRaceCondition(
+ final ICache intCache = CacheManager.inst.testCreateCacheRaceCondition(
"race", Integer.class, CacheType.SOFT_REFERENCE_SAFE);
- ICache intCache1 = CacheManager.inst.testCreateCacheRaceCondition(
+ final ICache intCache1 = CacheManager.inst.testCreateCacheRaceCondition(
"race", Integer.class, CacheType.SOFT_REFERENCE_SAFE);
log.debug("Test simulation of the worst case scenario: "
+ "race condition in creating cache AND class cast exception");
try {
- ICache doubleCache = CacheManager.inst.testCreateCacheRaceCondition(
+ final ICache doubleCache = CacheManager.inst.testCreateCacheRaceCondition(
"race", Double.class, CacheType.SOFT_REFERENCE_SAFE);
assert false : "Bug: Cache for Integer cannot be used for Double.";
- } catch (ClassCastException ex) {
+ } catch (final ClassCastException ex) {
// should go here.
}
assertTrue(intCache == intCache1);
@@ -94,15 +94,15 @@ public class SafeCacheManagerTest extends TestCase {
public void testRemoveCache() {
log.debug("Test remove cache");
- ICacheSafe<Integer> intCache = CacheManager.inst.getSafeCache("race", Integer.class);
+ final ICacheSafe<Integer> intCache = CacheManager.inst.getSafeCache("race", Integer.class);
intCache.put("1", 1);
assertEquals(intCache.size(), 1);
assertEquals(intCache, CacheManager.inst.removeCache("race"));
assertEquals(intCache.size(), 0);
- ICacheSafe intCache1 = CacheManager.inst.getSafeCache("race", Integer.class);
+ final ICacheSafe intCache1 = CacheManager.inst.getSafeCache("race", Integer.class);
assertFalse(intCache == intCache1);
CacheManager.inst.removeCache("race");
- ICache<Double> doubleCache =
+ final ICache<Double> doubleCache =
CacheManager.inst.testCreateCacheRaceCondition(
"race", Double.class, CacheType.SOFT_REFERENCE_SAFE);
doubleCache.put("double", 1.234);
@@ -130,7 +130,7 @@ public class SafeCacheManagerTest extends TestCase {
CacheManager.inst.removeCache("myCache");
ICacheSafe<TestSerializable> c = CacheManager.inst.getSafeCache(
"myCache", TestSerializable.class, CacheType.SOFT_REFERENCE_SAFE);
- TestSerializable[] ta = {
+ final TestSerializable[] ta = {
new TestSerializable("First Put"),
new TestSerializable("Second Put"),
new TestSerializable("Third Put")
@@ -169,13 +169,13 @@ public class SafeCacheManagerTest extends TestCase {
assertTrue(null == c.getCopy("2"));
assertTrue(null == c.getCopy("1"));
log.debug("Test getCache and getValueType");
- ICacheSafe c1 = CacheManager.inst.getSafeCache("myCache");
+ final ICacheSafe c1 = CacheManager.inst.getSafeCache("myCache");
assertTrue(c1.getValueType() == TestSerializable.class);
log.debug("Test checking of cache value type");
try {
- ICacheSafe<Integer> c2 = CacheManager.inst.getSafeCache("myCache", Integer.class);
+ final ICacheSafe<Integer> c2 = CacheManager.inst.getSafeCache("myCache", Integer.class);
assert false : "Bug: Cache for string cannot be used for Integer.";
- } catch (ClassCastException ex) {
+ } catch (final ClassCastException ex) {
// should go here.
}
log.debug(CacheManager.inst);
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefCacheTest.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefCacheTest.java
index 48ce9417..5780a6c8 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefCacheTest.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefCacheTest.java
@@ -34,10 +34,10 @@ import org.apache.commons.logging.LogFactory;
@CopyRightApache
@TestOnly
public class SoftRefCacheTest extends TestCase {
- private Log log = LogFactory.getLog(this.getClass());
+ private final Log log = LogFactory.getLog(this.getClass());
public void testSoftRefCache() throws Exception {
- ICache<byte[]> c = CacheManager.inst.getCache(
+ final ICache<byte[]> c = CacheManager.inst.getCache(
"bytesCache", byte[].class, CacheType.SOFT_REFERENCE);
for (int h=0; h < 10; h++) {
for (int i=h*10, max=i+10; i < max; i++) {
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCacheSafeTest.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCacheSafeTest.java
index 8096021d..a1b19edc 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCacheSafeTest.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/soft/SoftRefFileCacheSafeTest.java
@@ -34,10 +34,10 @@ import org.apache.commons.logging.LogFactory;
@CopyRightApache
@TestOnly
public class SoftRefFileCacheSafeTest extends TestCase {
- private Log log = LogFactory.getLog(this.getClass());
+ private final Log log = LogFactory.getLog(this.getClass());
public void testSoftRefCache() throws Exception {
- ICacheSafe<byte[]> c = CacheManager.inst.getSafeCache(
+ final ICacheSafe<byte[]> c = CacheManager.inst.getSafeCache(
"bytesCache", byte[].class, CacheType.SOFT_REFERENCE_FILE_SAFE);
for (int h=0; h < 10; h++) {
for (int i=h*10, max=i+10; i < max; i++) {
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/SerializeUtilsTest.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/SerializeUtilsTest.java
index 095ae630..0e10e106 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/SerializeUtilsTest.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/SerializeUtilsTest.java
@@ -33,42 +33,44 @@ import org.apache.commons.logging.LogFactory;
@CopyRightApache
@TestOnly
public class SerializeUtilsTest extends TestCase {
- private Log log = LogFactory.getLog(this.getClass());
+ private final Log log = LogFactory.getLog(this.getClass());
/**
* Test of dup method, of class org.apache.commons.jcs.yajcache.util.SerializeUtils.
*/
public void testDup() {
// Test string dup: no clone
log.debug("Test string dup: no clone");
- String s1 = "Abc Def";
- String s2 = SerializeUtils.inst.dup(s1);
+ final String s1 = "Abc Def";
+ final String s2 = SerializeUtils.inst.dup(s1);
assertTrue(s1 == s2);
// Test non-string Seriailzable dup: deep clone
log.debug("Test non-string Seriailzable dup: deep clone");
- TestSerializable o1 = new TestSerializable("abc Def");
- TestSerializable o2 = SerializeUtils.inst.dup(o1);
+ final TestSerializable o1 = new TestSerializable("abc Def");
+ final TestSerializable o2 = SerializeUtils.inst.dup(o1);
assertFalse(o1 == o2);
assertEquals(o1, o2);
// Test string array dup: shallow clone
log.debug("Test string array dup: shallow clone");
- String[] sa = {"1", "2", "3"};
- String[] sa1 = SerializeUtils.inst.dup(sa);
+ final String[] sa = {"1", "2", "3"};
+ final String[] sa1 = SerializeUtils.inst.dup(sa);
assertFalse(sa == sa1);
assertTrue(Arrays.equals(sa, sa1));
- for (int i=sa.length-1; i > -1; i--)
+ for (int i=sa.length-1; i > -1; i--) {
assertTrue(sa[i] == sa1[i]);
+ }
// Test int array dup: shallow clone
log.debug("Test int array dup: shallow clone");
- int[] ia = {1,2,3};
- int[] ia1 = SerializeUtils.inst.dup(ia);
+ final int[] ia = {1,2,3};
+ final int[] ia1 = SerializeUtils.inst.dup(ia);
assertFalse(ia == ia1);
assertTrue(Arrays.equals(ia, ia1));
- for (int i=ia.length-1; i > -1; i--)
+ for (int i=ia.length-1; i > -1; i--) {
assertTrue(ia[i] == ia1[i]);
+ }
// Test Integer array dup: shallow clone
log.debug("Test Integer array dup: shallow clone");
- Integer[] inta = {1,2,3};
- Integer[] inta1 = SerializeUtils.inst.dup(inta);
+ final Integer[] inta = {1,2,3};
+ final Integer[] inta1 = SerializeUtils.inst.dup(inta);
assertFalse(inta == inta1);
assertTrue(Arrays.equals(inta, inta1));
@@ -77,8 +79,8 @@ public class SerializeUtilsTest extends TestCase {
}
// Test non-string Seriailzable array dup: deep clone
log.debug("Test non-string Seriailzable array dup: deep clone");
- TestSerializable[] ta1 = {new TestSerializable("abc Def"), new TestSerializable("123"), new TestSerializable("assdk")};
- TestSerializable[] ta2 = SerializeUtils.inst.dup(ta1);
+ final TestSerializable[] ta1 = {new TestSerializable("abc Def"), new TestSerializable("123"), new TestSerializable("assdk")};
+ final TestSerializable[] ta2 = SerializeUtils.inst.dup(ta1);
assertFalse(ta1 == ta2);
assertTrue(Arrays.equals(ta1, ta2));
diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/TestSerializable.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/TestSerializable.java
index 311c46cc..323142dd 100644
--- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/TestSerializable.java
+++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/util/TestSerializable.java
@@ -37,13 +37,15 @@ public class TestSerializable implements Serializable {
public TestSerializable() {
}
/** Creates a new instance of TestSerializable */
- public TestSerializable(String name) {
+ public TestSerializable(final String name) {
this.name = name;
}
+ @Override
public int hashCode() {
return this.name == null ? 0 : this.name.hashCode();
}
- public boolean equals(Object obj) {
+ @Override
+ public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@@ -51,7 +53,7 @@ public class TestSerializable implements Serializable {
return name;
}
- public void setName(String name) {
+ public void setName(final String name) {
this.name = name;
}
}