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 b27e6ee5854b1e5247b15d5384c3cde208679ec2 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Jul 9 19:42:44 2024 -0400 Use final Use blocks Remove useless or redundant parens Use diamonds Remove redundant keywords --- .../commons/jcs3/access/GroupCacheAccess.java | 22 +-- .../auxiliary/disk/indexed/IndexedDiskCache.java | 6 +- .../lateral/behavior/ILateralCacheAttributes.java | 2 +- .../jcs3/engine/behavior/IElementSerializer.java | 22 +-- .../commons/jcs3/utils/net/HostNameUtil.java | 2 +- .../utils/serialization/EncryptingSerializer.java | 44 ++--- .../jcs3/auxiliary/disk/jdbc/HsqlSetupUtil.java | 2 +- .../jcs3/engine/EventQueueConcurrentLoadTest.java | 4 +- .../EncryptingSerializerUnitTest.java | 2 +- .../jcache/extras/cdi/ExtraJCacheExtension.java | 4 +- .../jcs/auxiliary/disk/file/FileDiskCache.java | 126 +++++++------- .../disk/file/FileDiskCacheAttributes.java | 10 +- .../auxiliary/disk/file/FileDiskCacheFactory.java | 8 +- .../auxiliary/disk/file/FileDiskCacheManager.java | 16 +- .../disk/file/FileDiskCacheFactoryUnitTest.java | 14 +- .../auxiliary/disk/file/FileDiskCacheUnitTest.java | 188 ++++++++++----------- .../jcs/yajcache/beans/ICacheChangeHandler.java | 12 +- .../jcs/yajcache/beans/ICacheChangeListener.java | 3 +- .../apache/commons/jcs/yajcache/core/ICache.java | 9 +- .../commons/jcs/yajcache/core/ICacheSafe.java | 27 +-- .../apache/commons/jcs/yajcache/lang/ref/IKey.java | 2 +- .../commons/jcs/yajcache/util/EqualsUtils.java | 46 +++-- .../util/concurrent/locks/IKeyedReadWriteLock.java | 4 +- .../jcs/yajcache/file/FileContentTypeTest.java | 8 +- 24 files changed, 287 insertions(+), 296 deletions(-) diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/access/GroupCacheAccess.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/access/GroupCacheAccess.java index 45bc4982..971b559c 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/access/GroupCacheAccess.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/access/GroupCacheAccess.java @@ -62,8 +62,8 @@ public class GroupCacheAccess<K, V> @Override public V getFromGroup( final K name, final String group ) { - final ICacheElement<GroupAttrName<K>, V> element = this.getCacheControl().get( getGroupAttrName( group, name ) ); - return ( element != null ) ? element.getVal() : null; + final ICacheElement<GroupAttrName<K>, V> element = getCacheControl().get( getGroupAttrName( group, name ) ); + return element != null ? element.getVal() : null; } /** @@ -75,7 +75,7 @@ public class GroupCacheAccess<K, V> */ private GroupAttrName<K> getGroupAttrName( final String group, final K name ) { - final GroupId gid = new GroupId( this.getCacheControl().getCacheName(), group ); + final GroupId gid = new GroupId( getCacheControl().getCacheName(), group ); return new GroupAttrName<>( gid, name ); } @@ -88,9 +88,9 @@ public class GroupCacheAccess<K, V> @Override public Set<K> getGroupKeys( final String group ) { - final GroupId groupId = new GroupId( this.getCacheControl().getCacheName(), group ); + final GroupId groupId = new GroupId( getCacheControl().getCacheName(), group ); - return this.getCacheControl().getKeySet() + return getCacheControl().getKeySet() .stream() .filter(gan -> gan.groupId.equals(groupId)) .map(gan -> gan.attrName) @@ -104,7 +104,7 @@ public class GroupCacheAccess<K, V> */ public Set<String> getGroupNames() { - return this.getCacheControl().getKeySet() + return getCacheControl().getKeySet() .stream() .map(gan -> gan.groupId.groupName) .collect(Collectors.toSet()); @@ -119,7 +119,7 @@ public class GroupCacheAccess<K, V> @Override public void invalidateGroup( final String group ) { - this.getCacheControl().remove(getGroupAttrName(group, null)); + getCacheControl().remove(getGroupAttrName(group, null)); } /** @@ -177,12 +177,12 @@ public class GroupCacheAccess<K, V> { final GroupAttrName<K> key = getGroupAttrName( groupName, name ); final CacheElement<GroupAttrName<K>, V> ce = - new CacheElement<>( this.getCacheControl().getCacheName(), key, value ); + new CacheElement<>( getCacheControl().getCacheName(), key, value ); - final IElementAttributes attributes = (attr == null) ? this.getCacheControl().getElementAttributes() : attr; + final IElementAttributes attributes = attr == null ? getCacheControl().getElementAttributes() : attr; ce.setElementAttributes( attributes ); - this.getCacheControl().update( ce ); + getCacheControl().update( ce ); } catch ( final IOException e ) { @@ -201,6 +201,6 @@ public class GroupCacheAccess<K, V> public void removeFromGroup( final K name, final String group ) { final GroupAttrName<K> key = getGroupAttrName( group, name ); - this.getCacheControl().remove( key ); + getCacheControl().remove( key ); } } diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java index 7760a934..17e6b158 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java @@ -88,7 +88,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V> { addToRecycleBin(value); log.debug("{0}: Removing key: [{1}] from key store.", logCacheName, key); - log.debug("{0}: Key store size: [{1}].", logCacheName, this.size()); + log.debug("{0}: Key store size: [{1}].", logCacheName, size()); doOptimizeRealTime(); } @@ -151,7 +151,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V> addToRecycleBin(value); log.debug("{0}: Removing key: [{1}] from key store.", logCacheName, key); - log.debug("{0}: Key store size: [{1}].", logCacheName, this.size()); + log.debug("{0}: Key store size: [{1}].", logCacheName, size()); doOptimizeRealTime(); } @@ -203,7 +203,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V> @Override protected boolean shouldRemove() { - return maxSize > 0 && contentSize.get() > maxSize && !this.isEmpty(); + return maxSize > 0 && contentSize.get() > maxSize && !isEmpty(); } // keep the content size in kB, so 2^31 kB is reasonable value diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java index 109db058..5492cef5 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java @@ -46,7 +46,7 @@ public interface ILateralCacheAttributes private final String typeName; - Type(String typeName) + Type(final String typeName) { this.typeName = typeName; } diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/behavior/IElementSerializer.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/behavior/IElementSerializer.java index 8af3bc40..8b18d952 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/behavior/IElementSerializer.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/behavior/IElementSerializer.java @@ -64,7 +64,7 @@ public interface IElementSerializer * @throws ClassNotFoundException thrown if we don't know the object. * @since 3.1 */ - default <T> T deSerializeFrom(AsynchronousByteChannel ic, int readTimeoutMs, ClassLoader loader) + default <T> T deSerializeFrom(final AsynchronousByteChannel ic, final int readTimeoutMs, final ClassLoader loader) throws IOException, ClassNotFoundException { final ByteBuffer bufferSize = ByteBuffer.allocate(4); @@ -72,7 +72,7 @@ public interface IElementSerializer try { - int read = readFuture.get(readTimeoutMs, TimeUnit.MILLISECONDS); + final int read = readFuture.get(readTimeoutMs, TimeUnit.MILLISECONDS); if (read < 0) { throw new EOFException("End of stream reached (length)"); @@ -92,7 +92,7 @@ public interface IElementSerializer readFuture = ic.read(serialized); try { - int read = readFuture.get(readTimeoutMs, TimeUnit.MILLISECONDS); + final int read = readFuture.get(readTimeoutMs, TimeUnit.MILLISECONDS); if (read < 0) { throw new EOFException("End of stream reached (object)"); @@ -121,7 +121,7 @@ public interface IElementSerializer * @throws ClassNotFoundException thrown if we don't know the object. * @since 3.1 */ - default <T> T deSerializeFrom(InputStream is, ClassLoader loader) + default <T> T deSerializeFrom(final InputStream is, final ClassLoader loader) throws IOException, ClassNotFoundException { final byte[] bufferSize = new byte[4]; @@ -131,9 +131,9 @@ public interface IElementSerializer throw new EOFException("End of stream reached"); } assert read == bufferSize.length; - ByteBuffer size = ByteBuffer.wrap(bufferSize); + final ByteBuffer size = ByteBuffer.wrap(bufferSize); - byte[] serialized = new byte[size.getInt()]; + final byte[] serialized = new byte[size.getInt()]; read = is.read(serialized); assert read == serialized.length; @@ -152,7 +152,7 @@ public interface IElementSerializer * @throws ClassNotFoundException thrown if we don't know the object. * @since 3.1 */ - default <T> T deSerializeFrom(ReadableByteChannel ic, ClassLoader loader) + default <T> T deSerializeFrom(final ReadableByteChannel ic, final ClassLoader loader) throws IOException, ClassNotFoundException { final ByteBuffer bufferSize = ByteBuffer.allocate(4); @@ -202,7 +202,7 @@ public interface IElementSerializer * @throws IOException if serialization or writing fails * @since 3.1 */ - default <T> int serializeTo(T obj, AsynchronousByteChannel oc, int writeTimeoutMs) + default <T> int serializeTo(final T obj, final AsynchronousByteChannel oc, final int writeTimeoutMs) throws IOException { final byte[] serialized = serialize(obj); @@ -214,7 +214,7 @@ public interface IElementSerializer int count = 0; while (buffer.hasRemaining()) { - Future<Integer> bytesWritten = oc.write(buffer); + final Future<Integer> bytesWritten = oc.write(buffer); try { count += bytesWritten.get(writeTimeoutMs, TimeUnit.MILLISECONDS); @@ -239,7 +239,7 @@ public interface IElementSerializer * @throws IOException if serialization or writing fails * @since 3.1 */ - default <T> int serializeTo(T obj, OutputStream os) + default <T> int serializeTo(final T obj, final OutputStream os) throws IOException { final byte[] serialized = serialize(obj); @@ -263,7 +263,7 @@ public interface IElementSerializer * @throws IOException if serialization or writing fails * @since 3.1 */ - default <T> int serializeTo(T obj, WritableByteChannel oc) + default <T> int serializeTo(final T obj, final WritableByteChannel oc) throws IOException { final byte[] serialized = serialize(obj); diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java index f9868a55..a299c922 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java @@ -116,7 +116,7 @@ public class HostNameUtil public static List<InetAddress> getLocalHostLANAddresses() throws UnknownHostException { - List<InetAddress> addresses = new ArrayList<>(); + final List<InetAddress> addresses = new ArrayList<>(); try { diff --git a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java index 731414cd..d5984121 100644 --- a/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java +++ b/commons-jcs3-core/src/main/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializer.java @@ -84,7 +84,7 @@ public class EncryptingSerializer extends StandardSerializer * @param serializer * the wrapped serializer */ - public EncryptingSerializer(IElementSerializer serializer) + public EncryptingSerializer(final IElementSerializer serializer) { this.serializer = serializer; @@ -93,39 +93,39 @@ public class EncryptingSerializer extends StandardSerializer this.secureRandom = new SecureRandom(); this.secretKeyFactory = SecretKeyFactory.getInstance(DEFAULT_SECRET_KEY_ALGORITHM); } - catch (NoSuchAlgorithmException e) + catch (final NoSuchAlgorithmException e) { throw new IllegalStateException("Could not set up encryption tools", e); } } - private SecretKey createSecretKey(String password, byte[] salt) throws InvalidKeySpecException + private SecretKey createSecretKey(final String password, final byte[] salt) throws InvalidKeySpecException { /* Derive the key, given password and salt. */ - PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, + final PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, KEYHASH_ITERATION_COUNT, KEY_LENGTH); - SecretKey tmp = secretKeyFactory.generateSecret(spec); + final SecretKey tmp = secretKeyFactory.generateSecret(spec); return new SecretKeySpec(tmp.getEncoded(), "AES"); } - private byte[] decrypt(byte[] source) throws IOException + private byte[] decrypt(final byte[] source) throws IOException { try { // split data in initial vector, salt and encrypted data - ByteBuffer wrapped = ByteBuffer.wrap(source); + final ByteBuffer wrapped = ByteBuffer.wrap(source); - byte[] iv = new byte[IV_LENGTH]; + final byte[] iv = new byte[IV_LENGTH]; wrapped.get(iv); - byte[] salt = new byte[SALT_LENGTH]; + final byte[] salt = new byte[SALT_LENGTH]; wrapped.get(salt); - byte[] encrypted = new byte[wrapped.remaining()]; + final byte[] encrypted = new byte[wrapped.remaining()]; wrapped.get(encrypted); - SecretKey secretKey = createSecretKey(psk, salt); - Cipher cipher = Cipher.getInstance(cipherTransformation); + final SecretKey secretKey = createSecretKey(psk, salt); + final Cipher cipher = Cipher.getInstance(cipherTransformation); if (cipher.getAlgorithm().startsWith("AES/GCM")) { @@ -169,15 +169,15 @@ public class EncryptingSerializer extends StandardSerializer return serializer.deSerialize(deccrypted, loader); } - private byte[] encrypt(byte[] source) throws IOException + private byte[] encrypt(final byte[] source) throws IOException { try { - byte[] salt = getRandomBytes(SALT_LENGTH); - byte[] iv = getRandomBytes(IV_LENGTH); + final byte[] salt = getRandomBytes(SALT_LENGTH); + final byte[] iv = getRandomBytes(IV_LENGTH); - SecretKey secretKey = createSecretKey(psk, salt); - Cipher cipher = Cipher.getInstance(cipherTransformation); + final SecretKey secretKey = createSecretKey(psk, salt); + final Cipher cipher = Cipher.getInstance(cipherTransformation); if (cipher.getAlgorithm().startsWith("AES/GCM")) { cipher.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(TAG_LENGTH, iv)); @@ -187,7 +187,7 @@ public class EncryptingSerializer extends StandardSerializer cipher.init(Cipher.ENCRYPT_MODE, secretKey); } - byte[] encrypted = cipher.doFinal(source); + final byte[] encrypted = cipher.doFinal(source); // join initial vector, salt and encrypted data for later decryption return ByteBuffer.allocate(IV_LENGTH + SALT_LENGTH + encrypted.length) @@ -204,9 +204,9 @@ public class EncryptingSerializer extends StandardSerializer } } - private byte[] getRandomBytes(int length) + private byte[] getRandomBytes(final int length) { - byte[] bytes = new byte[length]; + final byte[] bytes = new byte[length]; secureRandom.nextBytes(bytes); return bytes; @@ -233,7 +233,7 @@ public class EncryptingSerializer extends StandardSerializer * * @param transformation the transformation */ - public void setAesCipherTransformation(String transformation) + public void setAesCipherTransformation(final String transformation) { this.cipherTransformation = transformation; } @@ -243,7 +243,7 @@ public class EncryptingSerializer extends StandardSerializer * * @param psk the key */ - public void setPreSharedKey(String psk) + public void setPreSharedKey(final String psk) { this.psk = psk; } diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/HsqlSetupUtil.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/HsqlSetupUtil.java index 238c7389..4da1f0ff 100644 --- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/HsqlSetupUtil.java +++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/HsqlSetupUtil.java @@ -32,7 +32,7 @@ public final class HsqlSetupUtil private static final class HSQLDiskCacheFactoryHelper extends HSQLDiskCacheFactory { @Override - protected synchronized void setupTable(Connection cConn, String tableName) throws SQLException + protected synchronized void setupTable(final Connection cConn, final String tableName) throws SQLException { super.setupTable(cConn, tableName); } diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/EventQueueConcurrentLoadTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/EventQueueConcurrentLoadTest.java index 31a5d5a7..64f93ce9 100644 --- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/EventQueueConcurrentLoadTest.java +++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/engine/EventQueueConcurrentLoadTest.java @@ -193,7 +193,7 @@ public class EventQueueConcurrentLoadTest // this becomes less accurate with each test. It should never fail. If // it does things are very off. assertTrue( "The put count [" + listen.putCount + "] is below the expected minimum threshold [" - + expectedPutCount + "]", listen.putCount.get() >= ( expectedPutCount - 1 ) ); + + expectedPutCount + "]", listen.putCount.get() >= expectedPutCount - 1 ); } @@ -225,7 +225,7 @@ public class EventQueueConcurrentLoadTest // this becomes less accurate with each test. It should never fail. If // it does things are very off. assertTrue( "The put count [" + listen.putCount + "] is below the expected minimum threshold [" - + expectedPutCount + "]", listen.putCount.get() >= ( expectedPutCount - 1 ) ); + + expectedPutCount + "]", listen.putCount.get() >= expectedPutCount - 1 ); } diff --git a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java index 91e3d66a..71369ddb 100644 --- a/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java +++ b/commons-jcs3-core/src/test/java/org/apache/commons/jcs3/utils/serialization/EncryptingSerializerUnitTest.java @@ -70,7 +70,7 @@ public class EncryptingSerializerUnitTest { // DO WORK final String before = "adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdsfdsafdsafsa333 31231"; - byte[] serialized = serializer.serialize(before); + final byte[] serialized = serializer.serialize(before); serializer.setPreSharedKey("another_key"); assertThrows(IOException.class, () -> serializer.deSerialize(serialized, null)); diff --git a/commons-jcs3-jcache-extras/src/main/java/org/apache/commons/jcs3/jcache/extras/cdi/ExtraJCacheExtension.java b/commons-jcs3-jcache-extras/src/main/java/org/apache/commons/jcs3/jcache/extras/cdi/ExtraJCacheExtension.java index e9d27e57..caadd76f 100644 --- a/commons-jcs3-jcache-extras/src/main/java/org/apache/commons/jcs3/jcache/extras/cdi/ExtraJCacheExtension.java +++ b/commons-jcs3-jcache-extras/src/main/java/org/apache/commons/jcs3/jcache/extras/cdi/ExtraJCacheExtension.java @@ -42,7 +42,7 @@ public class ExtraJCacheExtension implements Extension public void addJCacheBeans(final @Observes AfterBeanDiscovery afterBeanDiscovery) { - if (!ACTIVATED || (cacheManagerFound && cacheProviderFound)) { + if (!ACTIVATED || cacheManagerFound && cacheProviderFound) { return; } @@ -75,7 +75,7 @@ public class ExtraJCacheExtension implements Extension public <A> void processBean(final @Observes ProcessBean<A> processBeanEvent) { - if (!ACTIVATED || (cacheManagerFound && cacheProviderFound)) + if (!ACTIVATED || cacheManagerFound && cacheProviderFound) { return; } diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java index 4a86c28f..09749f62 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java @@ -43,7 +43,6 @@ import java.io.OutputStream; import java.util.Map; import java.util.Set; -import org.apache.commons.jcs.utils.timing.SleepUtil; import org.apache.commons.jcs3.auxiliary.AuxiliaryCacheAttributes; import org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache; import org.apache.commons.jcs3.engine.behavior.ICacheElement; @@ -80,7 +79,7 @@ public class FileDiskCache<K, V> * <p> * @param cacheAttributes */ - public FileDiskCache( FileDiskCacheAttributes cacheAttributes ) + public FileDiskCache( final FileDiskCacheAttributes cacheAttributes ) { this( cacheAttributes, null ); } @@ -92,7 +91,7 @@ public class FileDiskCache<K, V> * @param cattr * @param elementSerializer used if supplied, the super's super will not set a null */ - public FileDiskCache( FileDiskCacheAttributes cattr, IElementSerializer elementSerializer ) + public FileDiskCache( final FileDiskCacheAttributes cattr, final IElementSerializer elementSerializer ) { super( cattr ); setElementSerializer( elementSerializer ); @@ -107,11 +106,11 @@ public class FileDiskCache<K, V> * @param cattr * @return does the directory exist. */ - private boolean initializeFileSystem( FileDiskCacheAttributes cattr ) + private boolean initializeFileSystem( final FileDiskCacheAttributes cattr ) { // TODO, we might need to make this configurable this.setDirectory( new File( cattr.getDiskPath(), cattr.getCacheName() ) ); - boolean createdDirectories = getDirectory().mkdirs(); + final boolean createdDirectories = getDirectory().mkdirs(); if ( log.isInfoEnabled() ) { log.info( logCacheName + "Cache file root directory: " + getDirectory() ); @@ -119,7 +118,7 @@ public class FileDiskCache<K, V> } // TODO consider throwing. - boolean exists = getDirectory().exists(); + final boolean exists = getDirectory().exists(); if ( !exists ) { log.error( "Could not initialize File Disk Cache. The root directory does not exist." ); @@ -136,13 +135,13 @@ public class FileDiskCache<K, V> * @param key * @return the file for the key */ - protected <KK> File file( KK key ) + protected <KK> File file( final KK key ) { - StringBuilder fileNameBuffer = new StringBuilder(); + final StringBuilder fileNameBuffer = new StringBuilder(); // add key as file name in a file system safe way - String keys = key.toString(); - int l = keys.length(); + final String keys = key.toString(); + final int l = keys.length(); for ( int i = 0; i < l; i++ ) { char c = keys.charAt( i ); @@ -152,7 +151,7 @@ public class FileDiskCache<K, V> } fileNameBuffer.append( c ); } - String fileName = fileNameBuffer.toString(); + final String fileName = fileNameBuffer.toString(); if ( log.isDebugEnabled() ) { @@ -213,7 +212,7 @@ public class FileDiskCache<K, V> protected synchronized void processDispose() throws IOException { - ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT ); + final ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT ); try { if ( !isAlive() ) @@ -245,10 +244,10 @@ public class FileDiskCache<K, V> * @throws IOException */ @Override - protected ICacheElement<K, V> processGet( K key ) + protected ICacheElement<K, V> processGet( final K key ) throws IOException { - File file = file( key ); + final File file = file( key ); if ( !file.exists() ) { @@ -266,9 +265,9 @@ public class FileDiskCache<K, V> { fis = new FileInputStream( file ); - long length = file.length(); + final long length = file.length(); // Create the byte array to hold the data - byte[] bytes = new byte[(int) length]; + final byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = 0; @@ -296,11 +295,7 @@ public class FileDiskCache<K, V> element = null; } } - catch ( IOException e ) - { - log.error( logCacheName + "Failure getting element, key: [" + key + "]", e ); - } - catch ( ClassNotFoundException e ) + catch ( IOException | ClassNotFoundException e ) { log.error( logCacheName + "Failure getting element, key: [" + key + "]", e ); } @@ -323,7 +318,7 @@ public class FileDiskCache<K, V> * @throws IOException */ @Override - protected Map<K, ICacheElement<K, V>> processGetMatching( String pattern ) + protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern ) throws IOException { // TODO get a list of file and return those with matching keys. @@ -339,7 +334,7 @@ public class FileDiskCache<K, V> * @throws IOException */ @Override - protected boolean processRemove( K key ) + protected boolean processRemove( final K key ) throws IOException { return _processRemove(key); @@ -352,10 +347,10 @@ public class FileDiskCache<K, V> * @return true if the item was removed * @throws IOException */ - private <T> boolean _processRemove( T key ) + private <T> boolean _processRemove( final T key ) throws IOException { - File file = file( key ); + final File file = file( key ); if ( log.isDebugEnabled() ) { log.debug( logCacheName + "Removing file " + file ); @@ -375,10 +370,9 @@ public class FileDiskCache<K, V> protected void processRemoveAll() throws IOException { - String[] fileNames = getDirectory().list(); - for ( int i = 0; i < fileNames.length; i++ ) - { - _processRemove( fileNames[i] ); + final String[] fileNames = getDirectory().list(); + for (final String fileName : fileNames) { + _processRemove( fileName ); } } @@ -390,22 +384,22 @@ public class FileDiskCache<K, V> * @throws IOException */ @Override - protected void processUpdate( ICacheElement<K, V> element ) + protected void processUpdate( final ICacheElement<K, V> element ) throws IOException { removeIfLimitIsSetAndReached(); - File file = file( element.getKey() ); + final File file = file( element.getKey() ); File tmp = null; OutputStream os = null; try { - byte[] bytes = getElementSerializer().serialize( element ); + final byte[] bytes = getElementSerializer().serialize( element ); tmp = File.createTempFile( "JCS_DiskFileCache", null, getDirectory() ); - FileOutputStream fos = new FileOutputStream( tmp ); + final FileOutputStream fos = new FileOutputStream( tmp ); os = new BufferedOutputStream( fos ); if ( bytes != null ) @@ -418,13 +412,13 @@ public class FileDiskCache<K, V> os.close(); } deleteWithRetry( file ); - boolean result = tmp.renameTo( file ); + final boolean result = tmp.renameTo( file ); if ( log.isDebugEnabled() ) { log.debug( logCacheName + "Renamed to: " + file + " Result: " + result); } } - catch ( IOException e ) + catch ( final IOException e ) { log.error( logCacheName + "Failure updating element, key: [" + element.getKey() + "]", e ); } @@ -446,37 +440,33 @@ public class FileDiskCache<K, V> */ private void removeIfLimitIsSetAndReached() { - if ( diskFileCacheAttributes.getMaxNumberOfFiles() > 0 ) + // TODO we might want to synchronize this block. + if ( (diskFileCacheAttributes.getMaxNumberOfFiles() > 0) && (getSize() >= diskFileCacheAttributes.getMaxNumberOfFiles()) ) { - // TODO we might want to synchronize this block. - if ( getSize() >= diskFileCacheAttributes.getMaxNumberOfFiles() ) + if ( log.isDebugEnabled() ) { - if ( log.isDebugEnabled() ) - { - log.debug( logCacheName + "Max reached, removing least recently modified" ); - } + log.debug( logCacheName + "Max reached, removing least recently modified" ); + } - long oldestLastModified = System.currentTimeMillis(); - File theLeastRecentlyModified = null; - String[] fileNames = getDirectory().list(); - for ( int i = 0; i < fileNames.length; i++ ) + long oldestLastModified = System.currentTimeMillis(); + File theLeastRecentlyModified = null; + final String[] fileNames = getDirectory().list(); + for (final String fileName : fileNames) { + final File file = file( fileName ); + final long lastModified = file.lastModified(); + if ( lastModified < oldestLastModified ) { - File file = file( fileNames[i] ); - long lastModified = file.lastModified(); - if ( lastModified < oldestLastModified ) - { - oldestLastModified = lastModified; - theLeastRecentlyModified = file; - } + oldestLastModified = lastModified; + theLeastRecentlyModified = file; } - if ( theLeastRecentlyModified != null ) + } + if ( theLeastRecentlyModified != null ) + { + if ( log.isDebugEnabled() ) { - if ( log.isDebugEnabled() ) - { - log.debug( logCacheName + "Least recently modified: " + theLeastRecentlyModified ); - } - deleteWithRetry( theLeastRecentlyModified ); + log.debug( logCacheName + "Least recently modified: " + theLeastRecentlyModified ); } + deleteWithRetry( theLeastRecentlyModified ); } } } @@ -488,14 +478,14 @@ public class FileDiskCache<K, V> * @param file * @return true if the file does not exist or if it was removed */ - private boolean deleteWithRetry( File file ) + private boolean deleteWithRetry( final File file ) { boolean success = file.delete(); // TODO: The following should be identical to success == false, but it isn't if ( file.exists() ) { - int maxRetries = diskFileCacheAttributes.getMaxRetriesOnDelete(); + final int maxRetries = diskFileCacheAttributes.getMaxRetriesOnDelete(); for ( int i = 0; i < maxRetries && !success; i++ ) { SleepUtil.sleepAtLeast( 5 ); @@ -519,12 +509,12 @@ public class FileDiskCache<K, V> * @param file to touch * @return was it successful */ - private boolean touchWithRetry( File file ) + private boolean touchWithRetry( final File file ) { boolean success = file.setLastModified( System.currentTimeMillis() ); if ( !success ) { - int maxRetries = diskFileCacheAttributes.getMaxRetriesOnTouch(); + final int maxRetries = diskFileCacheAttributes.getMaxRetriesOnTouch(); if ( file.exists() ) { for ( int i = 0; i < maxRetries && !success; i++ ) @@ -546,7 +536,7 @@ public class FileDiskCache<K, V> * <p> * @param s the stream */ - private void silentClose( InputStream s ) + private void silentClose( final InputStream s ) { if ( s != null ) { @@ -554,7 +544,7 @@ public class FileDiskCache<K, V> { s.close(); } - catch ( IOException e ) + catch ( final IOException e ) { log.error( logCacheName + "Failure closing stream", e ); } @@ -566,7 +556,7 @@ public class FileDiskCache<K, V> * <p> * @param s the stream */ - private void silentClose( OutputStream s ) + private void silentClose( final OutputStream s ) { if ( s != null ) { @@ -574,7 +564,7 @@ public class FileDiskCache<K, V> { s.close(); } - catch ( IOException e ) + catch ( final IOException e ) { log.error( logCacheName + "Failure closing stream", e ); } @@ -584,7 +574,7 @@ public class FileDiskCache<K, V> /** * @param directory the directory to set */ - protected void setDirectory( File directory ) + protected void setDirectory( final File directory ) { this.directory = directory; } diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java index 64095390..05bf52d3 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java @@ -58,7 +58,7 @@ public class FileDiskCacheAttributes /** * @param maxNumberOfFiles the maxNumberOfFiles to set */ - public void setMaxNumberOfFiles( int maxNumberOfFiles ) + public void setMaxNumberOfFiles( final int maxNumberOfFiles ) { this.maxNumberOfFiles = maxNumberOfFiles; } @@ -74,7 +74,7 @@ public class FileDiskCacheAttributes /** * @param maxRetriesOnDelete the maxRetriesOnDelete to set */ - public void setMaxRetriesOnDelete( int maxRetriesOnDelete ) + public void setMaxRetriesOnDelete( final int maxRetriesOnDelete ) { this.maxRetriesOnDelete = maxRetriesOnDelete; } @@ -90,7 +90,7 @@ public class FileDiskCacheAttributes /** * @param touchOnGet the touchOnGet to set */ - public void setTouchOnGet( boolean touchOnGet ) + public void setTouchOnGet( final boolean touchOnGet ) { this.touchOnGet = touchOnGet; } @@ -106,7 +106,7 @@ public class FileDiskCacheAttributes /** * @param maxRetriesOnTouch the maxRetriesOnTouch to set */ - public void setMaxRetriesOnTouch( int maxRetriesOnTouch ) + public void setMaxRetriesOnTouch( final int maxRetriesOnTouch ) { this.maxRetriesOnTouch = maxRetriesOnTouch; } @@ -127,7 +127,7 @@ public class FileDiskCacheAttributes @Override public String toString() { - StringBuilder str = new StringBuilder(); + final StringBuilder str = new StringBuilder(); str.append( "DiskFileCacheAttributes " ); str.append( "\n diskPath = " + super.getDiskPath() ); str.append( "\n maxNumberOfFiles = " + getMaxNumberOfFiles() ); diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java index 7d56b95d..1a5ef5b2 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java @@ -50,10 +50,10 @@ public class FileDiskCacheFactory */ @Override public <K, V> FileDiskCache<K, V> createCache( - AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr, - ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) + final AuxiliaryCacheAttributes attr, final ICompositeCacheManager cacheMgr, + final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer ) { - FileDiskCacheAttributes idfca = (FileDiskCacheAttributes) attr; + final FileDiskCacheAttributes idfca = (FileDiskCacheAttributes) attr; if ( log.isDebugEnabled() ) { log.debug( "Creating DiskFileCache for attributes = " + idfca ); @@ -89,7 +89,7 @@ public class FileDiskCacheFactory * @param name The new name value */ @Override - public void setName( String name ) + public void setName( final String name ) { this.name = name; } diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java index 2e7e21e3..75fc6aaa 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java @@ -55,7 +55,7 @@ public class FileDiskCacheManager /** Each region has an entry here. */ private final ConcurrentMap<String, FileDiskCache<?, ?>> caches = - new ConcurrentHashMap<String, FileDiskCache<?, ?>>(); + new ConcurrentHashMap<>(); /** Lock cache initialization */ private final Lock lock = new ReentrantLock(); @@ -76,8 +76,8 @@ public class FileDiskCacheManager * @param cacheEventLogger * @param elementSerializer */ - protected FileDiskCacheManager( FileDiskCacheAttributes defaultCacheAttributes, ICacheEventLogger cacheEventLogger, - IElementSerializer elementSerializer ) + protected FileDiskCacheManager( final FileDiskCacheAttributes defaultCacheAttributes, final ICacheEventLogger cacheEventLogger, + final IElementSerializer elementSerializer ) { this.defaultCacheAttributes = defaultCacheAttributes; this.elementSerializer = elementSerializer; @@ -90,9 +90,9 @@ public class FileDiskCacheManager * @param cacheName Name that will be used when creating attributes. * @return A cache. */ - public <K, V> FileDiskCache<K, V> getCache( String cacheName ) + public <K, V> FileDiskCache<K, V> getCache( final String cacheName ) { - FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.clone(); + final FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.clone(); cacheAttributes.setCacheName( cacheName ); @@ -107,11 +107,11 @@ public class FileDiskCacheManager * @return A cache, either from the existing set or newly created. */ @SuppressWarnings("unchecked") // Need to cast because of common map for all caches - public <K, V> FileDiskCache<K, V> getCache( FileDiskCacheAttributes cacheAttributes ) + public <K, V> FileDiskCache<K, V> getCache( final FileDiskCacheAttributes cacheAttributes ) { FileDiskCache<K, V> cache = null; - String cacheName = cacheAttributes.getCacheName(); + final String cacheName = cacheAttributes.getCacheName(); log.debug( "Getting cache named: " + cacheName ); @@ -131,7 +131,7 @@ public class FileDiskCacheManager // attributes if ( cache == null ) { - cache = new FileDiskCache<K, V>( cacheAttributes, elementSerializer ); + cache = new FileDiskCache<>( cacheAttributes, elementSerializer ); cache.setCacheEventLogger( eventLogger ); caches.put( cacheName, cache ); } diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactoryUnitTest.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactoryUnitTest.java index 8e2da345..d516a903 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactoryUnitTest.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactoryUnitTest.java @@ -35,19 +35,19 @@ public class FileDiskCacheFactoryUnitTest public void testCreateCache_Normal() { // SETUP - String cacheName = "testCreateCache_Normal"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testCreateCache_Normal"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/FileDiskCacheFactoryUnitTest" ); - ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); - ICacheEventLogger cacheEventLogger = new MockCacheEventLogger(); - IElementSerializer elementSerializer = new MockElementSerializer(); + final ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); + final ICacheEventLogger cacheEventLogger = new MockCacheEventLogger(); + final IElementSerializer elementSerializer = new MockElementSerializer(); - FileDiskCacheFactory factory = new FileDiskCacheFactory(); + final FileDiskCacheFactory factory = new FileDiskCacheFactory(); // DO WORK - FileDiskCache<String, String> result = factory.createCache( cattr, cacheMgr, cacheEventLogger, + final FileDiskCache<String, String> result = factory.createCache( cattr, cacheMgr, cacheEventLogger, elementSerializer ); // VERIFY diff --git a/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheUnitTest.java b/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheUnitTest.java index 69e948ac..b655d88b 100644 --- a/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheUnitTest.java +++ b/commons-jcs3-sandbox/commons-jcs3-filecache/src/test/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheUnitTest.java @@ -41,14 +41,14 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testInitialization_Normal"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testInitialization_Normal"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); // DO WORK - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); - File directory = diskCache.getDirectory(); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); + final File directory = diskCache.getDirectory(); // VERIFY assertNotNull( "Should have a directory", directory ); @@ -69,11 +69,11 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testDispose_Normal"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testDispose_Normal"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); // DO WORK diskCache.dispose(); @@ -93,14 +93,14 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testInitialization_JunkFileName"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testInitialization_JunkFileName"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest%$&*#@" ); // DO WORK - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); - File directory = diskCache.getDirectory(); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); + final File directory = diskCache.getDirectory(); // VERIFY assertNotNull( "Should have a directory", directory ); @@ -117,16 +117,16 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testGetSize_Empty"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testGetSize_Empty"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); diskCache.removeAll(); // DO WORK - int result = diskCache.getSize(); + final int result = diskCache.getSize(); // VERIFY assertEquals( "Should be empty.", 0, result ); @@ -141,18 +141,18 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testGetSize_OneItem"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testGetSize_OneItem"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); diskCache.removeAll(); - diskCache.update( new CacheElement<String, String>( cacheName, "key1", "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key1", "Data" ) ); SleepUtil.sleepAtLeast( 100 ); // DO WORK - int result = diskCache.getSize(); + final int result = diskCache.getSize(); // VERIFY assertEquals( "Should not be empty.", 1, result ); @@ -167,19 +167,19 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testRemoveAll_OneItem"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testRemoveAll_OneItem"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - diskCache.update( new CacheElement<String, String>( cacheName, "key1", "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key1", "Data" ) ); SleepUtil.sleepAtLeast( 100 ); // DO WORK diskCache.removeAll(); SleepUtil.sleepAtLeast( 100 ); - int result = diskCache.getSize(); + final int result = diskCache.getSize(); // VERIFY assertEquals( "Should be empty.", 0, result ); @@ -194,14 +194,14 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testGet_Empty"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testGet_Empty"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); // DO WORK - ICacheElement<String, String> result = diskCache.get( "key" ); + final ICacheElement<String, String> result = diskCache.get( "key" ); // VERIFY assertNull( "Should be null.", result ); @@ -216,17 +216,17 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testGet_Empty"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testGet_Empty"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - diskCache.update( new CacheElement<String, String>( cacheName, "key1", "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key1", "Data" ) ); SleepUtil.sleepAtLeast( 100 ); // DO WORK - ICacheElement<String, String> result = diskCache.get( "key1" ); + final ICacheElement<String, String> result = diskCache.get( "key1" ); // VERIFY assertNotNull( "Should NOT be null.", result ); @@ -241,17 +241,17 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - int maxNumberOfFiles = 10; - String cacheName = "testRemoveIfLimitIsSetAndReached_NotReached"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final int maxNumberOfFiles = 10; + final String cacheName = "testRemoveIfLimitIsSetAndReached_NotReached"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); cattr.setMaxNumberOfFiles( maxNumberOfFiles ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); for ( int i = 0; i < maxNumberOfFiles; i++ ) { - diskCache.update( new CacheElement<String, String>( cacheName, "key" + i, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + i, "Data" ) ); } SleepUtil.sleepAtLeast( 100 ); @@ -260,7 +260,7 @@ public class FileDiskCacheUnitTest for ( int i = 0; i < maxNumberOfFiles; i++ ) { final String key = "key" + i; - ICacheElement<String, String> result = diskCache.get( key ); + final ICacheElement<String, String> result = diskCache.get( key ); // System.out.println("Entry "+ key+ " null? " + (result==null)); if (result != null) { stillCached++; @@ -280,17 +280,17 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - int maxNumberOfFiles = 10; - String cacheName = "testRemoveIfLimitIsSetAndReached_Reached"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final int maxNumberOfFiles = 10; + final String cacheName = "testRemoveIfLimitIsSetAndReached_Reached"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); cattr.setMaxNumberOfFiles( maxNumberOfFiles ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); for ( int i = 0; i <= maxNumberOfFiles; i++ ) { - diskCache.update( new CacheElement<String, String>( cacheName, "key" + i, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + i, "Data" ) ); } SleepUtil.sleepAtLeast( 500 ); @@ -299,7 +299,7 @@ public class FileDiskCacheUnitTest for ( int i = 0; i <= maxNumberOfFiles; i++ ) { final String key = "key" + i; - ICacheElement<String, String> result = diskCache.get( key ); + final ICacheElement<String, String> result = diskCache.get( key ); // System.out.println("Entry "+ key+ " null? " + (result==null)); if (result != null) { stillCached++; @@ -320,19 +320,19 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - int maxNumberOfFiles = 10; - String cacheName = "testRemoveIfLimitIsSetAndReached_Reached_TouchTrue"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final int maxNumberOfFiles = 10; + final String cacheName = "testRemoveIfLimitIsSetAndReached_Reached_TouchTrue"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); cattr.setMaxNumberOfFiles( maxNumberOfFiles ); cattr.setTouchOnGet( true ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); diskCache.removeAll(); for ( int i = 0; i < maxNumberOfFiles; i++ ) { - diskCache.update( new CacheElement<String, String>( cacheName, "key" + i, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + i, "Data" ) ); } SleepUtil.sleepAtLeast( 100 ); @@ -341,18 +341,18 @@ public class FileDiskCacheUnitTest // tv: The Mac file system has 1 sec resolution, so this is the minimum value // to make this test work. SleepUtil.sleepAtLeast( 501 ); - ICacheElement<String, String> ice = diskCache.get( "key" + i ); + final ICacheElement<String, String> ice = diskCache.get( "key" + i ); assertNotNull("Value of key" + i + " should not be null", ice); } SleepUtil.sleepAtLeast( 100 ); // This will push it over. number 9, the youngest, but LRU item should be removed - diskCache.update( new CacheElement<String, String>( cacheName, "key" + maxNumberOfFiles, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + maxNumberOfFiles, "Data" ) ); SleepUtil.sleepAtLeast( 501 ); // DO WORK - ICacheElement<String, String> result = diskCache.get( "key9" ); + final ICacheElement<String, String> result = diskCache.get( "key9" ); // VERIFY assertNull( "Should be null.", result ); @@ -368,19 +368,19 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - int maxNumberOfFiles = 10; - String cacheName = "testRemoveIfLimitIsSetAndReached_Reached_TouchTrue"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final int maxNumberOfFiles = 10; + final String cacheName = "testRemoveIfLimitIsSetAndReached_Reached_TouchTrue"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); cattr.setMaxNumberOfFiles( maxNumberOfFiles ); cattr.setTouchOnGet( false ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); diskCache.removeAll(); for ( int i = 0; i < maxNumberOfFiles; i++ ) { - diskCache.update( new CacheElement<String, String>( cacheName, "key" + i, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + i, "Data" ) ); if (i == 0 ){ SleepUtil.sleepAtLeast( 1001 ); // ensure the first file is seen as older } @@ -395,11 +395,11 @@ public class FileDiskCacheUnitTest SleepUtil.sleepAtLeast( 100 ); // This will push it over. number 0, the oldest should be removed - diskCache.update( new CacheElement<String, String>( cacheName, "key" + maxNumberOfFiles, "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key" + maxNumberOfFiles, "Data" ) ); SleepUtil.sleepAtLeast( 100 ); // DO WORK - ICacheElement<String, String> result = diskCache.get( "key0" ); + final ICacheElement<String, String> result = diskCache.get( "key0" ); // VERIFY assertNull( "Should be null.", result ); @@ -414,16 +414,16 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testFile"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testFile"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - String key = "simplestring"; + final String key = "simplestring"; // DO WORK - File result = diskCache.file( key ); + final File result = diskCache.file( key ); // VERIFY assertEquals( "Wrong string.", key, result.getName() ); @@ -438,16 +438,16 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testFile"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testFile"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - String key = "simple string"; + final String key = "simple string"; // DO WORK - File result = diskCache.file( key ); + final File result = diskCache.file( key ); // VERIFY assertEquals( "Wrong string.", "simple_string", result.getName() ); @@ -462,16 +462,16 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testFile"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testFile"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - String key = "simple%string"; + final String key = "simple%string"; // DO WORK - File result = diskCache.file( key ); + final File result = diskCache.file( key ); // VERIFY assertEquals( "Wrong string.", "simple_string", result.getName() ); @@ -486,17 +486,17 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testFile"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testFile"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - String key = "simple%string"; - File firstResult = diskCache.file( key ); + final String key = "simple%string"; + final File firstResult = diskCache.file( key ); // DO WORK - File result = diskCache.file( firstResult.getName() ); + final File result = diskCache.file( firstResult.getName() ); // VERIFY assertEquals( "Wrong string.", "simple_string", result.getName() ); @@ -511,19 +511,19 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testRemove_OneItem"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testRemove_OneItem"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); - diskCache.update( new CacheElement<String, String>( cacheName, "key1", "Data" ) ); + diskCache.update( new CacheElement<>( cacheName, "key1", "Data" ) ); SleepUtil.sleepAtLeast( 100 ); // DO WORK diskCache.remove( "key1" ); SleepUtil.sleepAtLeast( 100 ); - int result = diskCache.getSize(); + final int result = diskCache.getSize(); // VERIFY assertEquals( "Should be empty.", 0, result ); @@ -538,14 +538,14 @@ public class FileDiskCacheUnitTest throws Exception { // SETUP - String cacheName = "testPutGet_BigString"; - FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); + final String cacheName = "testPutGet_BigString"; + final FileDiskCacheAttributes cattr = new FileDiskCacheAttributes(); cattr.setCacheName( cacheName ); cattr.setDiskPath( "target/test-sandbox/DiskFileCacheUnitTest" ); - FileDiskCache<String, String> diskCache = new FileDiskCache<String, String>( cattr ); + final FileDiskCache<String, String> diskCache = new FileDiskCache<>( cattr ); String string = "This is my big string ABCDEFGH"; - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append( string ); for ( int i = 0; i < 4; i++ ) { @@ -554,13 +554,13 @@ public class FileDiskCacheUnitTest string = sb.toString(); // DO WORK - diskCache.update( new CacheElement<String, String>( cacheName, "x", string ) ); + diskCache.update( new CacheElement<>( cacheName, "x", string ) ); SleepUtil.sleepAtLeast( 300 ); // VERIFY - ICacheElement<String, String> afterElement = diskCache.get( "x" ); + final ICacheElement<String, String> afterElement = diskCache.get( "x" ); assertNotNull( afterElement ); - String after = afterElement.getVal(); + final String after = afterElement.getVal(); assertNotNull( "afterElement = " + afterElement, after ); assertEquals( "wrong string after retrieval", string, after ); diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeHandler.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeHandler.java index 31261c5c..35f206a0 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeHandler.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeHandler.java @@ -26,15 +26,15 @@ import org.apache.commons.jcs.yajcache.lang.annotation.*; */ @CopyRightApache public interface ICacheChangeHandler<V> { - public boolean handlePut(@NonNullable String cacheName, + boolean handlePut(@NonNullable String cacheName, @NonNullable String key, @NonNullable V value); - public boolean handlePutCopy(@NonNullable String cacheName, + boolean handlePutCopy(@NonNullable String cacheName, @NonNullable String key, @NonNullable V value); - public boolean handlePutBeanCopy(@NonNullable String cacheName, + boolean handlePutBeanCopy(@NonNullable String cacheName, @NonNullable String key, @NonNullable V value); - public boolean handlePutBeanClone(@NonNullable String cacheName, + boolean handlePutBeanClone(@NonNullable String cacheName, @NonNullable String key, @NonNullable V value); - public boolean handleRemove( + boolean handleRemove( @NonNullable String cacheName, @NonNullable String key); - public boolean handleClear(@NonNullable String cacheName); + boolean handleClear(@NonNullable String cacheName); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeListener.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeListener.java index fd4c3d54..d580f537 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeListener.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/beans/ICacheChangeListener.java @@ -19,7 +19,6 @@ package org.apache.commons.jcs.yajcache.beans; * under the License. */ -import org.apache.commons.jcs.yajcache.beans.CacheChangeEvent; import org.apache.commons.jcs.yajcache.lang.annotation.*; /** @@ -27,5 +26,5 @@ import org.apache.commons.jcs.yajcache.lang.annotation.*; */ @CopyRightApache public interface ICacheChangeListener<V> extends java.util.EventListener { - public void cacheChange(@NonNullable CacheChangeEvent<V> evt); + void cacheChange(@NonNullable CacheChangeEvent<V> evt); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICache.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICache.java index b60fa7d1..c50b2702 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICache.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICache.java @@ -31,19 +31,18 @@ import java.util.Map; public interface ICache<V> extends Map<String,V> { /** Returns the cache name. */ @ThreadSafety(ThreadSafetyType.IMMUTABLE) - public @NonNullable String getName(); + @NonNullable String getName(); /** Returns the value type of the cached items. */ @ThreadSafety(ThreadSafetyType.IMMUTABLE) - public @NonNullable Class<V> getValueType(); + @NonNullable Class<V> getValueType(); /** Returns the value cached for the specified key. */ @ThreadSafety( value=ThreadSafetyType.SAFE, caveat="This method itself is thread-safe. However," + " the thread-safetyness of the return value cannot be guaranteed" + " by this interface." - ) - public V get(String key); + ) V get(String key); /** Returns the cache type. */ @ThreadSafety(ThreadSafetyType.IMMUTABLE) - public @NonNullable CacheType getCacheType(); + @NonNullable CacheType getCacheType(); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICacheSafe.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICacheSafe.java index 90b13022..53cb6384 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICacheSafe.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/core/ICacheSafe.java @@ -36,8 +36,7 @@ public interface ICacheSafe<V> extends ICache<V> { value=ThreadSafetyType.SAFE, note="The return value is guaranteed to be thread-safe" + " only if the return value type is Serializable." - ) - public V getCopy(@NonNullable String key); + ) V getCopy(@NonNullable String key); /** * If the cache value is Serializable, puts a deep clone copy of * the given value to the cache. Else, the behavior is the same as put. @@ -46,8 +45,7 @@ public interface ICacheSafe<V> extends ICache<V> { value=ThreadSafetyType.SAFE, note="The given value is guaranteed to be thread-safe" + " only if the value type is Serializable." - ) - public V putCopy(@NonNullable String key, @NonNullable V value); + ) V putCopy(@NonNullable String key, @NonNullable V value); /** * If the cache value is Serializable, puts the deep clone copies of * the given values to the cache. Else, the behavior is the same as putAll. @@ -57,8 +55,7 @@ public interface ICacheSafe<V> extends ICache<V> { caveat="The thread-safetyness of the given map cannot be guaranteed.", note="The given values in the map is guaranteed to be thread-safe" + " only if the value type is Serializable." - ) - public void putAllCopies(@NonNullable Map<? extends String, ? extends V> map); + ) void putAllCopies(@NonNullable Map<? extends String, ? extends V> map); /** * Treats the cache value as a Java Bean and returns a deep clone copy of * the cached value. @@ -67,8 +64,7 @@ public interface ICacheSafe<V> extends ICache<V> { value=ThreadSafetyType.SAFE, note="The return value is guaranteed to be thread-safe" + " only if the return value is a Java Bean." - ) - public V getBeanCopy(@NonNullable String key); + ) V getBeanCopy(@NonNullable String key); /** * Treats the cache value as a Java Bean and puts a deep clone copy of * the given value to the cache. @@ -77,8 +73,7 @@ public interface ICacheSafe<V> extends ICache<V> { value=ThreadSafetyType.SAFE, note="The given value is guaranteed to be thread-safe" + " only if the value is a Java Bean." - ) - public V putBeanCopy(@NonNullable String key, @NonNullable V value); + ) V putBeanCopy(@NonNullable String key, @NonNullable V value); /** * Treats the cache value as a Java Bean and puts the deep clone copies of * the given values to the cache. @@ -89,8 +84,7 @@ public interface ICacheSafe<V> extends ICache<V> { + " by this interface.", note="The given values in the map is guaranteed to be thread-safe" + " only if the values are Java Beans." - ) - public void putAllBeanCopies(@NonNullable Map<? extends String, ? extends V> map); + ) void putAllBeanCopies(@NonNullable Map<? extends String, ? extends V> map); /** * Treats the cache value as a Java Bean and returns a shallow clone copy of * the cached value. @@ -101,8 +95,7 @@ public interface ICacheSafe<V> extends ICache<V> { + " be garanteed by this interface.", note="The return value is guaranteed to be thread-safe" + " only if the return value is a JavaBean." - ) - public V getBeanClone(@NonNullable String key); + ) V getBeanClone(@NonNullable String key); /** * Treats the cache value as a Java Bean and puts a shallow clone copy of * the given value to the cache. @@ -113,8 +106,7 @@ public interface ICacheSafe<V> extends ICache<V> { + " be garanteed by this interface.", note="The given value is guaranteed to be thread-safe" + " only if the value is a Java Bean." - ) - public V putBeanClone(@NonNullable String key, @NonNullable V value); + ) V putBeanClone(@NonNullable String key, @NonNullable V value); /** * Treats the cache value as a Java Bean and puts the shallow clone copies of * the given values to the cache. @@ -127,6 +119,5 @@ public interface ICacheSafe<V> extends ICache<V> { + " in the map cannot be garanteed.", note="The given values in the map is guaranteed to be thread-safe" + " only if the values are Java Beans." - ) - public void putAllBeanClones(@NonNullable Map<? extends String, ? extends V> map); + ) void putAllBeanClones(@NonNullable Map<? extends String, ? extends V> map); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/lang/ref/IKey.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/lang/ref/IKey.java index 4a53af9b..ba4f29ef 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/lang/ref/IKey.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/lang/ref/IKey.java @@ -26,5 +26,5 @@ import org.apache.commons.jcs.yajcache.lang.annotation.*; @CopyRightApache public interface IKey<K> { /** Returns the key. */ - public @NonNullable @Immutable K getKey(); + @NonNullable @Immutable K getKey(); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/EqualsUtils.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/EqualsUtils.java index 6e6a9c78..e6af1b70 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/EqualsUtils.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/EqualsUtils.java @@ -31,45 +31,57 @@ public enum EqualsUtils { * when they are arrays. * Returns false otherwise. */ - public boolean equals(Object lhs, Object rhs) { - if (lhs == rhs) + public boolean equals(final Object lhs, final Object rhs) { + if (lhs == rhs) { return true; - if (lhs == null || rhs == null) + } + if (lhs == null || rhs == null) { return false; - Class lClass = lhs.getClass(); - Class rClass = rhs.getClass(); + } + final Class lClass = lhs.getClass(); + final Class rClass = rhs.getClass(); if (lClass.isArray() && rClass.isArray()) { - Class lCompType = lClass.getComponentType(); - Class rCompType = rClass.getComponentType(); + final Class lCompType = lClass.getComponentType(); + final Class rCompType = rClass.getComponentType(); if (lCompType.isPrimitive()) { if (rCompType.isPrimitive()) { - if (lCompType != rCompType) + if (lCompType != rCompType) { return false; - if (lCompType == int.class) + } + if (lCompType == int.class) { return Arrays.equals((int[])lhs, (int[])rhs); - if (lCompType == boolean.class) + } + if (lCompType == boolean.class) { return Arrays.equals((boolean[])lhs, (boolean[])rhs); - if (lCompType == byte.class) + } + if (lCompType == byte.class) { return Arrays.equals((byte[])lhs, (byte[])rhs); - if (lCompType == char.class) + } + if (lCompType == char.class) { return Arrays.equals((char[])lhs, (char[])rhs); - if (lCompType == double.class) + } + if (lCompType == double.class) { return Arrays.equals((double[])lhs, (double[])rhs); - if (lCompType == float.class) + } + if (lCompType == float.class) { return Arrays.equals((float[])lhs, (float[])rhs); - if (lCompType == long.class) + } + if (lCompType == long.class) { return Arrays.equals((long[])lhs, (long[])rhs); - if (lCompType == short.class) + } + if (lCompType == short.class) { return Arrays.equals((short[])lhs, (short[])rhs); + } } return false; } - if (rCompType.isPrimitive()) + if (rCompType.isPrimitive()) { return false; + } return Arrays.equals((Object[])lhs, (Object[])rhs); } return lhs.equals(rhs); diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/concurrent/locks/IKeyedReadWriteLock.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/concurrent/locks/IKeyedReadWriteLock.java index ba530d2e..02c195e0 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/concurrent/locks/IKeyedReadWriteLock.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/main/java/org/apache/commons/jcs/yajcache/util/concurrent/locks/IKeyedReadWriteLock.java @@ -27,6 +27,6 @@ import java.util.concurrent.locks.Lock; */ @CopyRightApache public interface IKeyedReadWriteLock<K> { - public Lock readLock(K key); - public Lock writeLock(K key); + Lock readLock(K key); + Lock writeLock(K key); } diff --git a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/FileContentTypeTest.java b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/FileContentTypeTest.java index ca2297fa..d9f2eff6 100644 --- a/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/FileContentTypeTest.java +++ b/commons-jcs3-sandbox/commons-jcs3-yajcache/src/test/java/org/apache/commons/jcs/yajcache/file/FileContentTypeTest.java @@ -31,14 +31,14 @@ import org.apache.commons.logging.LogFactory; @CopyRightApache @TestOnly public class FileContentTypeTest extends TestCase { - private Log log = LogFactory.getLog(this.getClass()); + private final Log log = LogFactory.getLog(this.getClass()); /** * Test of toByte method, of class org.apache.commons.jcs.yajcache.config.FileContentType. */ public void test() { log.debug("test toByte"); - Byte bJavaSerialization = CacheFileContentType.JAVA_SERIALIZATION.toByte(); - Byte bXmlEncoder = CacheFileContentType.XML_ENCODER.toByte(); + final Byte bJavaSerialization = CacheFileContentType.JAVA_SERIALIZATION.toByte(); + final Byte bXmlEncoder = CacheFileContentType.XML_ENCODER.toByte(); assertFalse(bJavaSerialization == bXmlEncoder); log.debug("test fromByte"); assertTrue(CacheFileContentType.JAVA_SERIALIZATION == CacheFileContentType.fromByte(bJavaSerialization)); @@ -47,7 +47,7 @@ public class FileContentTypeTest extends TestCase { try { CacheFileContentType.fromByte((byte)99); assert false; - } catch (IllegalArgumentException ex) { + } catch (final IllegalArgumentException ex) { } } }