You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2003/01/06 04:59:12 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/primitives TestArrayIntList.java TestAll.java

rwaldhoff    2003/01/05 19:59:12

  Modified:    collections/src/java/org/apache/commons/collections/primitives
                        AbstractIntCollection.java IntList.java
               collections/src/test/org/apache/commons/collections/primitives
                        TestAll.java
  Added:       collections/src/java/org/apache/commons/collections/primitives
                        AbstractRandomAccessIntList.java ArrayIntList.java
               collections/src/test/org/apache/commons/collections/primitives
                        TestArrayIntList.java
  Log:
  * add ArrayIntList, AbstractRandomAccessIntList
  * add missing addAll(int,IntCollection) method to IntList
  * add tests
  
  Revision  Changes    Path
  1.2       +3 -4      jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractIntCollection.java
  
  Index: AbstractIntCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractIntCollection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractIntCollection.java	5 Jan 2003 03:03:14 -0000	1.1
  +++ AbstractIntCollection.java	6 Jan 2003 03:59:12 -0000	1.2
  @@ -69,7 +69,6 @@
       public abstract IntIterator iterator();
       public abstract int size();
             
  -    
       protected AbstractIntCollection() { }
                 
       /** Unsupported in this base implementation. */
  
  
  
  1.3       +7 -5      jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntList.java
  
  Index: IntList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/IntList.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IntList.java	4 Jan 2003 23:16:29 -0000	1.2
  +++ IntList.java	6 Jan 2003 03:59:12 -0000	1.3
  @@ -67,13 +67,15 @@
    * @version $Revision$ $Date$
    * @author Rodney Waldhoff 
    */
  -public interface IntList {
  +public interface IntList extends IntCollection {
       /** 
        * Inserts the specified element at the specified position 
        * within me (optional operation). 
        */
       void add(int index, int element);
             
  +    boolean addAll(int index, IntCollection collection);
  +    
       /** 
        * Returns the element at the specified position within 
        * me. 
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java
  
  Index: AbstractRandomAccessIntList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/AbstractRandomAccessIntList.java,v 1.1 2003/01/06 03:59:12 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/06 03:59:12 $
   *
   * ====================================================================
   *
   * 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements 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 Group.
   *
   * 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.util.ConcurrentModificationException;
  import java.util.List;
  import java.util.NoSuchElementException;
  
  public abstract class AbstractRandomAccessIntList extends AbstractIntCollection implements IntList {
  
      // constructors
      //-------------------------------------------------------------------------
  
      protected AbstractRandomAccessIntList() { }    
  
      // fully abstract methods
      //-------------------------------------------------------------------------
      
      public abstract int get(int index);
      public abstract int size();
  
      // unsupported in base
      //-------------------------------------------------------------------------
      
      public int removeElementAt(int index) {
          throw new UnsupportedOperationException();
      }
      
      public int set(int index, int element) {
          throw new UnsupportedOperationException();
      }
          
      public void add(int index, int element) {
          throw new UnsupportedOperationException();
      }
  
      //-------------------------------------------------------------------------
      
      public boolean add(int element) {
          add(size(),element);
          return true;
      }
  
      public boolean addAll(int index, IntCollection collection) {
          boolean modified = false;
          for(IntIterator iter = collection.iterator(); iter.hasNext(); ) {
              add(index++,iter.next());
              modified = true;
          }
          return modified;
      }
  
      public int indexOf(int element) {
          int i = 0;
          for(IntIterator iter = iterator(); iter.hasNext(); ) {
              if(iter.next() == element) { 
                  return i;
              } else {
                  i++;
              }
          }
          return -1;
      }
  
      public int lastIndexOf(int element) {
          for(IntListIterator iter = listIterator(size()); iter.hasPrevious(); ) {
              if(iter.previous() == element) {
                  return iter.nextIndex();
              }
          }
          return -1;
      }
  
      public IntIterator iterator() {
          return listIterator();
      }
  
      public IntListIterator listIterator() {
          return listIterator(0);
      }
  
      public IntListIterator listIterator(int index) {
          return new RandomAccessIntListIterator(this,index);            
      }
  
      public IntList subList(int fromIndex, int toIndex) {
          return new RandomAccessIntSubList(this,fromIndex,toIndex);
      }
  
      public boolean equals(Object that) {
          // handle an easy and somewhat frequent case via a shortcut
          if(this == that) { return true; } 
  
          // otherwise, try to get an IntIterator from that object
          IntIterator thatIter = null;        
          if(that instanceof IntList) {
              if(size() != ((IntList)that).size()) { return false; } // another quick check
              thatIter = ((IntList)that).iterator();
          } else if(that instanceof List) {
              if(size() != ((List)that).size()) { return false; } // another quick check
              thatIter = IteratorIntIterator.wrap(((List)that).iterator());
          }
          
          if(null == thatIter) { return false; }
          
          // walk thru thisIter and thatIter, checking for any differences
          for(IntIterator thisIter = iterator(); thisIter.hasNext();) {
              if(!thatIter.hasNext()) { return false; } // thatIter has a different length
              if(thisIter.next() != thatIter.next()) { 
                  return false; 
              }
          }
          
          if(thatIter.hasNext()) { return false; } // thatIter has a different length
          
          return true;
      }
      
      public int hashCode() {
          int hash = 1;
          for(IntIterator iter = iterator(); iter.hasNext(); ) {
              hash = 31*hash + iter.next();
          }
          return hash;
      }
      
      // protected utilities
      //-------------------------------------------------------------------------
      
      protected int getModCount() {
          return _modCount;
      }
  
      protected void incrModCount() {
          _modCount++;
      }
  
      // attributes
      //-------------------------------------------------------------------------
      
      private int _modCount = 0;
  
      // inner classes
      //-------------------------------------------------------------------------
      
      protected static class ComodChecker {
          ComodChecker(AbstractRandomAccessIntList source) {
              _source = source;  
              resyncModCount();             
          }
          
          protected AbstractRandomAccessIntList getList() {
              return _source;
          }
          
          protected void assertNotComodified() throws ConcurrentModificationException {
              if(_expectedModCount != getList().getModCount()) {
                  throw new ConcurrentModificationException();
              }
          }
              
          protected void resyncModCount() {
              _expectedModCount = getList().getModCount();
          }
          
          private AbstractRandomAccessIntList _source = null;
          private int _expectedModCount = -1;
      }
      
      protected static class RandomAccessIntListIterator extends ComodChecker implements IntListIterator {
          RandomAccessIntListIterator(AbstractRandomAccessIntList list) {
              this(list,0);
          }
              
          RandomAccessIntListIterator(AbstractRandomAccessIntList list, int index) {
              super(list);
              if(index < 0 || index > getList().size()) {
                  throw new IllegalArgumentException("Index " + index + " not in [0," + getList().size() + ")");
              } else {
                  _nextIndex = index;
                  resyncModCount();
              }
          }
              
          public boolean hasNext() {
              assertNotComodified();
              return _nextIndex < getList().size();
          }
          
          public boolean hasPrevious() {
              assertNotComodified();
              return _nextIndex > 0;
          }
          
          public int nextIndex() {
              assertNotComodified();
              return _nextIndex;
          }
          
          public int previousIndex() {
              assertNotComodified();
              return _nextIndex - 1;
          }
          
          public int next() {
              assertNotComodified();
              if(!hasNext()) {
                  throw new NoSuchElementException();
              } else {
                  int val = getList().get(_nextIndex);
                  _lastReturnedIndex = _nextIndex;
                  _nextIndex++;
                  return val;
              }
          }
          
          public int previous() {
              assertNotComodified();
              if(!hasPrevious()) {
                  throw new NoSuchElementException();
              } else {
                  int val = getList().get(_nextIndex-1);
                  _lastReturnedIndex = _nextIndex-1;
                  _nextIndex--;
                  return val;
              }
          }
          
          public void add(int value) {
              assertNotComodified();
              getList().add(_nextIndex,value);
              _nextIndex++;
              _lastReturnedIndex = -1;
              resyncModCount();
          }
      
          public void remove() {
              assertNotComodified();
              if(-1 == _lastReturnedIndex) {
                  throw new IllegalStateException();
              } else {
                  getList().removeElementAt(_lastReturnedIndex);
                  _lastReturnedIndex = -1;
                  _nextIndex--;
                  resyncModCount();
              }
          }
          
          public void set(int value) {
              assertNotComodified();
              if(-1 == _lastReturnedIndex) {
                  throw new IllegalStateException();
              } else {
                  getList().set(_lastReturnedIndex,value);
                  resyncModCount();
              }
          }
          
          private int _nextIndex = 0;
          private int _lastReturnedIndex = -1;        
      }   
  
      protected static class RandomAccessIntSubList extends AbstractRandomAccessIntList implements IntList {
          RandomAccessIntSubList(AbstractRandomAccessIntList list, int fromIndex, int toIndex) {
              if(fromIndex < 0 || toIndex > list.size() || fromIndex > toIndex) {
                  throw new IllegalArgumentException();
              } else {
                  _list = list;
                  _offset = fromIndex;
                  _limit = toIndex - fromIndex;
                  _comod = new ComodChecker(list);
                  _comod.resyncModCount();
              }            
          }
      
          public int get(int index) {
              checkRange(index);
              _comod.assertNotComodified();
              return _list.get(toUnderlyingIndex(index));
          }
      
          public int removeElementAt(int index) {
              checkRange(index);
              _comod.assertNotComodified();
              int val = _list.removeElementAt(toUnderlyingIndex(index));
              _limit--;
              _comod.resyncModCount();
              incrModCount();
              return val;
          }
      
          public int set(int index, int element) {
              checkRange(index);
              _comod.assertNotComodified();
              int val = _list.set(toUnderlyingIndex(index),element);
              incrModCount();
              _comod.resyncModCount();
              return val;
          }
      
          public void add(int index, int element) {
              checkRangeIncludingEndpoint(index);
              _comod.assertNotComodified();
               _list.add(toUnderlyingIndex(index),element);
              _limit++;
              _comod.resyncModCount();
              incrModCount();
          }
      
          public int size() {
              _comod.assertNotComodified();
              return _limit;
          }
      
          private void checkRange(int index) {
              if(index < 0 || index >= size()) {
                  throw new IllegalArgumentException("index " + index + " not in [0," + size() + ")");
              }
          }
            
          private void checkRangeIncludingEndpoint(int index) {
              if(index < 0 || index > size()) {
                  throw new IllegalArgumentException("index " + index + " not in [0," + size() + "]");
              }
          }
            
          private int toUnderlyingIndex(int index) {
              return (index + _offset);
          }
          
          private int _offset = 0;        
          private int _limit = 0; 
          private AbstractRandomAccessIntList _list = null;
          private ComodChecker _comod = null;
      
      }
  }
  
  
  
  
  1.1                  jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ArrayIntList.java
  
  Index: ArrayIntList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/primitives/ArrayIntList.java,v 1.1 2003/01/06 03:59:12 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/06 03:59:12 $
   *
   * ====================================================================
   *
   * 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements 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 Group.
   *
   * 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;
  
  public class ArrayIntList extends AbstractRandomAccessIntList implements IntList {
  
      // constructors
      //-------------------------------------------------------------------------
  
      protected ArrayIntList() {
          this(8);
      }    
  
      protected ArrayIntList(int initialCapacity) {
          if(initialCapacity < 0) {
              throw new IllegalArgumentException("capacity " + initialCapacity);
          }
          _data = new int[initialCapacity];
          _size = 0;
      }    
  
      // IntList methods
      //-------------------------------------------------------------------------
  
      public int get(int index) {
          checkRange(index);
          return _data[index];
      }
      
      public int size() {
          return _size;
      }
      
      public int 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;
      }
      
      public int set(int index, int element) {
          checkRange(index);
          incrModCount();
          int oldval = _data[index];
          _data[index] = element;
          return oldval;
      }
          
      public void add(int index, int element) {
          checkRangeIncludingEndpoint(index);
          incrModCount();
          ensureCapacity(_size+1);
          int numtomove = _size-index;
          System.arraycopy(_data,index,_data,index+1,numtomove);
          _data[index] = element;
          _size++;
      }
  
      // capacity methods
      //-------------------------------------------------------------------------
  
      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);
          }
      }
  
      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 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
      //-------------------------------------------------------------------------
      
      private transient int[] _data = null;
      private int _size = 0;
  
  }
  
  
  
  1.3       +5 -4      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestAll.java	4 Jun 2002 16:50:09 -0000	1.2
  +++ TestAll.java	6 Jan 2003 03:59:12 -0000	1.3
  @@ -81,6 +81,7 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite();
  +        suite.addTest(TestArrayIntList.suite());
           suite.addTest(TestUnsignedByteArrayList.suite());
           suite.addTest(TestShortArrayList.suite());
           suite.addTest(TestUnsignedShortArrayList.suite());
  
  
  
  1.1                  jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java
  
  Index: TestArrayIntList.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/primitives/TestArrayIntList.java,v 1.1 2003/01/06 03:59:12 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/06 03:59:12 $
   *
   * ====================================================================
   *
   * 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements 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 Group.
   *
   * 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.util.List;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.collections.BulkTest;
  import org.apache.commons.collections.TestList;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/01/06 03:59:12 $
   * @author Rodney Waldhoff
   */
  public class TestArrayIntList extends TestList {
  
      //------------------------------------------------------------ Conventional
  
      public TestArrayIntList(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          TestSuite suite = BulkTest.makeSuite(TestArrayIntList.class);
          return suite;
      }
  
  
      //------------------------------------------------------- TestList interface
  
      public List makeEmptyList() {
          return new IntListList(new ArrayIntList());
      }
  
      /**
       *  Returns small Integer objects for testing.
       */
      protected Object[] getFullElements() {
          Integer[] result = new Integer[19];
          for (int i = 0; i < result.length; i++) {
              result[i] = new Integer(i + 19);
          }
          return result;
      }
  
      /**
       *  Returns small Integer objects for testing.
       */
      protected Object[] getOtherElements() {
          Integer[] result = new Integer[16];
          for (int i = 0; i < result.length; i++) {
              result[i] = new Integer(i + 48);
          }
          return result;
      }
  
      // TODO:  Create canonical collections in CVS
  
      public void testCanonicalEmptyCollectionExists() {
      }
  
      public void testCanonicalFullCollectionExists() {
      }
  
      public void testEmptyListCompatibility() {
      }
  
      public void testFullListCompatibility() {
      }
  
      //------------------------------------------------------------------- Tests
  
      public void testClearAndSize() {
          IntList list = new ArrayIntList();
          assertEquals(0, list.size());
          for (int i = 0; i < 100; i++) {
              list.add(i);
          }
          assertEquals(100, list.size());
          list.clear();
          assertEquals(0, list.size());
      }
  
      public void testAddGet() {
          IntList list = new ArrayIntList();
          for (int i = 0; i < 1000; i++) {
              list.add(i);
          }
          for (int i = 0; i < 1000; i++) {
              assertEquals(i, list.get(i));
          }
      }
  
      public void testAddGetLargeValues() {
          IntList list = new ArrayIntList();
          for (int i = 0; i < 1000; i++) {
              int value = ((int) (Short.MAX_VALUE));
              value += i;
              list.add(value);
          }
          for (int i = 0; i < 1000; i++) {
              int value = ((int) (Short.MAX_VALUE));
              value += i;
              assertEquals(value, list.get(i));
          }
      }
  
      public void testAddAndShift() {
          IntList list = new ArrayIntList();
          list.add(0, 1);
          assertEquals("Should have one entry", 1, list.size());
          list.add(3);
          list.add(4);
          list.add(1, 2);
          for(int i = 0; i < 4; i++) {
              assertEquals("Should get entry back", i + 1, list.get(i));
          }
          list.add(0, 0);
          for (int i = 0; i < 5; i++) {
              assertEquals("Should get entry back", i, list.get(i));
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>