colus       02/01/08 04:44:32

  Modified:    src/scratchpad/org/apache/avalon/excalibur/cache Cache.java
                        CacheStore.java DefaultCache.java
  Log:
  Fixed item existence check.
  More javadoc about key is not null. but value is possiable to be null.
  
  Revision  Changes    Path
  1.5       +7 -6      
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/Cache.java
  
  Index: Cache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/Cache.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Cache.java        11 Dec 2001 09:53:33 -0000      1.4
  +++ Cache.java        8 Jan 2002 12:44:32 -0000       1.5
  @@ -12,6 +12,7 @@
   
   /**
    * This is a cache that caches objects for reuse.
  + * Key is must not <code>null. Value is possible to <code>null</code>.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Eung-ju Park</a>
    */
  @@ -55,9 +56,9 @@
   
       /**
        * Puts a new item in the cache. If the cache is full, remove the 
selected item.
  -     * @param key
  -     * @param value
  -     * @return old value
  +     * @param key key for the item
  +     * @param value item
  +     * @return old value. null if old value not exists.
        */
       Object put( Object key, Object value );
   
  @@ -65,7 +66,7 @@
        * Get an item from the cache.
        *
        * @param key key to lookup the item
  -     * @return the matching object in the cache
  +     * @return the matching object in the cache. null if item not exists.
        */
       Object get( Object key );
   
  @@ -73,13 +74,13 @@
        * Removes an item from the cache.
        *
        * @param key key to remove
  -     * @return the value removed
  +     * @return the value removed. null if old value not exists.
        */
       Object remove( Object key );
   
       /**
        * @param key
  -     * @return
  +     * @return true if matching item in the cache
        */
       boolean containsKey( Object key );
   
  
  
  
  1.5       +4 -0      
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/CacheStore.java
  
  Index: CacheStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/CacheStore.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CacheStore.java   11 Dec 2001 09:53:33 -0000      1.4
  +++ CacheStore.java   8 Jan 2002 12:44:32 -0000       1.5
  @@ -32,6 +32,10 @@
   
       boolean isFull();
   
  +    /**
  +     * @param key not null
  +     * @param value may be null
  +     */
       Object put( Object key, Object value );
   
       Object get( Object key );
  
  
  
  1.6       +18 -2     
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/DefaultCache.java
  
  Index: DefaultCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/cache/DefaultCache.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultCache.java 11 Dec 2001 09:53:33 -0000      1.5
  +++ DefaultCache.java 8 Jan 2002 12:44:32 -0000       1.6
  @@ -100,9 +100,25 @@
   
       public boolean containsKey( final Object key )
       {
  -        boolean contains;
  +        boolean contains = false;
   
  -        return ( null != get( key ) );
  +        synchronized ( m_store )
  +        {
  +            if ( m_store.containsKey( key ) )
  +            {
  +                final Object value = m_store.get( key );
  +                if ( validate( key, value ) )
  +                {
  +                    contains = true;
  +                }
  +                else
  +                {
  +                    remove( key );
  +                }
  +            }
  +        }
  +
  +        return contains;
       }
   
       public void clear()
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to