You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2014/04/03 03:13:37 UTC

svn commit: r1584239 - in /commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access: AbstractCacheAccess.java CacheAccess.java GroupCacheAccess.java

Author: sebb
Date: Thu Apr  3 01:13:37 2014
New Revision: 1584239

URL: http://svn.apache.org/r1584239
Log:
Don't expose mutable fields

Modified:
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/AbstractCacheAccess.java
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/CacheAccess.java
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/GroupCacheAccess.java

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/AbstractCacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/AbstractCacheAccess.java?rev=1584239&r1=1584238&r2=1584239&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/AbstractCacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/AbstractCacheAccess.java Thu Apr  3 01:13:37 2014
@@ -48,7 +48,7 @@ public abstract class AbstractCacheAcces
      * <p>
      * TODO Should this be the interface?
      */
-    protected CompositeCache<K, V> cacheControl;
+    private final CompositeCache<K, V> cacheControl;
 
     /**
      * Constructor for the CacheAccess object.
@@ -71,7 +71,7 @@ public abstract class AbstractCacheAcces
     {
         try
         {
-            this.cacheControl.removeAll();
+            this.getCacheControl().removeAll();
         }
         catch ( IOException e )
         {
@@ -93,7 +93,7 @@ public abstract class AbstractCacheAcces
     public void setDefaultElementAttributes( IElementAttributes attr )
         throws CacheException
     {
-        this.cacheControl.setElementAttributes( attr );
+        this.getCacheControl().setElementAttributes( attr );
     }
 
     /**
@@ -110,7 +110,7 @@ public abstract class AbstractCacheAcces
     public IElementAttributes getDefaultElementAttributes()
         throws CacheException
     {
-        return this.cacheControl.getElementAttributes();
+        return this.getCacheControl().getElementAttributes();
     }
 
     /**
@@ -123,7 +123,7 @@ public abstract class AbstractCacheAcces
     @Override
     public ICacheStats getStatistics()
     {
-        return this.cacheControl.getStatistics();
+        return this.getCacheControl().getStatistics();
     }
 
     /**
@@ -132,7 +132,7 @@ public abstract class AbstractCacheAcces
     @Override
     public String getStats()
     {
-        return this.cacheControl.getStats();
+        return this.getCacheControl().getStats();
     }
 
     /**
@@ -144,7 +144,7 @@ public abstract class AbstractCacheAcces
     @Override
     public void dispose()
     {
-        this.cacheControl.dispose();
+        this.getCacheControl().dispose();
     }
 
     /**
@@ -156,7 +156,7 @@ public abstract class AbstractCacheAcces
     @Override
     public ICompositeCacheAttributes getCacheAttributes()
     {
-        return this.cacheControl.getCacheAttributes();
+        return this.getCacheControl().getCacheAttributes();
     }
 
     /**
@@ -167,7 +167,7 @@ public abstract class AbstractCacheAcces
     @Override
     public void setCacheAttributes( ICompositeCacheAttributes cattr )
     {
-        this.cacheControl.setCacheAttributes( cattr );
+        this.getCacheControl().setCacheAttributes( cattr );
     }
 
     /**
@@ -187,7 +187,7 @@ public abstract class AbstractCacheAcces
         int numFreed = -1;
         try
         {
-            numFreed = this.cacheControl.getMemoryCache().freeElements( numberToFree );
+            numFreed = this.getCacheControl().getMemoryCache().freeElements( numberToFree );
         }
         catch ( IOException ioe )
         {
@@ -196,4 +196,9 @@ public abstract class AbstractCacheAcces
         }
         return numFreed;
     }
+
+    public CompositeCache<K, V> getCacheControl() {
+        return cacheControl;
+    }
+
 }

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/CacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/CacheAccess.java?rev=1584239&r1=1584238&r2=1584239&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/CacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/CacheAccess.java Thu Apr  3 01:13:37 2014
@@ -74,7 +74,7 @@ public class CacheAccess<K extends Seria
     @Override
     public V get( K name )
     {
-        ICacheElement<K, V> element = this.cacheControl.get( name );
+        ICacheElement<K, V> element = this.getCacheControl().get( name );
 
         return ( element != null ) ? element.getVal() : null;
     }
@@ -90,7 +90,7 @@ public class CacheAccess<K extends Seria
     {
         HashMap<K, V> unwrappedResults = new HashMap<K, V>();
 
-        Map<K, ICacheElement<K, V>> wrappedResults = this.cacheControl.getMatching( pattern );
+        Map<K, ICacheElement<K, V>> wrappedResults = this.getCacheControl().getMatching( pattern );
         if ( wrappedResults != null )
         {
             for (Map.Entry<K, ICacheElement<K, V>> entry : wrappedResults.entrySet())
@@ -123,7 +123,7 @@ public class CacheAccess<K extends Seria
     @Override
     public ICacheElement<K, V> getCacheElement( K name )
     {
-        return this.cacheControl.get( name );
+        return this.getCacheControl().get( name );
     }
 
     /**
@@ -146,7 +146,7 @@ public class CacheAccess<K extends Seria
     @Override
     public Map<K, ICacheElement<K, V>> getCacheElements( Set<K> names )
     {
-        return this.cacheControl.getMultiple( names );
+        return this.getCacheControl().getMultiple( names );
     }
 
     /**
@@ -169,7 +169,7 @@ public class CacheAccess<K extends Seria
     @Override
     public Map<K, ICacheElement<K, V>> getMatchingCacheElements( String pattern )
     {
-        return this.cacheControl.getMatching( pattern );
+        return this.getCacheControl().getMatching( pattern );
     }
 
     /**
@@ -186,7 +186,7 @@ public class CacheAccess<K extends Seria
     public void putSafe( K key, V value )
         throws CacheException
     {
-        if ( this.cacheControl.get( key ) != null )
+        if ( this.getCacheControl().get( key ) != null )
         {
             throw new ObjectExistsException( "putSafe failed.  Object exists in the cache for key [" + key
                 + "].  Remove first or use a non-safe put to override the value." );
@@ -208,7 +208,7 @@ public class CacheAccess<K extends Seria
     {
         // Call put with a copy of the contained caches default attributes.
         // the attributes are copied by the cacheControl
-        put( name, obj, this.cacheControl.getElementAttributes() );
+        put( name, obj, this.getCacheControl().getElementAttributes() );
     }
 
     /**
@@ -237,12 +237,12 @@ public class CacheAccess<K extends Seria
         // should be wrapped by cache access.
         try
         {
-            CacheElement<K, V> ce = new CacheElement<K, V>( this.cacheControl.getCacheName(), key,
+            CacheElement<K, V> ce = new CacheElement<K, V>( this.getCacheControl().getCacheName(), key,
                                                 val );
 
             ce.setElementAttributes( attr );
 
-            this.cacheControl.update( ce );
+            this.getCacheControl().update( ce );
         }
         catch ( IOException e )
         {
@@ -260,7 +260,7 @@ public class CacheAccess<K extends Seria
     public void remove( K name )
         throws CacheException
     {
-        this.cacheControl.remove( name );
+        this.getCacheControl().remove( name );
     }
 
     /**
@@ -276,7 +276,7 @@ public class CacheAccess<K extends Seria
     public void resetElementAttributes( K name, IElementAttributes attr )
         throws CacheException, InvalidHandleException
     {
-        ICacheElement<K, V> element = this.cacheControl.get( name );
+        ICacheElement<K, V> element = this.getCacheControl().get( name );
 
         if ( element == null )
         {
@@ -308,7 +308,7 @@ public class CacheAccess<K extends Seria
 
         try
         {
-            attr = this.cacheControl.getElementAttributes( name );
+            attr = this.getCacheControl().getElementAttributes( name );
         }
         catch ( IOException ioe )
         {

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/GroupCacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/GroupCacheAccess.java?rev=1584239&r1=1584238&r2=1584239&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/GroupCacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/access/GroupCacheAccess.java Thu Apr  3 01:13:37 2014
@@ -63,7 +63,7 @@ public class GroupCacheAccess<K extends 
     @Override
     public V getFromGroup( K name, String group )
     {
-        ICacheElement<GroupAttrName<K>, V> element = this.cacheControl.get( getGroupAttrName( group, name ) );
+        ICacheElement<GroupAttrName<K>, V> element = this.getCacheControl().get( getGroupAttrName( group, name ) );
         return ( element != null ) ? element.getVal() : null;
     }
 
@@ -76,7 +76,7 @@ public class GroupCacheAccess<K extends 
      */
     private GroupAttrName<K> getGroupAttrName( String group, K name )
     {
-        GroupId gid = new GroupId( this.cacheControl.getCacheName(), group );
+        GroupId gid = new GroupId( this.getCacheControl().getCacheName(), group );
         return new GroupAttrName<K>( gid, name );
     }
 
@@ -135,12 +135,12 @@ public class GroupCacheAccess<K extends 
         {
             GroupAttrName<K> key = getGroupAttrName( groupName, name );
             CacheElement<GroupAttrName<K>, V> ce =
-                new CacheElement<GroupAttrName<K>, V>( this.cacheControl.getCacheName(), key, value );
+                new CacheElement<GroupAttrName<K>, V>( this.getCacheControl().getCacheName(), key, value );
 
-            IElementAttributes attributes = (attr == null) ? this.cacheControl.getElementAttributes() : attr;
+            IElementAttributes attributes = (attr == null) ? this.getCacheControl().getElementAttributes() : attr;
             ce.setElementAttributes( attributes );
 
-            this.cacheControl.update( ce );
+            this.getCacheControl().update( ce );
         }
         catch ( IOException e )
         {
@@ -157,7 +157,7 @@ public class GroupCacheAccess<K extends 
     public void removeFromGroup( K name, String group )
     {
         GroupAttrName<K> key = getGroupAttrName( group, name );
-        this.cacheControl.remove( key );
+        this.getCacheControl().remove( key );
     }
 
     /**
@@ -170,9 +170,9 @@ public class GroupCacheAccess<K extends 
     public Set<K> getGroupKeys( String group )
     {
         Set<K> groupKeys = new HashSet<K>();
-        GroupId groupId = new GroupId( this.cacheControl.getCacheName(), group );
+        GroupId groupId = new GroupId( this.getCacheControl().getCacheName(), group );
 
-        for (GroupAttrName<K> gan : this.cacheControl.getKeySet())
+        for (GroupAttrName<K> gan : this.getCacheControl().getKeySet())
         {
             if (gan.groupId.equals( groupId ))
             {
@@ -191,7 +191,7 @@ public class GroupCacheAccess<K extends 
     public Set<String> getGroupNames()
     {
         HashSet<String> names = new HashSet<String>();
-        for (GroupAttrName<K> gan : this.cacheControl.getKeySet())
+        for (GroupAttrName<K> gan : this.getCacheControl().getKeySet())
         {
             names.add(gan.groupId.groupName);
         }
@@ -207,6 +207,6 @@ public class GroupCacheAccess<K extends 
     @Override
     public void invalidateGroup( String group )
     {
-        this.cacheControl.remove(getGroupAttrName(group, null));
+        this.getCacheControl().remove(getGroupAttrName(group, null));
     }
 }