You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/11/22 11:38:38 UTC

svn commit: r348145 - /directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java

Author: elecharny
Date: Tue Nov 22 02:38:30 2005
New Revision: 348145

URL: http://svn.apache.org/viewcvs?rev=348145&view=rev
Log:
Changed the LRUMap name to SynchronizedLRUMap

Added:
    directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java
      - copied, changed from r347975, directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/LRUMap.java

Copied: directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java (from r347975, directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/LRUMap.java)
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java?p2=directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java&p1=directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/LRUMap.java&r1=347975&r2=348145&rev=348145&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/LRUMap.java (original)
+++ directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/SynchronizedLRUMap.java Tue Nov 22 02:38:30 2005
@@ -16,10 +16,6 @@
 package org.apache.ldap.common.util;
 
 import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Iterator;
 
 /**
  * <p>
@@ -48,7 +44,10 @@
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  * @author <a href="mailto:morgand@apache.org">Morgan Delagrange</a>
  */
-public final class LRUMap extends SequencedHashMap implements Externalizable {
+public final class SynchronizedLRUMap extends SequencedHashMap implements Externalizable {
+    // add a serial version uid, so that if we change things in the future
+    // without changing the format, we can still deserialize properly.
+    private static final long serialVersionUID = 2197433140769957051L;
         
     private int maximumSize = 0;
 
@@ -58,7 +57,7 @@
      * LRU limit of 100 keys, but this value may be overridden
      * internally as a result of de-externalization.
      */
-    public LRUMap() 
+    public SynchronizedLRUMap() 
     {
         this( 100 );
     }
@@ -70,7 +69,7 @@
      * 
      * @param i      Maximum capacity of the LRUMap
      */
-    public LRUMap(int i) 
+    public SynchronizedLRUMap(int i) 
     {
         super( i );
         maximumSize = i;
@@ -90,12 +89,12 @@
      */
     public synchronized Object get(Object key) 
     {
-    	if(!containsKey(key)) 
+    	if ( !containsKey( key ) ) 
     	{
     		return null;
     	}
     
-    	Object value = remove(key);
+    	Object value = remove( key );
         super.put(key, value);
         return value;
     }
@@ -124,20 +123,20 @@
 	        {
 	            // don't retire LRU if you are just
 	            // updating an existing key
-	            if (!containsKey(key)) 
+	            if ( !containsKey( key) ) 
 	            {
 	                // lets retire the least recently used item in the cache
 	                removeLRU();
 	            }
 
-	            retval = super.put(key,value);
+	            retval = super.put( key, value );
 	        }
         }
         else
         {
         	synchronized ( this )
         	{
-        		retval = super.put(key,value);
+        		retval = super.put( key, value);
         	}
         }
         
@@ -153,42 +152,11 @@
         Object key = getFirstKey();
         // be sure to call super.get(key), or you're likely to 
         // get infinite promotion recursion
-        super.get(key);
+        super.get( key );
         
         remove(key);
     }
 
-    // Externalizable interface
-    //-------------------------------------------------------------------------        
-    public void readExternal( ObjectInput in )  throws IOException, ClassNotFoundException 
-    {
-        maximumSize = in.readInt();
-        int size = in.readInt();
-        
-        for( int i = 0; i < size; i++ )  
-        {
-            Object key = in.readObject();
-            Object value = in.readObject();
-            put(key,value);
-        }
-    }
-
-    public void writeExternal( ObjectOutput out ) throws IOException {
-        out.writeInt( maximumSize );
-        out.writeInt( size() );
-        
-        for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) 
-        {
-            Object key = iterator.next();
-            out.writeObject( key );
-            // be sure to call super.get(key), or you're likely to 
-            // get infinite promotion recursion
-            Object value = super.get( key );
-            out.writeObject( value );
-        }
-    }
-    
-    
     // Properties
     //-------------------------------------------------------------------------        
     /** Getter for property maximumSize.
@@ -214,9 +182,4 @@
 	        }
         }
     }
-
-
-    // add a serial version uid, so that if we change things in the future
-    // without changing the format, we can still deserialize properly.
-    private static final long serialVersionUID = 2197433140769957051L;
 }