commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/primitives ArrayUnsignedIntList.java UnsignedIntArrayList.java
Date Wed, 09 Apr 2003 06:44:34 GMT
rwaldhoff    2003/04/08 23:44:34

  Modified:    collections/src/test/org/apache/commons/collections/primitives
                        TestLongArrayList.java TestAll.java
                        TestIntArrayList.java TestAbstractIntArrayList.java
                        TestUnsignedShortArrayList.java
                        TestUnsignedIntArrayList.java
               collections/src/java/org/apache/commons/collections/primitives
                        UnsignedIntArrayList.java
  Added:       collections/src/test/org/apache/commons/collections/primitives
                        TestArrayUnsignedIntList.java
               collections/src/java/org/apache/commons/collections/primitives
                        ArrayUnsignedIntList.java
  Log:
  * add ArrayUnsignedIntList and tests
  * deprecate some test cases to reduce the number of deprecation warnings
  
  Revision  Changes    Path
  1.7       +3 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestLongArrayList.java
  
  Index: TestLongArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestLongArrayList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestLongArrayList.java	12 Jan 2003 15:23:20 -0000	1.6
  +++ TestLongArrayList.java	9 Apr 2003 06:44:34 -0000	1.7
  @@ -65,6 +65,7 @@
   /**
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated as the tested classes are deprecated also
    */
   public class TestLongArrayList extends TestAbstractLongArrayList {
   
  
  
  
  1.11      +4 -3      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAll.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestAll.java	8 Apr 2003 18:24:34 -0000	1.10
  +++ TestAll.java	9 Apr 2003 06:44:34 -0000	1.11
  @@ -85,7 +85,8 @@
   
   		suite.addTest(TestAbstractLongCollection.suite());
   		suite.addTest(TestAbstractRandomAccessLongList.suite());
  -		suite.addTest(TestArrayLongList.suite());
  +        suite.addTest(TestArrayLongList.suite());
  +        suite.addTest(TestArrayUnsignedIntList.suite());
   
           suite.addTest(org.apache.commons.collections.primitives.adapters.TestAll.suite());
           
  
  
  
  1.7       +3 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntArrayList.java
  
  Index: TestIntArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestIntArrayList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestIntArrayList.java	12 Jan 2003 15:23:20 -0000	1.6
  +++ TestIntArrayList.java	9 Apr 2003 06:44:34 -0000	1.7
  @@ -65,6 +65,7 @@
   /**
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated as the tested classes are deprecated also
    */
   public class TestIntArrayList extends TestAbstractIntArrayList {
   
  
  
  
  1.7       +3 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractIntArrayList.java
  
  Index: TestAbstractIntArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestAbstractIntArrayList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestAbstractIntArrayList.java	5 Mar 2003 19:10:50 -0000	1.6
  +++ TestAbstractIntArrayList.java	9 Apr 2003 06:44:34 -0000	1.7
  @@ -64,6 +64,7 @@
   /**
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated as the tested classes are deprecated also
    */
   public abstract class TestAbstractIntArrayList extends TestList {
   
  
  
  
  1.7       +3 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedShortArrayList.java
  
  Index: TestUnsignedShortArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedShortArrayList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestUnsignedShortArrayList.java	12 Jan 2003 15:23:20 -0000	1.6
  +++ TestUnsignedShortArrayList.java	9 Apr 2003 06:44:34 -0000	1.7
  @@ -65,6 +65,7 @@
   /**
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated as the tested classes are deprecated also
    */
   public class TestUnsignedShortArrayList extends TestAbstractIntArrayList {
   
  
  
  
  1.7       +3 -2      jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedIntArrayList.java
  
  Index: TestUnsignedIntArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestUnsignedIntArrayList.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestUnsignedIntArrayList.java	12 Jan 2003 15:23:20 -0000	1.6
  +++ TestUnsignedIntArrayList.java	9 Apr 2003 06:44:34 -0000	1.7
  @@ -65,6 +65,7 @@
   /**
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff
  + * @deprecated as the tested classes are deprecated also
    */
   public class TestUnsignedIntArrayList extends TestAbstractLongArrayList {
   
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedIntList.java
  
  Index: TestArrayUnsignedIntList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayUnsignedIntList.java,v
1.1 2003/04/09 06:44:34 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 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 end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION OR
   * ITS 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.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.primitives;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.collections.BulkTest;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/04/09 06:44:34 $
   * @author Rodney Waldhoff
   */
  public class TestArrayUnsignedIntList extends TestLongList {
  
      // conventional
      // ------------------------------------------------------------------------
  
      public TestArrayUnsignedIntList(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = BulkTest.makeSuite(TestArrayUnsignedIntList.class);
          return suite;
      }
  
      // collections testing framework
      // ------------------------------------------------------------------------
  
      protected LongList makeEmptyLongList() {
          return new ArrayUnsignedIntList();
      }
  
      public String[] ignoredSimpleTests() {
          // sublists are not serializable
          return new String[] { 
              "TestArrayUnsignedLongList.bulkTestSubList.testFullListSerialization",
              "TestArrayUnsignedLongList.bulkTestSubList.testEmptyListSerialization",
              "TestArrayUnsignedLongList.bulkTestSubList.testCanonicalEmptyCollectionExists",
              "TestArrayUnsignedLongList.bulkTestSubList.testCanonicalFullCollectionExists",
              "TestArrayUnsignedLongList.bulkTestSubList.testEmptyListCompatibility",
              "TestArrayUnsignedLongList.bulkTestSubList.testFullListCompatibility",
              "TestArrayUnsignedLongList.bulkTestSubList.testSerializeDeserializeThenCompare",
              "TestArrayUnsignedLongList.bulkTestSubList.testSimpleSerialization"
          };
      }
  
      protected long[] getFullLongs() {
          long[] result = new long[19];
          for(int i = 0; i < result.length; i++) {
              result[i] = ((long)Integer.MAX_VALUE - 1L - (long)i);
          }
          return result;
      }
  
      // tests
      // ------------------------------------------------------------------------
  
      // @TODO need to add serialized form to cvs
      public void testCanonicalEmptyCollectionExists() {
          // XXX FIX ME XXX
          // need to add a serialized form to cvs
      }
  
      public void testCanonicalFullCollectionExists() {
          // XXX FIX ME XXX
          // need to add a serialized form to cvs
      }
  
      public void testEmptyListCompatibility() {
          // XXX FIX ME XXX
          // need to add a serialized form to cvs
      }
  
      public void testFullListCompatibility() {
          // XXX FIX ME XXX
          // need to add a serialized form to cvs
      }
  
      public void testZeroInitialCapacityIsValid() {
          ArrayUnsignedIntList list = new ArrayUnsignedIntList(0);
      }
      
      public void testIllegalArgumentExceptionWhenElementOutOfRange() {
          ArrayUnsignedIntList list = new ArrayUnsignedIntList();
          list.add(ArrayUnsignedIntList.MIN_VALUE);
          list.add(ArrayUnsignedIntList.MAX_VALUE);
          try {
              list.add(-1);
              fail("Expected IllegalArgumentException");
          } catch(IllegalArgumentException e) {
              // expected
          }
          try {
              list.add(ArrayUnsignedIntList.MAX_VALUE+1);
              fail("Expected IllegalArgumentException");
          } catch(IllegalArgumentException e) {
              // expected
          }
      }
  
      public void testNegativeInitialCapacityIsInvalid() {
          try {
              ArrayUnsignedIntList list = new ArrayUnsignedIntList(-1);
              fail("Expected IllegalArgumentException");
          } catch(IllegalArgumentException e) {
              // expected
          }
      }
  
      public void testCopyConstructor() {
          ArrayUnsignedIntList expected = new ArrayUnsignedIntList();
          for(int i=0;i<10;i++) {
              expected.add(i);
          }
          ArrayUnsignedIntList list = new ArrayUnsignedIntList(expected);
          assertEquals(10,list.size());
          assertEquals(expected,list);
      }
  
      public void testCopyConstructorWithNull() {
          try {
              ArrayUnsignedIntList list = new ArrayUnsignedIntList(null);
              fail("Expected NullPointerException");
          } catch(NullPointerException e) {
              // expected
          }
      }
  
  
      public void testTrimToSize() {
          ArrayUnsignedIntList list = new ArrayUnsignedIntList();
          for(int j=0;j<3;j++) {
              assertTrue(list.isEmpty());
      
              list.trimToSize();
      
              assertTrue(list.isEmpty());
              
              for(int i=0;i<10;i++) {
                  list.add(i);
              }
              
              for(int i=0;i<10;i++) {
                  assertEquals(i,list.get(i));
              }
              
              list.trimToSize();
      
              for(int i=0;i<10;i++) {
                  assertEquals(i,list.get(i));
              }
      
              for(int i=0;i<10;i+=2) {
                  list.removeElement(i);
              }
              
              for(int i=0;i<5;i++) {
                  assertEquals((2*i)+1,list.get(i));
              }
      
              list.trimToSize();
                      
              for(int i=0;i<5;i++) {
                  assertEquals((2*i)+1,list.get(i));
              }
      
              list.trimToSize();
                      
              for(int i=0;i<5;i++) {
                  assertEquals((2*i)+1,list.get(i));
              }
  
              list.clear();
          }
      }
  
  }
  
  
  
  1.9       +3 -2      jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedIntArrayList.java
  
  Index: UnsignedIntArrayList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/UnsignedIntArrayList.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- UnsignedIntArrayList.java	11 Jan 2003 21:28:02 -0000	1.8
  +++ UnsignedIntArrayList.java	9 Apr 2003 06:44:34 -0000	1.9
  @@ -73,6 +73,7 @@
    *
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff 
  + * @deprecated use ArrayUnsignedIntList or another LongList implementation instead.
    */
   public class UnsignedIntArrayList extends AbstractLongArrayList implements Serializable
{
   
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ArrayUnsignedIntList.java
  
  Index: ArrayUnsignedIntList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ArrayUnsignedIntList.java,v
1.1 2003/04/09 06:44:34 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 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 end-user documentation included with the redistribution, if
   *    any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION OR
   * ITS 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.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.collections.primitives;
  
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.Serializable;
  
  /**
   * An {@link IntList} backed by an array of unsigned
   * <code>int</code> values.
   * This list stores <code>int</code> values
   * in the range [{@link #MIN_VALUE <code>0</code>},
   * {@link #MAX_VALUE <code>65535</code>}] in 16-bits 
   * per element.  Attempts to use elements outside this 
   * range may cause an 
   * {@link IllegalArgumentException IllegalArgumentException} 
   * to be thrown.
   * <p />
   * This implementation supports all optional methods.
   * 
   * @since Commons Collections 2.2
   * @version $Revision: 1.1 $ $Date: 2003/04/09 06:44:34 $
   * 
   * @author Rodney Waldhoff 
   */
  public class ArrayUnsignedIntList extends AbstractRandomAccessLongList implements LongList,
Serializable {
  
      // constructors
      //-------------------------------------------------------------------------
  
      /** 
       * Construct an empty list with the default
       * initial capacity.
       */
      protected ArrayUnsignedIntList() {
          this(8);
      }    
  
      /**
       * Construct an empty list with the given
       * initial capacity.
       * @throws IllegalArgumentException when <i>initialCapacity</i> is negative
       */
      protected ArrayUnsignedIntList(int initialCapacity) {
          if(initialCapacity < 0) {
              throw new IllegalArgumentException("capacity " + initialCapacity);
          }
          _data = new int[initialCapacity];
          _size = 0;
      }    
  
      /** 
       * Constructs a list containing the elements of the given collection, 
       * in the order they are returned by that collection's iterator.
       * 
       * @see ArrayIntList#addAll(org.apache.commons.collections.primitives.LongCollection)
       * @param that the non-<code>null</code> collection of <code>int</code>s

       *        to add
       * @throws NullPointerException if <i>that</i> is <code>null</code>
       */
      public ArrayUnsignedIntList(LongCollection that) { 
          this(that.size());
          addAll(that);
      }    
  
      // IntList methods
      //-------------------------------------------------------------------------
  
      /** 
       * Returns the element at the specified position within 
       * me. 
       * By construction, the returned value will be 
       * between {@link #MIN_VALUE} and {@link #MAX_VALUE}, inclusive.
       * 
       * @param index the index of the element to return
       * @return the value of the element at the specified position
       * @throws IndexOutOfBoundsException if the specified index is out of range
       */
      public long get(int index) {
          checkRange(index);
          return toLong(_data[index]);
      }
      
      public int size() {
          return _size;
      }
      
      /** 
       * Removes the element at the specified position in 
       * (optional operation).  Any subsequent elements 
       * are shifted to the left, subtracting one from their 
       * indices.  Returns the element that was removed.
       * By construction, the returned value will be 
       * between {@link #MIN_VALUE} and {@link #MAX_VALUE}, inclusive.
       * 
       * @param index the index of the element to remove
       * @return the value of the element that was removed
       * 
       * @throws UnsupportedOperationException when this operation is not 
       *         supported
       * @throws IndexOutOfBoundsException if the specified index is out of range
       */
      public long removeElementAt(int index) {
          checkRange(index);
          incrModCount();
          int oldval = _data[index];
          int numtomove = _size - index - 1;
          if(numtomove > 0) {
              System.arraycopy(_data,index+1,_data,index,numtomove);
          }
          _size--;
          return oldval;
      }
      
      /** 
       * Replaces the element at the specified 
       * position in me with the specified element
       * (optional operation). 
       * Throws {@link IllegalArgumentException} if <i>element</i>
       * is less than {@link #MIN_VALUE} or greater than {@link #MAX_VALUE}.
       * 
       * @param index the index of the element to change
       * @param element the value to be stored at the specified position
       * @return the value previously stored at the specified position
       * 
       * @throws UnsupportedOperationException when this operation is not 
       *         supported
       * @throws IndexOutOfBoundsException if the specified index is out of range
       */
      public long set(int index, long element) {
          assertValidUnsignedInt(element);
          checkRange(index);
          incrModCount();
          long oldval = toLong(_data[index]);
          _data[index] = fromLong(element);
          return oldval;
      }
          
      /** 
       * Inserts the specified element at the specified position 
       * (optional operation). Shifts the element currently 
       * at that position (if any) and any subsequent elements to the 
       * right, increasing their indices.
       * Throws {@link IllegalArgumentException} if <i>element</i>
       * is less than {@link #MIN_VALUE} or greater than {@link #MAX_VALUE}.
       * 
       * @param index the index at which to insert the element
       * @param element the value to insert
       * 
       * @throws UnsupportedOperationException when this operation is not 
       *         supported
       * @throws IllegalArgumentException if some aspect of the specified element 
       *         prevents it from being added to me
       * @throws IndexOutOfBoundsException if the specified index is out of range
       */
      public void add(int index, long element) {
          assertValidUnsignedInt(element);
          checkRangeIncludingEndpoint(index);
          incrModCount();
          ensureCapacity(_size+1);
          int numtomove = _size-index;
          System.arraycopy(_data,index,_data,index+1,numtomove);
          _data[index] = fromLong(element);
          _size++;
      }
  
      // capacity methods
      //-------------------------------------------------------------------------
  
      /** 
       * Increases my capacity, if necessary, to ensure that I can hold at 
       * least the number of elements specified by the minimum capacity 
       * argument without growing.
       */
      public void ensureCapacity(int mincap) {
          incrModCount();
          if(mincap > _data.length) {
              int newcap = (_data.length * 3)/2 + 1;
              int[] olddata = _data;
              _data = new int[newcap < mincap ? mincap : newcap];
              System.arraycopy(olddata,0,_data,0,_size);
          }
      }
  
      /** 
       * Reduce my capacity, if necessary, to match my
       * current {@link #size size}.
       */
      public void trimToSize() {
          incrModCount();
          if(_size < _data.length) {
              int[] olddata = _data;
              _data = new int[_size];
              System.arraycopy(olddata,0,_data,0,_size);
          }
      }
  
      // private methods
      //-------------------------------------------------------------------------
  
      private final long toLong(int value) { 
          return ((long)value)&MAX_VALUE;
      }
  
      private final int fromLong(long value) {
          return (int)(value&MAX_VALUE);
      }
  
      private final void assertValidUnsignedInt(long value) throws IllegalArgumentException
{
          if(value > MAX_VALUE) {
              throw new IllegalArgumentException(value + " > " + MAX_VALUE);
          }
          if(value < MIN_VALUE) {
              throw new IllegalArgumentException(value + " < " + MIN_VALUE);
          }
      }
  
      private void writeObject(ObjectOutputStream out) throws IOException{
          out.defaultWriteObject();
          out.writeInt(_data.length);
          for(int i=0;i<_size;i++) {
              out.writeInt(_data[i]);
          }
      }
  
      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
          in.defaultReadObject();
          _data = new int[in.readInt()];
          for(int i=0;i<_size;i++) {
              _data[i] = in.readInt();
          }
      }
      
      private final void checkRange(int index) {
          if(index < 0 || index >= _size) {
              throw new IndexOutOfBoundsException("Should be at least 0 and less than " +
_size + ", found " + index);
          }
      }
  
      private final void checkRangeIncludingEndpoint(int index) {
          if(index < 0 || index > _size) {
              throw new IndexOutOfBoundsException("Should be at least 0 and at most " + _size
+ ", found " + index);
          }
      }
  
      // attributes
      //-------------------------------------------------------------------------
      
      /**
       *  The maximum possible unsigned 32-bit value.
       */
      public static final long MAX_VALUE = 0xFFFFFFFFL;
  
      /**
       *  The minimum possible unsigned 32-bit value.
       */
      public static final long MIN_VALUE = 0L;
  
      private transient int[] _data = null;
      private int _size = 0;
  
  }
  
  
  

---------------------------------------------------------------------
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