directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1435064 [3/7] - in /directory/jdbm/trunk/jdbm1: ./ src/ src/etc/ src/examples/ src/main/ src/main/java/ src/main/java/jdbm/ src/main/java/jdbm/btree/ src/main/java/jdbm/helper/ src/main/java/jdbm/htree/ src/main/java/jdbm/recman/ src/main/...
Date Fri, 18 Jan 2013 10:10:57 GMT
Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Conversion.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Conversion.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Conversion.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Conversion.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,229 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+import jdbm.I18n;
+
+
+/**
+ * Miscelaneous conversion utility methods.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class Conversion
+{
+
+    /**
+     * Convert a string into a byte array.
+     */
+    public static byte[] convertToByteArray( String s )
+    {
+        try
+        {
+            // see the following page for character encoding
+            // http://java.sun.com/products/jdk/1.1/docs/guide/intl/encoding.doc.html
+            return s.getBytes( "UTF8" );
+        }
+        catch ( java.io.UnsupportedEncodingException uee )
+        {
+            uee.printStackTrace();
+            throw new Error( I18n.err( I18n.ERR_527 ) );
+        }
+    }
+
+
+    /**
+     * Convert a byte into a byte array.
+     */
+    public static byte[] convertToByteArray( byte n )
+    {
+        n = ( byte ) ( n ^ ( ( byte ) 0x80 ) ); // flip MSB because "byte" is signed
+        return new byte[]
+            { n };
+    }
+
+
+    /**
+     * Convert a short into a byte array.
+     */
+    public static byte[] convertToByteArray( short n )
+    {
+        n = ( short ) ( n ^ ( ( short ) 0x8000 ) ); // flip MSB because "short" is signed
+        byte[] key = new byte[2];
+        pack2( key, 0, n );
+        return key;
+    }
+
+
+    /**
+     * Convert an int into a byte array.
+     */
+    public static byte[] convertToByteArray( int n )
+    {
+        n = ( n ^ 0x80000000 ); // flip MSB because "int" is signed
+        byte[] key = new byte[4];
+        pack4( key, 0, n );
+        return key;
+    }
+
+
+    /**
+     * Convert a long into a byte array.
+     */
+    public static byte[] convertToByteArray( long n )
+    {
+        n = ( n ^ 0x8000000000000000L ); // flip MSB because "long" is signed
+        byte[] key = new byte[8];
+        pack8( key, 0, n );
+        return key;
+    }
+
+
+    /**
+     * Convert a byte array (encoded as UTF-8) into a String
+     */
+    public static String convertToString( byte[] buf )
+    {
+        try
+        {
+            // see the following page for character encoding
+            // http://java.sun.com/products/jdk/1.1/docs/guide/intl/encoding.doc.html
+            return new String( buf, "UTF8" );
+        }
+        catch ( java.io.UnsupportedEncodingException uee )
+        {
+            uee.printStackTrace();
+            throw new Error( I18n.err( I18n.ERR_527 ) );
+        }
+    }
+
+
+    /**
+     * Convert a byte array into an integer (signed 32-bit) value.
+     */
+    public static int convertToInt( byte[] buf )
+    {
+        int value = unpack4( buf, 0 );
+        value = ( value ^ 0x80000000 ); // flip MSB because "int" is signed
+        return value;
+    }
+
+
+    /**
+     * Convert a byte array into a long (signed 64-bit) value.
+     */
+    public static long convertToLong( byte[] buf )
+    {
+        long value = ( ( long ) unpack4( buf, 0 ) << 32 )
+            + ( unpack4( buf, 4 ) & 0xFFFFFFFFL );
+        value = ( value ^ 0x8000000000000000L ); // flip MSB because "long" is signed
+        return value;
+    }
+
+
+    static int unpack4( byte[] buf, int offset )
+    {
+        int value = ( buf[offset] << 24 )
+            | ( ( buf[offset + 1] << 16 ) & 0x00FF0000 )
+            | ( ( buf[offset + 2] << 8 ) & 0x0000FF00 )
+            | ( ( buf[offset + 3] << 0 ) & 0x000000FF );
+
+        return value;
+    }
+
+
+    static final void pack2( byte[] data, int offs, int val )
+    {
+        data[offs++] = ( byte ) ( val >> 8 );
+        data[offs++] = ( byte ) val;
+    }
+
+
+    static final void pack4( byte[] data, int offs, int val )
+    {
+        data[offs++] = ( byte ) ( val >> 24 );
+        data[offs++] = ( byte ) ( val >> 16 );
+        data[offs++] = ( byte ) ( val >> 8 );
+        data[offs++] = ( byte ) val;
+    }
+
+
+    static final void pack8( byte[] data, int offs, long val )
+    {
+        pack4( data, 0, ( int ) ( val >> 32 ) );
+        pack4( data, 4, ( int ) val );
+    }
+
+
+    /**
+     * Test static methods
+     */
+    public static void main( String[] args )
+    {
+        byte[] buf;
+
+        buf = convertToByteArray( 5 );
+        System.out.println( "int value of 5 is: " + convertToInt( buf ) );
+
+        buf = convertToByteArray( -1 );
+        System.out.println( "int value of -1 is: " + convertToInt( buf ) );
+
+        buf = convertToByteArray( 22111000 );
+        System.out.println( "int value of 22111000 is: " + convertToInt( buf ) );
+
+        buf = convertToByteArray( 5L );
+        System.out.println( "long value of 5 is: " + convertToLong( buf ) );
+
+        buf = convertToByteArray( -1L );
+        System.out.println( "long value of -1 is: " + convertToLong( buf ) );
+
+        buf = convertToByteArray( 1112223334445556667L );
+        System.out.println( "long value of 1112223334445556667 is: " + convertToLong( buf ) );
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/DefaultSerializer.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/DefaultSerializer.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/DefaultSerializer.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/DefaultSerializer.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,102 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+package jdbm.helper;
+
+
+import java.io.IOException;
+
+
+/**
+ * Default java serializer.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class DefaultSerializer implements Serializer
+{
+    private static final long serialVersionUID = -3818545055661017388L;
+
+    public static final DefaultSerializer INSTANCE = new DefaultSerializer();
+    
+    
+    /**
+     * Construct a DefaultSerializer.
+     */
+    public DefaultSerializer()
+    {
+        // no op
+    }
+
+    
+    /**
+     * Serialize the content of an object into a byte array.
+     *
+     * @param obj Object to serialize
+     * @return a byte array representing the object's state
+     */
+     public byte[] serialize( Object obj ) throws IOException
+     {
+         return Serialization.serialize( obj );
+     }
+        
+        
+    /**
+     * De-serialize the content of an object from a byte array.
+     *
+     * @param serialized Byte array representation of the object
+     * @return de-serialized object
+     */
+     public Object deserialize( byte[] serialized ) throws IOException
+     {
+         try 
+         {
+            return Serialization.deserialize( serialized );
+         } 
+         catch ( ClassNotFoundException except ) 
+         {
+            throw new WrappedRuntimeException( except );
+         }
+     }
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/FastIterator.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/FastIterator.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/FastIterator.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/FastIterator.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,67 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id: FastIterator.java,v 1.2 2003/10/21 15:43:58 boisvert Exp $
+ */
+
+package jdbm.helper;
+
+
+/**
+ * Fast and simple iterator.
+ *
+ * @author <a href="boisvert@intalio.com">Alex Boisvert</a>
+ */
+public abstract class FastIterator
+{
+
+    /**
+     * Returns the next element in the interation.
+     *
+     * @return the next element in the iteration, or null if no more element.
+     */
+    public abstract Object next()
+        throws IterationException;
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerComparator.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerComparator.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerComparator.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerComparator.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,115 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import jdbm.I18n;
+
+
+/**
+ * Comparator for Integer objects.
+ *
+ * @author <a href="mailto:cdaller@iicm.edu">Christof Dallermassl</a>
+ */
+public final class IntegerComparator
+    implements Comparator<Integer>, Serializable
+{
+
+    /**
+     * Version id for serialization.
+     */
+    final static long serialVersionUID = 1L;
+
+
+    /**
+     * Compare two objects.
+     *
+     * @param obj1 First object
+     * @param obj2 Second object
+     * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
+     *         and a negative integer if obj1 < obj2
+     */
+    public int compare( Integer obj1, Integer obj2 )
+    {
+        if ( obj1 == obj2 )
+        {
+            return 0;
+        }
+
+        if ( obj1 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) );
+        }
+
+        if ( obj2 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) );
+        }
+
+        // complicated to avoid usage of Integer.compareTo, as this
+        // method is Java 1.2 only!
+        int int1 = obj1.intValue();
+        int int2 = obj2.intValue();
+        if ( int1 == int2 )
+        {
+            return 0;
+        }
+
+        if ( int1 < int2 )
+        {
+            return -1;
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerSerializer.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerSerializer.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerSerializer.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IntegerSerializer.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,100 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.IOException;
+
+/**
+ * Optimized serializer for integers.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class IntegerSerializer
+    implements Serializer
+{
+
+    
+    public static final IntegerSerializer INSTANCE = new IntegerSerializer();
+    
+    
+    /**
+     * Construct an IntegerSerializer.
+     */
+    public IntegerSerializer()
+    {
+        // no op
+    }
+
+    
+    /**
+     * Serialize the content of an object into a byte array.
+     *
+     * @param obj Object to serialize
+     * @return a byte array representing the object's state
+     */
+     public byte[] serialize( Object obj )
+        throws IOException
+     {
+         Integer number = (Integer) obj;
+         return Conversion.convertToByteArray( number.intValue() );
+     }
+        
+        
+    /**
+     * Deserialize the content of an object from a byte array.
+     *
+     * @param serialized Byte array representation of the object
+     * @return deserialized object
+     */
+     public Object deserialize( byte[] serialized )
+        throws IOException
+     {
+         int number = Conversion.convertToInt( serialized );
+         return Integer.valueOf( number );
+     }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IterationException.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IterationException.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IterationException.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/IterationException.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,96 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id: IterationException.java,v 1.2 2003/09/21 15:47:00 boisvert Exp $
+ */
+
+package jdbm.helper;
+
+
+/**
+ * Iteration exception.
+ *
+ * @author <a href="boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class IterationException
+    extends WrappedRuntimeException
+{
+
+    /**
+     * Construct a new iteration exception wrapping an underlying exception
+     * and providing a message.
+     *
+     * @param message The exception message
+     * @param except The underlying exception
+     */
+    public IterationException( String message, Exception except )
+    {
+        super( message, except );
+    }
+
+
+    /**
+     * Construct a new iteration exception with a message.
+     *
+     * @param message The exception message
+     */
+    public IterationException( String message )
+    {
+        super( message, null );
+    }
+
+
+    /**
+     * Construct a new iteration exception wrapping an underlying exception.
+     *
+     * @param except The underlying exception
+     */
+    public IterationException( Exception except )
+    {
+        super( except );
+    }
+
+}
+
+

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongComparator.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongComparator.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongComparator.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongComparator.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,108 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import jdbm.I18n;
+
+
+/**
+ * Comparator for java.lang.Long objects.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public final class LongComparator
+    implements Comparator<Long>, Serializable
+{
+
+    /**
+     * Version id for serialization.
+     */
+    final static long serialVersionUID = 1L;
+
+
+    /**
+     * Compare two objects.
+     *
+     * @param obj1 First object
+     * @param obj2 Second object
+     * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
+     *         and a negative integer if obj1 < obj2
+     */
+    public int compare( Long obj1, Long obj2 )
+    {
+        if ( obj1 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) );
+        }
+
+        if ( obj2 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) );
+        }
+
+        long l1 = obj1.longValue();
+        long l2 = obj2.longValue();
+
+        if ( l1 > l2 )
+        {
+            return 1;
+        }
+        else if ( l1 == l2 )
+        {
+            return 0;
+        }
+        else
+        {
+            return -1;
+        }
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongSerializer.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongSerializer.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongSerializer.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/LongSerializer.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,100 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.IOException;
+
+/**
+ * Optimized serializer for long integers.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class LongSerializer 
+    implements Serializer
+{
+
+    
+    public static final LongSerializer INSTANCE = new LongSerializer();
+    
+    
+    /**
+     * Construct a LongSerializer.
+     */
+    public LongSerializer()
+    {
+        // no op
+    }
+
+    
+    /**
+     * Serialize the content of an object into a byte array.
+     *
+     * @param obj Object to serialize
+     * @return a byte array representing the object's state
+     */
+     public byte[] serialize( Object obj )
+        throws IOException
+     {
+         Long number = (Long) obj;
+         return Conversion.convertToByteArray( number.longValue() );
+     }
+        
+        
+    /**
+     * Deserialize the content of an object from a byte array.
+     *
+     * @param serialized Byte array representation of the object
+     * @return deserialized object
+     */
+     public Object deserialize( byte[] serialized )
+        throws IOException
+     {
+         long number = Conversion.convertToLong( serialized );
+         return Long.valueOf( number );
+     }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/MRU.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/MRU.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/MRU.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/MRU.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,416 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id: MRU.java,v 1.8 2005/06/25 23:12:31 doomdark Exp $
+ */
+
+package jdbm.helper;
+
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import jdbm.I18n;
+
+
+/**
+ *  MRU - Most Recently Used cache policy.
+ *
+ *  Methods are *not* synchronized, so no concurrent access is allowed.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class MRU<K, V> implements CachePolicy<K, V>
+{
+    /** Cached object Map */
+    Map<Object, CacheEntry> map = new HashMap<Object, CacheEntry>();
+
+    /**
+     * Maximum number of objects in the cache.
+     */
+    int max;
+
+    /**
+     * Beginning of linked-list of cache elements.  First entry is element
+     * which has been used least recently.
+     */
+    CacheEntry first;
+
+    /**
+     * End of linked-list of cache elements.  Last entry is element
+     * which has been used most recently.
+     */
+    CacheEntry last;
+
+    /**
+     * Cache eviction listeners
+     */
+    List<CachePolicyListener> listeners = new ArrayList<CachePolicyListener>();
+
+
+    /**
+     * Construct an MRU with a given maximum number of objects.
+     */
+    public MRU( int max )
+    {
+        if ( max <= 0 )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_528 ) );
+        }
+
+        this.max = max;
+    }
+
+
+    /**
+     * Place an object in the cache.
+     */
+    public void put( K key, V value ) throws CacheEvictionException
+    {
+        CacheEntry entry = map.get( key );
+
+        if ( entry != null )
+        {
+            entry.setValue( value );
+            touchEntry( entry );
+        }
+        else
+        {
+
+            if ( map.size() == max )
+            {
+                // purge and recycle entry
+                entry = purgeEntry();
+                entry.setKey( key );
+                entry.setValue( value );
+            }
+            else
+            {
+                entry = new CacheEntry( key, value );
+            }
+
+            addEntry( entry );
+            map.put( entry.getKey(), entry );
+        }
+    }
+
+
+    /**
+     * Obtain an object in the cache
+     */
+    public V get( K key )
+    {
+        CacheEntry entry = map.get( key );
+
+        if ( entry != null )
+        {
+            touchEntry( entry );
+            return ( V ) entry.getValue();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+
+    /**
+     * Remove an object from the cache
+     */
+    public void remove( K key )
+    {
+        CacheEntry entry = map.get( key );
+
+        if ( entry != null )
+        {
+            removeEntry( entry );
+            map.remove( entry.getKey() );
+        }
+    }
+
+
+    /**
+     * Remove all objects from the cache
+     */
+    public void removeAll()
+    {
+        map = new HashMap<Object, CacheEntry>();
+        first = null;
+        last = null;
+    }
+
+
+    /**
+     * Enumerate elements' values in the cache
+     */
+    public Enumeration<V> elements()
+    {
+        return new MRUEnumeration<V>( map.values().iterator() );
+    }
+
+
+    /**
+     * Add a listener to this cache policy
+     *
+     * @param listener Listener to add to this policy
+     */
+    public void addListener( CachePolicyListener listener )
+    {
+        if ( listener == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_539_BAD_BLOCK_ID ) );
+        }
+
+        if ( !listeners.contains( listener ) )
+        {
+            listeners.add( listener );
+        }
+    }
+
+
+    /**
+     * Remove a listener from this cache policy
+     *
+     * @param listener Listener to remove from this policy
+     */
+    public void removeListener( CachePolicyListener listener )
+    {
+        listeners.remove( listener );
+    }
+
+
+    /**
+     * Add a CacheEntry.  Entry goes at the end of the list.
+     */
+    protected void addEntry( CacheEntry entry )
+    {
+        if ( first == null )
+        {
+            first = entry;
+            last = entry;
+        }
+        else
+        {
+            last.setNext( entry );
+            entry.setPrevious( last );
+            last = entry;
+        }
+    }
+
+
+    /**
+     * Remove a CacheEntry from linked list, and relink the 
+     * remaining element sin the list.
+     */
+    protected void removeEntry( CacheEntry entry )
+    {
+        if ( entry == first )
+        {
+            first = entry.getNext();
+
+            if ( first != null )
+            {
+                first.setPrevious( null );
+            }
+        }
+        else if ( last == entry )
+        {
+            last = entry.getPrevious();
+
+            if ( last != null )
+            {
+                last.setNext( null );
+            }
+        }
+        else
+        {
+            entry.getPrevious().setNext( entry.getNext() );
+            entry.getNext().setPrevious( entry.getPrevious() );
+        }
+    }
+
+
+    /**
+     * Place entry at the end of linked list -- Most Recently Used
+     */
+    protected void touchEntry( CacheEntry entry )
+    {
+        if ( last == entry )
+        {
+            return;
+        }
+
+        removeEntry( entry );
+        addEntry( entry );
+    }
+
+
+    /**
+     * Purge least recently used object from the cache
+     *
+     * @return recyclable CacheEntry
+     */
+    protected CacheEntry purgeEntry() throws CacheEvictionException
+    {
+        CacheEntry entry = first;
+
+        // Notify policy listeners first. if any of them throw an
+        // eviction exception, then the internal data structure
+        // remains untouched.
+        CachePolicyListener listener;
+
+        for ( int i = 0; i < listeners.size(); i++ )
+        {
+            listener = listeners.get( i );
+            listener.cacheObjectEvicted( entry.getValue() );
+        }
+
+        removeEntry( entry );
+        map.remove( entry.getKey() );
+        entry.setValue( null );
+
+        return entry;
+    }
+
+}
+
+/**
+ * State information for cache entries.
+ */
+class CacheEntry
+{
+    private Object key;
+    private Object value;
+
+    private CacheEntry previous;
+    private CacheEntry next;
+
+
+    CacheEntry( Object key, Object value )
+    {
+        this.key = key;
+        this.value = value;
+    }
+
+
+    Object getKey()
+    {
+        return key;
+    }
+
+
+    void setKey( Object obj )
+    {
+        key = obj;
+    }
+
+
+    Object getValue()
+    {
+        return value;
+    }
+
+
+    void setValue( Object obj )
+    {
+        value = obj;
+    }
+
+
+    CacheEntry getPrevious()
+    {
+        return previous;
+    }
+
+
+    void setPrevious( CacheEntry entry )
+    {
+        previous = entry;
+    }
+
+
+    CacheEntry getNext()
+    {
+        return next;
+    }
+
+
+    void setNext( CacheEntry entry )
+    {
+        next = entry;
+    }
+}
+
+/**
+ * Enumeration wrapper to return actual user objects instead of
+ * CacheEntries.
+ */
+class MRUEnumeration<V> implements Enumeration<V>
+{
+    Iterator<CacheEntry> elements;
+
+
+    MRUEnumeration( Iterator<CacheEntry> elements )
+    {
+        this.elements = elements;
+    }
+
+
+    public boolean hasMoreElements()
+    {
+        return elements.hasNext();
+    }
+
+
+    public V nextElement()
+    {
+        CacheEntry entry = elements.next();
+
+        return ( V ) entry.getValue();
+    }
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/ObjectBAComparator.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/ObjectBAComparator.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/ObjectBAComparator.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/ObjectBAComparator.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,194 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Comparator;
+
+import jdbm.I18n;
+
+
+/**
+ * Comparator for objects which have been serialized into byte arrays.
+ * In effect, it wraps another Comparator which compares object and provides
+ * transparent deserialization from byte array to object.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public final class ObjectBAComparator
+    implements Comparator, Serializable
+{
+
+    /**
+     * Version id for serialization.
+     */
+    final static long serialVersionUID = 1L;
+
+    /**
+     * Wrapped comparator.
+     */
+    private Comparator _comparator;
+
+
+    /**
+     * Construct an ObjectByteArrayComparator which wraps an Object Comparator.
+     *
+     * @param comparator Object comparator.
+     */
+    public ObjectBAComparator( Comparator comparator )
+    {
+        if ( comparator == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_518 ) );
+        }
+
+        _comparator = comparator;
+    }
+
+
+    /**
+     * Compare two objects.
+     *
+     * @param obj1 First object
+     * @param obj2 Second object
+     * @return 1 if obj1 > obj2, 0 if obj1 == obj2, -1 if obj1 < obj2
+     */
+    public int compare( Object obj1, Object obj2 )
+    {
+        if ( obj1 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) );
+        }
+
+        if ( obj2 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) );
+        }
+
+        try
+        {
+            obj1 = Serialization.deserialize( ( byte[] ) obj1 );
+            obj2 = Serialization.deserialize( ( byte[] ) obj2 );
+
+            return _comparator.compare( obj1, obj2 );
+        }
+        catch ( IOException except )
+        {
+            throw new WrappedRuntimeException( except );
+        }
+        catch ( ClassNotFoundException except )
+        {
+            throw new WrappedRuntimeException( except );
+        }
+    }
+
+
+    /**
+     * Compare two byte arrays.
+     */
+    public static int compareByteArray( byte[] thisKey, byte[] otherKey )
+    {
+        int len = Math.min( thisKey.length, otherKey.length );
+
+        // compare the byte arrays
+        for ( int i = 0; i < len; i++ )
+        {
+            if ( thisKey[i] >= 0 )
+            {
+                if ( otherKey[i] >= 0 )
+                {
+                    // both positive
+                    if ( thisKey[i] < otherKey[i] )
+                    {
+                        return -1;
+                    }
+                    else if ( thisKey[i] > otherKey[i] )
+                    {
+                        return 1;
+                    }
+                }
+                else
+                {
+                    // otherKey is negative => greater (because MSB is 1)
+                    return -1;
+                }
+            }
+            else
+            {
+                if ( otherKey[i] >= 0 )
+                {
+                    // thisKey is negative => greater (because MSB is 1)
+                    return 1;
+                }
+                else
+                {
+                    // both negative
+                    if ( thisKey[i] < otherKey[i] )
+                    {
+                        return -1;
+                    }
+                    else if ( thisKey[i] > otherKey[i] )
+                    {
+                        return 1;
+                    }
+                }
+            }
+        }
+        if ( thisKey.length == otherKey.length )
+        {
+            return 0;
+        }
+        if ( thisKey.length < otherKey.length )
+        {
+            return -1;
+        }
+        return 1;
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serialization.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serialization.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serialization.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serialization.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,97 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * Serialization-related utility methods.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public final class Serialization
+{
+
+    /**
+     * Serialize the object into a byte array.
+     */
+    public static byte[] serialize( Object obj )
+        throws IOException
+    {
+        ByteArrayOutputStream  baos;
+        ObjectOutputStream     oos;
+
+        baos = new ByteArrayOutputStream();
+        oos = new ObjectOutputStream( baos );
+        oos.writeObject( obj );
+        oos.close();
+
+        byte[] res = baos.toByteArray();
+        
+        return res;
+    }
+
+
+    /**
+     * Deserialize an object from a byte array
+     */
+    public static Object deserialize( byte[] buf )
+        throws ClassNotFoundException, IOException
+    {
+        ByteArrayInputStream  bais;
+        ObjectInputStream     ois;
+
+        bais = new ByteArrayInputStream( buf );
+        ois = new ObjectInputStream( bais );
+        return ois.readObject();
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serializer.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serializer.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serializer.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Serializer.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,76 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * Interface used to provide a serialization mechanism other than a class' normal
+ * serialization.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public interface Serializer extends Serializable
+{
+    /**
+     * Serialize the content of an object into a byte array.
+     *
+     * @param obj Object to serialize
+     * @return a byte array representing the object's state
+     */
+     public byte[] serialize( Object obj ) throws IOException;
+        
+        
+    /**
+     * Deserialize the content of an object from a byte array.
+     *
+     * @param serialized Byte array representation of the object
+     * @return deserialized object
+     */
+     public Object deserialize( byte[] serialized ) throws IOException;
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/SoftCache.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/SoftCache.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/SoftCache.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/SoftCache.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,346 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
+ * Contributions are Copyright (C) 2000 by their associated contributors.
+ *
+ * $Id
+ */
+package jdbm.helper;
+
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import jdbm.I18n;
+
+
+/**
+ * Wraps a deterministic cache policy with a <q>Level-2</q> cache based on
+ * J2SE's {@link SoftReference soft references}. Soft references allow
+ * this cache to keep references to objects until the memory they occupy
+ * is required elsewhere.
+ * <p>
+ * Since the {@link CachePolicy} interface requires an event be fired
+ * when an object is evicted, and the event contains the actual object,
+ * this class cannot be a stand-alone implementation of
+ * <code>CachePolicy</code>. This limitation arises because Java References
+ * does not support notification before references are cleared; nor do
+ * they support reaching soft referents. Therefore, this wrapper cache
+ * aggressively notifies evictions: events are fired when the objects are
+ * evicted from the internal cache. Consequently, the soft cache may return
+ * a non-null object when <code>get( )</code> is called, even if that
+ * object was said to have been evicted.
+ * <p>
+ * The current implementation uses a hash structure for its internal key
+ * to value mappings.
+ * <p>
+ * Note: this component's publicly exposed methods are not threadsafe;
+ * potentially concurrent code should synchronize on the cache instance.
+ *
+ * @author <a href="mailto:dranatunga@users.sourceforge.net">Dilum Ranatunga</a>
+ */
+public class SoftCache implements CachePolicy
+{
+    private static final int INITIAL_CAPACITY = 128;
+    private static final float DEFAULT_LOAD_FACTOR = 1.5f;
+
+    private final ReferenceQueue clearQueue = new ReferenceQueue();
+    private final CachePolicy internal;
+    private final Map map;
+
+
+    /**
+     * Creates a soft-reference based L2 cache with a {@link MRU} cache as
+     * the internal (L1) cache. The soft reference cache uses the
+     * default load capacity of 1.5f, which is intended to sacrifice some
+     * performance for space. This compromise is reasonable, since all
+     * {@link #get(Object) get( )s} first try the L1 cache anyway. The
+     * internal MRU is given a capacity of 128 elements.
+     */
+    public SoftCache()
+    {
+        this( new MRU( INITIAL_CAPACITY ) );
+    }
+
+
+    /**
+     * Creates a soft-reference based L2 cache wrapping the specified
+     * L1 cache.
+     *
+     * @param internal non null internal cache.
+     * @throws NullPointerException if the internal cache is null.
+     */
+    public SoftCache( CachePolicy internal ) throws NullPointerException
+    {
+        this( DEFAULT_LOAD_FACTOR, internal );
+    }
+
+
+    /**
+     * Creates a soft-reference based L2 cache wrapping the specified
+     * L1 cache. This constructor is somewhat implementation-specific,
+     * so users are encouraged to use {@link #SoftCache(CachePolicy)}
+     * instead.
+     *
+     * @param loadFactor load factor that the soft cache's hash structure
+     *        should use.
+     * @param internal non null internal cache.
+     * @throws IllegalArgumentException if the load factor is nonpositive.
+     * @throws NullPointerException if the internal cache is null.
+     */
+    public SoftCache( float loadFactor, CachePolicy internal ) throws IllegalArgumentException, NullPointerException
+    {
+        if ( internal == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_531 ) );
+        }
+
+        this.internal = internal;
+        map = new HashMap( INITIAL_CAPACITY, loadFactor );
+    }
+
+
+    /**
+     * Adds the specified value to the cache under the specified key. Note
+     * that the object is added to both this and the internal cache.
+     * @param key the (non-null) key to store the object under
+     * @param value the (non-null) object to place in the cache
+     * @throws CacheEvictionException exception that the internal cache
+     *         would have experienced while evicting an object it currently
+     *         cached.
+     */
+    public void put( Object key, Object value ) throws CacheEvictionException
+    {
+        if ( key == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_532 ) );
+        }
+        else if ( value == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_533 ) );
+        }
+
+        internal.put( key, value );
+        removeClearedEntries();
+        map.put( key, new Entry( key, value, clearQueue ) );
+    }
+
+
+    /**
+     * Gets the object cached under the specified key.
+     * <p>
+     * The cache is looked up in the following manner:
+     * <ol>
+     * <li>The internal (L1) cache is checked. If the object is found, it is
+     *     returned.</li>
+     * <li>This (L2) cache is checked. If the object is not found, then
+     *     the caller is informed that the object is inaccessible.</li>
+     * <li>Since the object exists in L2, but not in L1, the object is
+     *     readded to L1 using {@link CachePolicy#put(Object, Object)}.</li>
+     * <li>If the readding succeeds, the value is returned to caller.</li>
+     * <li>If a cache eviction exception is encountered instead, we
+     *     remove the object from L2 and behave as if the object was
+     *     inaccessible.</li>
+     * </ol>
+     * @param key the key that the object was stored under.
+     * @return the object stored under the key specified; null if the
+     *         object is not (nolonger) accessible via this cache.
+     */
+    public Object get( Object key )
+    {
+        // first try the internal cache.
+        Object value = internal.get( key );
+
+        if ( value != null )
+        {
+            return value;
+        }
+
+        // poll and remove cleared references.
+        removeClearedEntries();
+        Entry entry = ( Entry ) map.get( key );
+
+        if ( entry == null )
+        { // object is not in cache.
+            return null;
+        }
+
+        value = entry.getValue();
+
+        if ( value == null )
+        { // object was in cache, but it was cleared.
+            return null;
+        }
+
+        // we have the object. so we try to re-insert it into internal cache
+        try
+        {
+            internal.put( key, value );
+        }
+        catch ( CacheEvictionException e )
+        {
+            // if the internal cache causes a fuss, we kick the object out.
+            map.remove( key );
+            return null;
+        }
+
+        return value;
+    }
+
+
+    /**
+     * Removes any object stored under the key specified. Note that the
+     * object is removed from both this (L2) and the internal (L1)
+     * cache.
+     * @param key the key whose object should be removed
+     */
+    public void remove( Object key )
+    {
+        map.remove( key );
+        internal.remove( key );
+    }
+
+
+    /**
+     * Removes all objects in this (L2) and its internal (L1) cache.
+     */
+    public void removeAll()
+    {
+        map.clear();
+        internal.removeAll();
+    }
+
+
+    /**
+     * Gets all the objects stored by the internal (L1) cache.
+     * @return an enumeration of objects in internal cache.
+     */
+    public Enumeration elements()
+    {
+        return internal.elements();
+    }
+
+
+    /**
+     * Adds the specified listener to this cache. Note that the events
+     * fired by this correspond to the <em>internal</em> cache's events.
+     * @param listener the (non-null) listener to add to this policy
+     * @throws IllegalArgumentException if listener is null.
+     */
+    public void addListener( CachePolicyListener listener ) throws IllegalArgumentException
+    {
+        internal.addListener( listener );
+    }
+
+
+    /**
+     * Removes a listener that was added earlier.
+     * @param listener the listener to remove.
+     */
+    public void removeListener( CachePolicyListener listener )
+    {
+        internal.removeListener( listener );
+    }
+
+
+    /**
+     * Cleans the mapping structure of any obsolete entries. This is usually
+     * called before insertions and lookups on the mapping structure. The
+     * runtime of this is usually very small, but it can be as expensive as
+     * n * log(n) if a large number of soft references were recently cleared.
+     */
+    private final void removeClearedEntries()
+    {
+        for ( Reference r = clearQueue.poll(); r != null; r = clearQueue.poll() )
+        {
+            Object key = ( ( Entry ) r ).getKey();
+            map.remove( key );
+        }
+    }
+
+    /**
+     * Value objects we keep in the internal map. This contains the key in
+     * addition to the value, because polling for cleared references
+     * returns these instances, and having access to their corresponding
+     * keys drastically improves the performance of removing the pair
+     * from the map (see {@link SoftCache#removeClearedEntries()}.)
+     */
+    private static class Entry extends SoftReference
+    {
+        private final Object key;
+
+
+        /**
+         * Constructor that uses <code>value</code> as the soft
+         * reference's referent.
+         */
+        public Entry( Object key, Object value, ReferenceQueue queue )
+        {
+            super( value, queue );
+            this.key = key;
+        }
+
+
+        /**
+         * Gets the key
+         * @return the key associated with this value.
+         */
+        final Object getKey()
+        {
+            return key;
+        }
+
+
+        /**
+         * Gets the value
+         * @return the value; null if it is no longer accessible
+         */
+        final Object getValue()
+        {
+            return this.get();
+        }
+    }
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/StringComparator.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/StringComparator.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/StringComparator.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/StringComparator.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,94 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import jdbm.I18n;
+
+
+/**
+ * Comparator for String objects.  Delegates to String.compareTo().
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public final class StringComparator
+    implements Comparator<String>, Serializable
+{
+
+    /**
+     * Version id for serialization.
+     */
+    final static long serialVersionUID = 1L;
+
+
+    /**
+     * Compare two objects.
+     *
+     * @param obj1 First object
+     * @param obj2 Second object
+     * @return a positive integer if obj1 > obj2, 0 if obj1 == obj2,
+     *         and a negative integer if obj1 < obj2
+     */
+    public int compare( String obj1, String obj2 )
+    {
+        if ( obj1 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_525 ) );
+        }
+
+        if ( obj2 == null )
+        {
+            throw new IllegalArgumentException( I18n.err( I18n.ERR_526 ) );
+        }
+
+        return obj1.compareTo( obj2 );
+    }
+
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Tuple.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Tuple.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Tuple.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/Tuple.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,126 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+
+/**
+ * Tuple consisting of a key-value pair.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public final class Tuple<K, V> {
+
+    /** Key */
+    private K key;
+
+    /** Value */
+    private V value;
+
+
+    /**
+     * Construct an empty Tuple.
+     */
+    public Tuple() 
+    {
+        // empty
+    }
+
+
+    /**
+     * Construct a Tuple.
+     *
+     * @param key The key.
+     * @param value The value.
+     */
+    public Tuple( K key, V value ) 
+    {
+        this.key = key;
+        this.value = value;
+    }
+
+
+    /**
+     * Get the key.
+     */
+    public K getKey() 
+    {
+        return this.key;
+    }
+
+
+    /**
+     * Set the key.
+     */
+    public void setKey( K key ) 
+    {
+        this.key = key;
+    }
+
+
+    /**
+     * Get the value.
+     */
+    public V getValue() 
+    {
+        return value;
+    }
+
+
+    /**
+     * Set the value.
+     */
+    public void setValue( V value ) 
+    {
+        this.value = value;
+    }
+    
+    
+    public String toString()
+    {
+        return "<" + key + "," + value + ">";
+    }
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/TupleBrowser.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/TupleBrowser.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/TupleBrowser.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/TupleBrowser.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,76 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.IOException;
+
+/**
+ * Browser to traverse a collection of tuples.  The browser allows for
+ * forward and reverse order traversal.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public abstract class TupleBrowser<K, V> {
+    /**
+     * Get the next tuple.
+     *
+     * @param tuple Tuple into which values are copied.
+     * @return True if values have been copied in tuple, or false if there is
+     *         no next tuple.
+     */
+    public abstract boolean getNext( Tuple<K, V> tuple ) throws IOException;
+
+
+    /**
+     * Get the previous tuple.
+     *
+     * @param tuple Tuple into which values are copied.
+     * @return True if values have been copied in tuple, or false if there is
+     *         no previous tuple.
+     */
+    public abstract boolean getPrevious( Tuple<K, V> tuple ) throws IOException;
+}

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/WrappedRuntimeException.java
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/WrappedRuntimeException.java?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/WrappedRuntimeException.java (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/WrappedRuntimeException.java Fri Jan 18 10:10:55 2013
@@ -0,0 +1,150 @@
+/**
+ * JDBM LICENSE v1.00
+ *
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "JDBM" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Cees de Groot.  For written permission,
+ *    please contact cg@cdegroot.com.
+ *
+ * 4. Products derived from this Software may not be called "JDBM"
+ *    nor may "JDBM" appear in their names without prior written
+ *    permission of Cees de Groot.
+ *
+ * 5. Due credit should be given to the JDBM Project
+ *    (http://jdbm.sourceforge.net/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) Alex Boisvert. All Rights Reserved.
+ * Contributions are Copyright (C) 2001 by their associated contributors.
+ *
+ */
+
+package jdbm.helper;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+/**
+ * A run-time exception that wraps another exception. The printed stack
+ * trace will be that of the wrapped exception.
+ *
+ * @author <a href="mailto:boisvert@intalio.com">Alex Boisvert</a>
+ */
+public class WrappedRuntimeException
+    extends RuntimeException
+{
+
+
+    /**
+     * The underlying exception.
+     */
+    private final Exception _except;
+
+
+    /**
+     * Constructs a new runtime exception based on a checked exception.
+     *
+     * @param message The error message
+     * @param except The checked exception
+     */
+    public WrappedRuntimeException( String message, Exception except )
+    {
+        super( message == null ? "No message available" : message );
+
+        if ( except instanceof WrappedRuntimeException &&
+             ( (WrappedRuntimeException) except )._except != null )
+        {
+            _except = ( (WrappedRuntimeException) except )._except;
+        } else {
+            _except = except;
+        }
+    }
+
+
+    /**
+     * Constructs a new runtime exception based on a checked exception.
+     *
+     * @param except The checked exception
+     */
+    public WrappedRuntimeException( Exception except )
+    {
+        super( except == null || except.getLocalizedMessage() == null ? "No message available" : except.getLocalizedMessage() );
+
+        if ( except instanceof WrappedRuntimeException &&
+             ( (WrappedRuntimeException) except )._except != null )
+        {
+            _except = ( (WrappedRuntimeException) except )._except;
+        } else {
+            _except = except;
+        }
+    }
+
+
+    /**
+     * Returns the exception wrapped by this runtime exception.
+     *
+     * @return The exception wrapped by this runtime exception
+     */
+    public Exception getException()
+    {
+        return _except;
+    }
+
+
+    public void printStackTrace()
+    {
+        if ( _except == null ) {
+            super.printStackTrace();
+        } else {
+            _except.printStackTrace();
+        }
+    }
+
+
+    public void printStackTrace( PrintStream stream )
+    {
+        if ( _except == null ) {
+            super.printStackTrace( stream );
+        } else {
+            _except.printStackTrace( stream );
+        }
+    }
+
+
+    public void printStackTrace( PrintWriter writer )
+    {
+        if ( _except == null ) {
+            super.printStackTrace( writer );
+        } else {
+            _except.printStackTrace( writer );
+        }
+    }
+
+}
+
+

Added: directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/package.html
URL: http://svn.apache.org/viewvc/directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/package.html?rev=1435064&view=auto
==============================================================================
--- directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/package.html (added)
+++ directory/jdbm/trunk/jdbm1/src/main/java/jdbm/helper/package.html Fri Jan 18 10:10:55 2013
@@ -0,0 +1,12 @@
+<!-- $Id: package.html,v 1.1 2001/05/19 16:01:33 boisvert Exp $ -->
+<html>
+  <body>
+    <p>Miscelaneous utility classes and interfaces.</p>
+
+    <dl>
+      <dt><b>Version: </b></dt><dd>$Revision: 1.1 $ $Date: 2001/05/19 16:01:33 $</dd>
+      <dt><b>Author: </b></dt><dd><a href="mailto:boisvert@intalio.com">Alex Boisvert</a></dd>
+    </dl>
+
+  </body>
+</html>



Mime
View raw message