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/primitives/src/java/org/apache/commons/collections/primitives/adapters Adapt.java
Date Thu, 04 Dec 2003 23:19:23 GMT
rwaldhoff    2003/12/04 15:19:23

  Modified:    primitives/src/test/org/apache/commons/collections/primitives/adapters
                        TestAdapt.java
               primitives/src/java/org/apache/commons/collections/primitives/adapters
                        Adapt.java
  Log:
  add Adapt methods and tests
  
  Revision  Changes    Path
  1.2       +139 -2    jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/TestAdapt.java
  
  Index: TestAdapt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/TestAdapt.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAdapt.java	4 Dec 2003 22:57:19 -0000	1.1
  +++ TestAdapt.java	4 Dec 2003 23:19:22 -0000	1.2
  @@ -57,6 +57,7 @@
   
   package org.apache.commons.collections.primitives.adapters;
   
  +import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.List;
  @@ -73,19 +74,33 @@
   import org.apache.commons.collections.primitives.ArrayIntList;
   import org.apache.commons.collections.primitives.ArrayLongList;
   import org.apache.commons.collections.primitives.ArrayShortList;
  +import org.apache.commons.collections.primitives.ByteCollection;
   import org.apache.commons.collections.primitives.ByteIterator;
  +import org.apache.commons.collections.primitives.ByteList;
   import org.apache.commons.collections.primitives.ByteListIterator;
  +import org.apache.commons.collections.primitives.CharCollection;
   import org.apache.commons.collections.primitives.CharIterator;
  +import org.apache.commons.collections.primitives.CharList;
   import org.apache.commons.collections.primitives.CharListIterator;
  +import org.apache.commons.collections.primitives.DoubleCollection;
   import org.apache.commons.collections.primitives.DoubleIterator;
  +import org.apache.commons.collections.primitives.DoubleList;
   import org.apache.commons.collections.primitives.DoubleListIterator;
  +import org.apache.commons.collections.primitives.FloatCollection;
   import org.apache.commons.collections.primitives.FloatIterator;
  +import org.apache.commons.collections.primitives.FloatList;
   import org.apache.commons.collections.primitives.FloatListIterator;
  +import org.apache.commons.collections.primitives.IntCollection;
   import org.apache.commons.collections.primitives.IntIterator;
  +import org.apache.commons.collections.primitives.IntList;
   import org.apache.commons.collections.primitives.IntListIterator;
  +import org.apache.commons.collections.primitives.LongCollection;
   import org.apache.commons.collections.primitives.LongIterator;
  +import org.apache.commons.collections.primitives.LongList;
   import org.apache.commons.collections.primitives.LongListIterator;
  +import org.apache.commons.collections.primitives.ShortCollection;
   import org.apache.commons.collections.primitives.ShortIterator;
  +import org.apache.commons.collections.primitives.ShortList;
   import org.apache.commons.collections.primitives.ShortListIterator;
   
   /**
  @@ -112,6 +127,9 @@
           assertNotNull(new Adapt());
       }
       
  +    // to object based
  +    //---------------------------------------------------------------
  +    
       public void testToCollection() {
           assertNull(Adapt.toCollection((ArrayByteList)null));
           assertTrue(Adapt.toCollection(new ArrayByteList()) instanceof Collection);
  @@ -178,5 +196,124 @@
           assertTrue(Adapt.toListIterator(new ArrayLongList().listIterator()) instanceof
ListIterator);
           assertNull(Adapt.toListIterator((ShortListIterator)null));
           assertTrue(Adapt.toListIterator(new ArrayShortList().listIterator()) instanceof
ListIterator);
  +    }
  +
  +    // to byte based
  +    //---------------------------------------------------------------
  +    
  +    public void testToByteType() {
  +        assertTrue(Adapt.toByteCollection(new ArrayList()) instanceof ByteCollection);
  +        assertTrue(Adapt.toByteList(new ArrayList()) instanceof ByteList);
  +        assertTrue(Adapt.toByteIterator(new ArrayList().iterator()) instanceof ByteIterator);
  +        assertTrue(Adapt.toByteListIterator(new ArrayList().listIterator()) instanceof
ByteListIterator);
  +    }
  +
  +    public void testToByteTypeFromNull() {
  +        assertNull(Adapt.toByteCollection(null));
  +        assertNull(Adapt.toByteList(null));
  +        assertNull(Adapt.toByteIterator(null));
  +        assertNull(Adapt.toByteListIterator(null));
  +    }
  +
  +    // to char based
  +    //---------------------------------------------------------------
  +    
  +    public void testToCharType() {
  +        assertTrue(Adapt.toCharCollection(new ArrayList()) instanceof CharCollection);
  +        assertTrue(Adapt.toCharList(new ArrayList()) instanceof CharList);
  +        assertTrue(Adapt.toCharIterator(new ArrayList().iterator()) instanceof CharIterator);
  +        assertTrue(Adapt.toCharListIterator(new ArrayList().listIterator()) instanceof
CharListIterator);
  +    }
  +
  +    public void testToCharTypeFromNull() {
  +        assertNull(Adapt.toCharCollection(null));
  +        assertNull(Adapt.toCharList(null));
  +        assertNull(Adapt.toCharIterator(null));
  +        assertNull(Adapt.toCharListIterator(null));
  +    }
  +
  +    // to double based
  +    //---------------------------------------------------------------
  +    
  +    public void testToDoubleType() {
  +        assertTrue(Adapt.toDoubleCollection(new ArrayList()) instanceof DoubleCollection);
  +        assertTrue(Adapt.toDoubleList(new ArrayList()) instanceof DoubleList);
  +        assertTrue(Adapt.toDoubleIterator(new ArrayList().iterator()) instanceof DoubleIterator);
  +        assertTrue(Adapt.toDoubleListIterator(new ArrayList().listIterator()) instanceof
DoubleListIterator);
  +    }
  +
  +    public void testToDoubleTypeFromNull() {
  +        assertNull(Adapt.toDoubleCollection(null));
  +        assertNull(Adapt.toDoubleList(null));
  +        assertNull(Adapt.toDoubleIterator(null));
  +        assertNull(Adapt.toDoubleListIterator(null));
  +    }
  +
  +    // to float based
  +    //---------------------------------------------------------------
  +    
  +    public void testToFloatType() {
  +        assertTrue(Adapt.toFloatCollection(new ArrayList()) instanceof FloatCollection);
  +        assertTrue(Adapt.toFloatList(new ArrayList()) instanceof FloatList);
  +        assertTrue(Adapt.toFloatIterator(new ArrayList().iterator()) instanceof FloatIterator);
  +        assertTrue(Adapt.toFloatListIterator(new ArrayList().listIterator()) instanceof
FloatListIterator);
  +    }
  +
  +    public void testToFloatTypeFromNull() {
  +        assertNull(Adapt.toFloatCollection(null));
  +        assertNull(Adapt.toFloatList(null));
  +        assertNull(Adapt.toFloatIterator(null));
  +        assertNull(Adapt.toFloatListIterator(null));
  +    }
  +
  +    // to int based
  +    //---------------------------------------------------------------
  +    
  +    public void testToIntType() {
  +        assertTrue(Adapt.toIntCollection(new ArrayList()) instanceof IntCollection);
  +        assertTrue(Adapt.toIntList(new ArrayList()) instanceof IntList);
  +        assertTrue(Adapt.toIntIterator(new ArrayList().iterator()) instanceof IntIterator);
  +        assertTrue(Adapt.toIntListIterator(new ArrayList().listIterator()) instanceof IntListIterator);
  +    }
  +
  +    public void testToIntTypeFromNull() {
  +        assertNull(Adapt.toIntCollection(null));
  +        assertNull(Adapt.toIntList(null));
  +        assertNull(Adapt.toIntIterator(null));
  +        assertNull(Adapt.toIntListIterator(null));
  +    }
  +
  +    // to long based
  +    //---------------------------------------------------------------
  +    
  +    public void testToLongType() {
  +        assertTrue(Adapt.toLongCollection(new ArrayList()) instanceof LongCollection);
  +        assertTrue(Adapt.toLongList(new ArrayList()) instanceof LongList);
  +        assertTrue(Adapt.toLongIterator(new ArrayList().iterator()) instanceof LongIterator);
  +        assertTrue(Adapt.toLongListIterator(new ArrayList().listIterator()) instanceof
LongListIterator);
  +    }
  +
  +    public void testToLongTypeFromNull() {
  +        assertNull(Adapt.toLongCollection(null));
  +        assertNull(Adapt.toLongList(null));
  +        assertNull(Adapt.toLongIterator(null));
  +        assertNull(Adapt.toLongListIterator(null));
  +    }
  +
  +    // to short based
  +    //---------------------------------------------------------------
  +    
  +    public void testToShortType() {
  +        assertTrue(Adapt.toShortCollection(new ArrayList()) instanceof ShortCollection);
  +        assertTrue(Adapt.toShortList(new ArrayList()) instanceof ShortList);
  +        assertTrue(Adapt.toShortIterator(new ArrayList().iterator()) instanceof ShortIterator);
  +        assertTrue(Adapt.toShortListIterator(new ArrayList().listIterator()) instanceof
ShortListIterator);
  +    }
  +
  +    public void testToShortTypeFromNull() {
  +        assertNull(Adapt.toShortCollection(null));
  +        assertNull(Adapt.toShortList(null));
  +        assertNull(Adapt.toShortIterator(null));
  +        assertNull(Adapt.toShortListIterator(null));
       }
   }
  
  
  
  1.2       +137 -2    jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters/Adapt.java
  
  Index: Adapt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters/Adapt.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Adapt.java	4 Dec 2003 22:57:19 -0000	1.1
  +++ Adapt.java	4 Dec 2003 23:19:23 -0000	1.2
  @@ -102,6 +102,9 @@
       public Adapt() {
       }
       
  +    // to object based
  +    //---------------------------------------------------------------
  +
       public static final Collection toCollection(ByteCollection c) {
           return ByteCollectionCollection.wrap(c);
       }
  @@ -214,4 +217,136 @@
           return ShortListIteratorListIterator.wrap(c);
       }
   
  +    // to byte based
  +    //---------------------------------------------------------------
  +    
  +    public static final ByteCollection toByteCollection(Collection c) {
  +        return CollectionByteCollection.wrap(c);
  +    }
  +
  +    public static final ByteList toByteList(List c) {
  +        return ListByteList.wrap(c);
  +    }
  +
  +    public static final ByteIterator toByteIterator(Iterator c) {
  +        return IteratorByteIterator.wrap(c);
  +    }
  +
  +    public static final ByteListIterator toByteListIterator(ListIterator c) {
  +        return ListIteratorByteListIterator.wrap(c);
  +    }
  +
  +    // to char based
  +    //---------------------------------------------------------------
  +    
  +    public static final CharCollection toCharCollection(Collection c) {
  +        return CollectionCharCollection.wrap(c);
  +    }
  +
  +    public static final CharList toCharList(List c) {
  +        return ListCharList.wrap(c);
  +    }
  +
  +    public static final CharIterator toCharIterator(Iterator c) {
  +        return IteratorCharIterator.wrap(c);
  +    }
  +
  +    public static final CharListIterator toCharListIterator(ListIterator c) {
  +        return ListIteratorCharListIterator.wrap(c);
  +    }
  +
  +    // to double based
  +    //---------------------------------------------------------------
  +    
  +    public static final DoubleCollection toDoubleCollection(Collection c) {
  +        return CollectionDoubleCollection.wrap(c);
  +    }
  +
  +    public static final DoubleList toDoubleList(List c) {
  +        return ListDoubleList.wrap(c);
  +    }
  +
  +    public static final DoubleIterator toDoubleIterator(Iterator c) {
  +        return IteratorDoubleIterator.wrap(c);
  +    }
  +
  +    public static final DoubleListIterator toDoubleListIterator(ListIterator c) {
  +        return ListIteratorDoubleListIterator.wrap(c);
  +    }
  +    
  +    // to float based
  +    //---------------------------------------------------------------
  +    
  +    public static final FloatCollection toFloatCollection(Collection c) {
  +        return CollectionFloatCollection.wrap(c);
  +    }
  +
  +    public static final FloatList toFloatList(List c) {
  +        return ListFloatList.wrap(c);
  +    }
  +
  +    public static final FloatIterator toFloatIterator(Iterator c) {
  +        return IteratorFloatIterator.wrap(c);
  +    }
  +
  +    public static final FloatListIterator toFloatListIterator(ListIterator c) {
  +        return ListIteratorFloatListIterator.wrap(c);
  +    }
  +    
  +    // to int based
  +    //---------------------------------------------------------------
  +    
  +    public static final IntCollection toIntCollection(Collection c) {
  +        return CollectionIntCollection.wrap(c);
  +    }
  +
  +    public static final IntList toIntList(List c) {
  +        return ListIntList.wrap(c);
  +    }
  +
  +    public static final IntIterator toIntIterator(Iterator c) {
  +        return IteratorIntIterator.wrap(c);
  +    }
  +
  +    public static final IntListIterator toIntListIterator(ListIterator c) {
  +        return ListIteratorIntListIterator.wrap(c);
  +    }
  +    
  +    // to long based
  +    //---------------------------------------------------------------
  +    
  +    public static final LongCollection toLongCollection(Collection c) {
  +        return CollectionLongCollection.wrap(c);
  +    }
  +
  +    public static final LongList toLongList(List c) {
  +        return ListLongList.wrap(c);
  +    }
  +
  +    public static final LongIterator toLongIterator(Iterator c) {
  +        return IteratorLongIterator.wrap(c);
  +    }
  +
  +    public static final LongListIterator toLongListIterator(ListIterator c) {
  +        return ListIteratorLongListIterator.wrap(c);
  +    }
  +    
  +    // to short based
  +    //---------------------------------------------------------------
  +    
  +    public static final ShortCollection toShortCollection(Collection c) {
  +        return CollectionShortCollection.wrap(c);
  +    }
  +
  +    public static final ShortList toShortList(List c) {
  +        return ListShortList.wrap(c);
  +    }
  +
  +    public static final ShortIterator toShortIterator(Iterator c) {
  +        return IteratorShortIterator.wrap(c);
  +    }
  +
  +    public static final ShortListIterator toShortListIterator(ListIterator c) {
  +        return ListIteratorShortListIterator.wrap(c);
  +    }
   }
  
  
  

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