commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/buffer TestBoundedFifoBuffer.java TestCircularFifoBuffer.java
Date Wed, 02 Jun 2004 23:12:45 GMT
scolebourne    2004/06/02 16:12:45

  Modified:    collections/src/java/org/apache/commons/collections/buffer
                        BoundedFifoBuffer.java CircularFifoBuffer.java
               collections/src/test/org/apache/commons/collections/buffer
                        TestBoundedFifoBuffer.java
                        TestCircularFifoBuffer.java
  Added:       collections/data/test
                        BoundedFifoBuffer.fullCollection.version3.1.obj
                        BoundedFifoBuffer.emptyCollection.version3.1.obj
                        CircularFifoBuffer.fullCollection.version3.1.obj
                        CircularFifoBuffer.emptyCollection.version3.1.obj
  Log:
  Make buffers serializable
  
  Revision  Changes    Path
  1.8       +51 -7     jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java
  
  Index: BoundedFifoBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/BoundedFifoBuffer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BoundedFifoBuffer.java	18 Feb 2004 00:58:18 -0000	1.7
  +++ BoundedFifoBuffer.java	2 Jun 2004 23:12:44 -0000	1.8
  @@ -15,6 +15,10 @@
    */
   package org.apache.commons.collections.buffer;
   
  +import java.io.IOException;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
  +import java.io.Serializable;
   import java.util.AbstractCollection;
   import java.util.Arrays;
   import java.util.Collection;
  @@ -45,6 +49,8 @@
    * </pre>
    * <p>
    * This buffer prevents null objects from being added.
  + * <p>
  + * This class is Serializable from Commons Collections 3.1.
    *
    * @since Commons Collections 3.0 (previously in main package v2.1)
    * @version $Revision$ $Date$
  @@ -56,12 +62,15 @@
    * @author Herve Quiroz
    */
   public class BoundedFifoBuffer extends AbstractCollection
  -        implements Buffer, BoundedCollection {
  -            
  -    private final Object[] elements;
  -    private int start = 0;
  -    private int end = 0;
  -    private boolean full = false;
  +        implements Buffer, BoundedCollection, Serializable {
  +
  +    /** Serialization version */
  +    private static final long serialVersionUID = 5603722811189451017L;
  +
  +    private transient Object[] elements;
  +    private transient int start = 0;
  +    private transient int end = 0;
  +    private transient boolean full = false;
       private final int maxElements;
   
       /**
  @@ -100,6 +109,41 @@
           addAll(coll);
       }
   
  +    //-----------------------------------------------------------------------
  +    /**
  +     * Write the buffer out using a custom routine.
  +     * 
  +     * @param out  the output stream
  +     * @throws IOException
  +     */
  +    private void writeObject(ObjectOutputStream out) throws IOException {
  +        out.defaultWriteObject();
  +        out.writeInt(size());
  +        for (Iterator it = iterator(); it.hasNext();) {
  +            out.writeObject(it.next());
  +        }
  +    }
  +
  +    /**
  +     * Read the buffer in using a custom routine.
  +     * 
  +     * @param in  the input stream
  +     * @throws IOException
  +     * @throws ClassNotFoundException
  +     */
  +    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
  +        in.defaultReadObject();
  +        elements = new Object[maxElements];
  +        int size = in.readInt();
  +        for (int i = 0; i < size; i++) {
  +            elements[i] = in.readObject();
  +        }
  +        start = 0;
  +        end = size;
  +        full = (size == maxElements);
  +    }
  +
  +    //-----------------------------------------------------------------------
       /**
        * Returns the number of elements stored in the buffer.
        *
  
  
  
  1.4       +3 -1      jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java
  
  Index: CircularFifoBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/CircularFifoBuffer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CircularFifoBuffer.java	18 Feb 2004 00:58:18 -0000	1.3
  +++ CircularFifoBuffer.java	2 Jun 2004 23:12:44 -0000	1.4
  @@ -36,6 +36,8 @@
    * </pre>
    * <p>
    * This buffer prevents null objects from being added.
  + * <p>
  + * This class is Serializable from Commons Collections 3.1.
    * 
    * @since Commons Collections 3.0
    * @version $Revision$ $Date$
  
  
  
  1.1                  jakarta-commons/collections/data/test/BoundedFifoBuffer.fullCollection.version3.1.obj
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons/collections/data/test/BoundedFifoBuffer.emptyCollection.version3.1.obj
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons/collections/data/test/CircularFifoBuffer.fullCollection.version3.1.obj
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons/collections/data/test/CircularFifoBuffer.emptyCollection.version3.1.obj
  
  	<<Binary file>>
  
  
  1.4       +13 -1     jakarta-commons/collections/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java
  
  Index: TestBoundedFifoBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/buffer/TestBoundedFifoBuffer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestBoundedFifoBuffer.java	18 Feb 2004 01:20:37 -0000	1.3
  +++ TestBoundedFifoBuffer.java	2 Jun 2004 23:12:45 -0000	1.4
  @@ -164,4 +164,16 @@
           }
           fail();
       }
  +
  +    public String getCompatibilityVersion() {
  +        return "3.1";
  +    }
  +
  +//    public void testCreate() throws Exception {
  +//        resetEmpty();
  +//        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/BoundedFifoBuffer.emptyCollection.version3.1.obj");
  +//        resetFull();
  +//        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/BoundedFifoBuffer.fullCollection.version3.1.obj");
  +//    }
  +
   }
  
  
  
  1.4       +13 -1     jakarta-commons/collections/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java
  
  Index: TestCircularFifoBuffer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/buffer/TestCircularFifoBuffer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestCircularFifoBuffer.java	18 Feb 2004 01:20:37 -0000	1.3
  +++ TestCircularFifoBuffer.java	2 Jun 2004 23:12:45 -0000	1.4
  @@ -193,4 +193,16 @@
           }
           fail();
       }
  +
  +    public String getCompatibilityVersion() {
  +        return "3.1";
  +    }
  +
  +//    public void testCreate() throws Exception {
  +//        resetEmpty();
  +//        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/CircularFifoBuffer.emptyCollection.version3.1.obj");
  +//        resetFull();
  +//        writeExternalFormToDisk((java.io.Serializable) collection, "D:/dev/collections/data/test/CircularFifoBuffer.fullCollection.version3.1.obj");
  +//    }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message