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/12/04 23:57:19 UTC

cvs commit: jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters Adapt.java

rwaldhoff    2003/12/04 14:57:19

  Modified:    primitives project.xml build.xml
               primitives/src/test/org/apache/commons/collections/primitives/adapters
                        PackageTestSuite.java
  Added:       primitives/src/test/org/apache/commons/collections/primitives/adapters
                        TestAdapt.java
               primitives/src/java/org/apache/commons/collections/primitives/adapters
                        Adapt.java
  Log:
  * add util method container Adapt, and tests
  * set version numbers to 1.1-dev (instead of 2.0-dev)
  
  Revision  Changes    Path
  1.11      +1 -1      jakarta-commons/primitives/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/project.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- project.xml	6 Nov 2003 01:06:58 -0000	1.10
  +++ project.xml	4 Dec 2003 22:57:19 -0000	1.11
  @@ -3,7 +3,7 @@
     <extend>../xdocs/maven/project-base.xml</extend>
     <id>commons-primitives</id>
     <name>Commons Primitives</name>
  -  <currentVersion>2.0-dev</currentVersion>
  +  <currentVersion>1.1-dev</currentVersion>
     <inceptionYear>2002</inceptionYear>
   
     <package>org.apache.commons.collections.primitives</package>
  
  
  
  1.9       +2 -2      jakarta-commons/primitives/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/build.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- build.xml	6 Nov 2003 01:06:58 -0000	1.8
  +++ build.xml	4 Dec 2003 22:57:19 -0000	1.9
  @@ -43,7 +43,7 @@
     <property name="component.title"         value="Primitive type utilities"/>
   
     <!-- The current version number of this component -->
  -  <property name="component.version"       value="2.0-dev"/>
  +  <property name="component.version"       value="1.1-dev"/>
   
     <!-- The final name of the component -->
     <property name="final.name"              value="commons-${component.name}-${component.version}"/>
  
  
  
  1.2       +4 -2      jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/PackageTestSuite.java
  
  Index: PackageTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/PackageTestSuite.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PackageTestSuite.java	13 Oct 2003 22:46:54 -0000	1.1
  +++ PackageTestSuite.java	4 Dec 2003 22:57:19 -0000	1.2
  @@ -78,6 +78,8 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite();
  +
  +        suite.addTest(TestAdapt.suite());
           
           suite.addTest(TestCollectionByteCollection.suite());
           suite.addTest(TestByteCollectionCollection.suite());
  
  
  
  1.1                  jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/TestAdapt.java
  
  Index: TestAdapt.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/primitives/src/test/org/apache/commons/collections/primitives/adapters/TestAdapt.java,v 1.1 2003/12/04 22:57:19 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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.adapters;
  
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.commons.collections.primitives.ArrayByteList;
  import org.apache.commons.collections.primitives.ArrayCharList;
  import org.apache.commons.collections.primitives.ArrayDoubleList;
  import org.apache.commons.collections.primitives.ArrayFloatList;
  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.ByteIterator;
  import org.apache.commons.collections.primitives.ByteListIterator;
  import org.apache.commons.collections.primitives.CharIterator;
  import org.apache.commons.collections.primitives.CharListIterator;
  import org.apache.commons.collections.primitives.DoubleIterator;
  import org.apache.commons.collections.primitives.DoubleListIterator;
  import org.apache.commons.collections.primitives.FloatIterator;
  import org.apache.commons.collections.primitives.FloatListIterator;
  import org.apache.commons.collections.primitives.IntIterator;
  import org.apache.commons.collections.primitives.IntListIterator;
  import org.apache.commons.collections.primitives.LongIterator;
  import org.apache.commons.collections.primitives.LongListIterator;
  import org.apache.commons.collections.primitives.ShortIterator;
  import org.apache.commons.collections.primitives.ShortListIterator;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2003/12/04 22:57:19 $
   * @author Rodney Waldhoff
   */
  public class TestAdapt extends TestCase {
  
      // conventional
      // ------------------------------------------------------------------------
  
      public TestAdapt(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestAdapt.class);
      }
  
      // tests
      // ------------------------------------------------------------------------
  
      public void testHasPublicConstructorForReflectionBasedAPIs() {
          assertNotNull(new Adapt());
      }
      
      public void testToCollection() {
          assertNull(Adapt.toCollection((ArrayByteList)null));
          assertTrue(Adapt.toCollection(new ArrayByteList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayCharList)null));
          assertTrue(Adapt.toCollection(new ArrayCharList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayDoubleList)null));
          assertTrue(Adapt.toCollection(new ArrayDoubleList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayFloatList)null));
          assertTrue(Adapt.toCollection(new ArrayFloatList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayIntList)null));
          assertTrue(Adapt.toCollection(new ArrayIntList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayLongList)null));
          assertTrue(Adapt.toCollection(new ArrayLongList()) instanceof Collection);
          assertNull(Adapt.toCollection((ArrayShortList)null));
          assertTrue(Adapt.toCollection(new ArrayShortList()) instanceof Collection);
      }
      
      public void testToList() {
          assertNull(Adapt.toList((ArrayByteList)null));
          assertTrue(Adapt.toList(new ArrayByteList()) instanceof List);
          assertNull(Adapt.toList((ArrayCharList)null));
          assertTrue(Adapt.toList(new ArrayCharList()) instanceof List);
          assertNull(Adapt.toList((ArrayDoubleList)null));
          assertTrue(Adapt.toList(new ArrayDoubleList()) instanceof List);
          assertNull(Adapt.toList((ArrayFloatList)null));
          assertTrue(Adapt.toList(new ArrayFloatList()) instanceof List);
          assertNull(Adapt.toList((ArrayIntList)null));
          assertTrue(Adapt.toList(new ArrayIntList()) instanceof List);
          assertNull(Adapt.toList((ArrayLongList)null));
          assertTrue(Adapt.toList(new ArrayLongList()) instanceof List);
          assertNull(Adapt.toList((ArrayShortList)null));
          assertTrue(Adapt.toList(new ArrayShortList()) instanceof List);
      }
      
      public void testToIterator() {
          assertNull(Adapt.toIterator((ByteIterator)null));
          assertTrue(Adapt.toIterator(new ArrayByteList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((CharIterator)null));
          assertTrue(Adapt.toIterator(new ArrayCharList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((DoubleIterator)null));
          assertTrue(Adapt.toIterator(new ArrayDoubleList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((FloatIterator)null));
          assertTrue(Adapt.toIterator(new ArrayFloatList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((IntIterator)null));
          assertTrue(Adapt.toIterator(new ArrayIntList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((LongIterator)null));
          assertTrue(Adapt.toIterator(new ArrayLongList().iterator()) instanceof Iterator);
          assertNull(Adapt.toIterator((ShortIterator)null));
          assertTrue(Adapt.toIterator(new ArrayShortList().iterator()) instanceof Iterator);
      }
  
      public void testToListIterator() {
          assertNull(Adapt.toListIterator((ByteListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayByteList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((CharListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayCharList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((DoubleListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayDoubleList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((FloatListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayFloatList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((IntListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayIntList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((LongListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayLongList().listIterator()) instanceof ListIterator);
          assertNull(Adapt.toListIterator((ShortListIterator)null));
          assertTrue(Adapt.toListIterator(new ArrayShortList().listIterator()) instanceof ListIterator);
      }
  }
  
  
  
  1.1                  jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters/Adapt.java
  
  Index: Adapt.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters/Adapt.java,v 1.1 2003/12/04 22:57:19 rwaldhoff Exp $
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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.adapters;
  
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  
  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;
  
  /**
   * Convenience methods for constructing adapters.
   *  
   * @since Commons Primitives 1.1
   * @version $Revision: 1.1 $ $Date: 2003/12/04 22:57:19 $
   * @author Rodney Waldhoff 
   */
  public final class Adapt {
      public Adapt() {
      }
      
      public static final Collection toCollection(ByteCollection c) {
          return ByteCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(CharCollection c) {
          return CharCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(DoubleCollection c) {
          return DoubleCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(FloatCollection c) {
          return FloatCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(IntCollection c) {
          return IntCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(LongCollection c) {
          return LongCollectionCollection.wrap(c);
      }
      
      public static final Collection toCollection(ShortCollection c) {
          return ShortCollectionCollection.wrap(c);
      }
  
      public static final List toList(ByteList c) {
          return ByteListList.wrap(c);
      }
      
      public static final List toList(CharList c) {
          return CharListList.wrap(c);
      }
      
      public static final List toList(DoubleList c) {
          return DoubleListList.wrap(c);
      }
      
      public static final List toList(FloatList c) {
          return FloatListList.wrap(c);
      }
      
      public static final List toList(IntList c) {
          return IntListList.wrap(c);
      }
      
      public static final List toList(LongList c) {
          return LongListList.wrap(c);
      }
      
      public static final List toList(ShortList c) {
          return ShortListList.wrap(c);
      }
  
      public static final Iterator toIterator(ByteIterator c) {
          return ByteIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(CharIterator c) {
          return CharIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(DoubleIterator c) {
          return DoubleIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(FloatIterator c) {
          return FloatIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(IntIterator c) {
          return IntIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(LongIterator c) {
          return LongIteratorIterator.wrap(c);
      }
      
      public static final Iterator toIterator(ShortIterator c) {
          return ShortIteratorIterator.wrap(c);
      }
  
      public static final ListIterator toListIterator(ByteListIterator c) {
          return ByteListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(CharListIterator c) {
          return CharListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(DoubleListIterator c) {
          return DoubleListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(FloatListIterator c) {
          return FloatListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(IntListIterator c) {
          return IntListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(LongListIterator c) {
          return LongListIteratorListIterator.wrap(c);
      }
      
      public static final ListIterator toListIterator(ShortListIterator c) {
          return ShortListIteratorListIterator.wrap(c);
      }
  
  }
  
  

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