* add IntCollections and test

* add additional primitives.decorators.* tests


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2003-05-20 17:05:28 +00:00
parent 813df07aae
commit d74454646d
10 changed files with 803 additions and 20 deletions

View File

@ -0,0 +1,163 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/Attic/IntCollections.java,v 1.1 2003/05/20 17:05:28 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 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 org.apache.commons.collections.primitives.decorators.UnmodifiableIntIterator;
import org.apache.commons.collections.primitives.decorators.UnmodifiableIntList;
import org.apache.commons.collections.primitives.decorators.UnmodifiableIntListIterator;
/**
* This class consists exclusively of static methods that operate on or
* return IntCollections.
* <p>
* The methods of this class all throw a NullPointerException is the
* provided collections are null.
*
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
*
* @author Rodney Waldhoff
*/
public class IntCollections {
/**
* Returns an unmodifiable version of the given non-null IntList.
* @param list the non-null IntList to wrap in an unmodifiable decorator
* @return an unmodifiable version of the given non-null IntList
* @throws NullPointerException if the given IntList is null
* @see org.apache.commons.collections.primitives.decorators.UnmodifiableIntList#wrap
*/
public static final IntList unmodifiableIntList(IntList list) throws NullPointerException {
if(null == list) {
throw new NullPointerException();
}
return UnmodifiableIntList.wrap(list);
}
/**
* Returns an unmodifiable version of the given non-null IntIterator.
* @param list the non-null IntIterator to wrap in an unmodifiable decorator
* @return an unmodifiable version of the given non-null IntIterator
* @throws NullPointerException if the given IntIterator is null
* @see org.apache.commons.collections.primitives.decorators.UnmodifiableIntIterator#wrap
*/
public static final IntIterator unmodifiableIntIterator(IntIterator iter) {
if(null == iter) {
throw new NullPointerException();
}
return UnmodifiableIntIterator.wrap(iter);
}
/**
* Returns an unmodifiable version of the given non-null IntListIterator.
* @param list the non-null IntListIterator to wrap in an unmodifiable decorator
* @return an unmodifiable version of the given non-null IntListIterator
* @throws NullPointerException if the given IntListIterator is null
* @see org.apache.commons.collections.primitives.decorators.UnmodifiableIntListIterator#wrap
*/
public static final IntListIterator unmodifiableIntListIterator(IntListIterator iter) {
if(null == iter) {
throw new NullPointerException();
}
return UnmodifiableIntListIterator.wrap(iter);
}
/**
* Returns an unmodifiable, empty IntList.
* @return an unmodifiable, empty IntList.
* @see #EMPTY_INT_LIST
*/
public static final IntList getEmptyIntList() {
return EMPTY_INT_LIST;
}
/**
* Returns an unmodifiable, empty IntIterator
* @return an unmodifiable, empty IntIterator.
* @see #EMPTY_INT_ITERATOR
*/
public static final IntIterator getEmptyIntIterator() {
return EMPTY_INT_ITERATOR;
}
/**
* Returns an unmodifiable, empty IntListIterator
* @return an unmodifiable, empty IntListIterator.
* @see #EMPTY_INT_LIST_ITERATOR
*/
public static final IntListIterator getEmptyIntListIterator() {
return EMPTY_INT_LIST_ITERATOR;
}
/**
* An unmodifiable, empty IntList
* @see #getEmptyIntList
*/
public static final IntList EMPTY_INT_LIST = unmodifiableIntList(new ArrayIntList(0));
/**
* An unmodifiable, empty IntIterator
* @see #getEmptyIntIterator
*/
public static final IntIterator EMPTY_INT_ITERATOR = unmodifiableIntIterator(EMPTY_INT_LIST.iterator());
/**
* An unmodifiable, empty IntListIterator
* @see #getEmptyIntListIterator
*/
public static final IntListIterator EMPTY_INT_LIST_ITERATOR = unmodifiableIntListIterator(EMPTY_INT_LIST.listIterator());
}

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/decorators/Attic/ProxyIntIterator.java,v 1.1 2003/05/20 00:44:11 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/decorators/Attic/ProxyIntIterator.java,v 1.2 2003/05/20 17:05:27 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -62,7 +62,7 @@ import org.apache.commons.collections.primitives.IntIterator;
/** /**
* *
* @since Commons Collections 2.2 * @since Commons Collections 2.2
* @version $Revision: 1.1 $ $Date: 2003/05/20 00:44:11 $ * @version $Revision: 1.2 $ $Date: 2003/05/20 17:05:27 $
* *
* @author Rodney Waldhoff * @author Rodney Waldhoff
*/ */
@ -78,9 +78,5 @@ abstract class ProxyIntIterator implements IntIterator {
return getIterator().next(); return getIterator().next();
} }
public void remove() {
getIterator().remove();
}
protected abstract IntIterator getIterator(); protected abstract IntIterator getIterator();
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/decorators/Attic/ProxyIntListIterator.java,v 1.1 2003/05/20 00:44:11 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/primitives/decorators/Attic/ProxyIntListIterator.java,v 1.2 2003/05/20 17:05:28 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -63,7 +63,7 @@ import org.apache.commons.collections.primitives.IntListIterator;
/** /**
* *
* @since Commons Collections 2.2 * @since Commons Collections 2.2
* @version $Revision: 1.1 $ $Date: 2003/05/20 00:44:11 $ * @version $Revision: 1.2 $ $Date: 2003/05/20 17:05:28 $
* *
* @author Rodney Waldhoff * @author Rodney Waldhoff
*/ */
@ -71,10 +71,6 @@ abstract class ProxyIntListIterator extends ProxyIntIterator implements IntListI
ProxyIntListIterator() { ProxyIntListIterator() {
} }
public void add(int element) {
getListIterator().add(element);
}
public boolean hasPrevious() { public boolean hasPrevious() {
return getListIterator().hasPrevious(); return getListIterator().hasPrevious();
} }
@ -91,10 +87,6 @@ abstract class ProxyIntListIterator extends ProxyIntIterator implements IntListI
return getListIterator().previousIndex(); return getListIterator().previousIndex();
} }
public void set(int element) {
getListIterator().set(element);
}
protected final IntIterator getIterator() { protected final IntIterator getIterator() {
return getListIterator(); return getListIterator();
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAll.java,v 1.19 2003/05/04 13:06:14 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestAll.java,v 1.20 2003/05/20 17:05:28 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -62,7 +62,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
/** /**
* @version $Revision: 1.19 $ $Date: 2003/05/04 13:06:14 $ * @version $Revision: 1.20 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff * @author Rodney Waldhoff
*/ */
public class TestAll extends TestCase { public class TestAll extends TestCase {
@ -91,6 +91,7 @@ public class TestAll extends TestCase {
suite.addTest(TestRandomAccessCharList.suite()); suite.addTest(TestRandomAccessCharList.suite());
suite.addTest(TestArrayCharList.suite()); suite.addTest(TestArrayCharList.suite());
suite.addTest(TestIntCollections.suite());
suite.addTest(TestAbstractIntCollection.suite()); suite.addTest(TestAbstractIntCollection.suite());
suite.addTest(TestRandomAccessIntList.suite()); suite.addTest(TestRandomAccessIntList.suite());
suite.addTest(TestArrayIntList.suite()); suite.addTest(TestArrayIntList.suite());

View File

@ -0,0 +1,144 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/Attic/TestIntCollections.java,v 1.1 2003/05/20 17:05:28 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.TestCase;
import junit.framework.TestSuite;
/**
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff
* @deprecated as the tested classes are deprecated also
*/
public class TestIntCollections extends TestCase {
//------------------------------------------------------------ Conventional
public TestIntCollections(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestIntCollections.class);
}
//---------------------------------------------------------------- Tests
public void testUnmodifiableIntListNull() {
try {
IntCollections.unmodifiableIntList(null);
fail("Expected NullPointerException");
} catch(NullPointerException e) {
// expected
}
}
public void testEmptyIntList() {
assertSame(IntCollections.EMPTY_INT_LIST,IntCollections.getEmptyIntList());
assertTrue(IntCollections.EMPTY_INT_LIST.isEmpty());
try {
IntCollections.EMPTY_INT_LIST.add(1);
fail("Expected UnsupportedOperationExcpetion");
} catch(UnsupportedOperationException e) {
// expected
}
}
public void testUnmodifiableIntIteratorNull() {
try {
IntCollections.unmodifiableIntIterator(null);
fail("Expected NullPointerException");
} catch(NullPointerException e) {
// expected
}
}
public void testEmptyIntIterator() {
assertSame(IntCollections.EMPTY_INT_ITERATOR,IntCollections.getEmptyIntIterator());
assertTrue(! IntCollections.EMPTY_INT_ITERATOR.hasNext());
try {
IntCollections.EMPTY_INT_ITERATOR.remove();
fail("Expected UnsupportedOperationExcpetion");
} catch(UnsupportedOperationException e) {
// expected
}
}
public void testUnmodifiableIntListIteratorNull() {
try {
IntCollections.unmodifiableIntListIterator(null);
fail("Expected NullPointerException");
} catch(NullPointerException e) {
// expected
}
}
public void testEmptyIntListIterator() {
assertSame(IntCollections.EMPTY_INT_LIST_ITERATOR,IntCollections.getEmptyIntListIterator());
assertTrue(! IntCollections.EMPTY_INT_LIST_ITERATOR.hasNext());
assertTrue(! IntCollections.EMPTY_INT_LIST_ITERATOR.hasPrevious());
try {
IntCollections.EMPTY_INT_LIST_ITERATOR.add(1);
fail("Expected UnsupportedOperationExcpetion");
} catch(UnsupportedOperationException e) {
// expected
}
}
}

View File

@ -0,0 +1,116 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/BaseUnmodifiableIntIteratorTest.java,v 1.1 2003/05/20 17:05:28 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 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.decorators;
import junit.framework.TestCase;
import org.apache.commons.collections.primitives.ArrayIntList;
import org.apache.commons.collections.primitives.IntIterator;
import org.apache.commons.collections.primitives.IntList;
/**
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff
*/
public abstract class BaseUnmodifiableIntIteratorTest extends TestCase {
// conventional
// ------------------------------------------------------------------------
public BaseUnmodifiableIntIteratorTest(String testName) {
super(testName);
}
// framework
// ------------------------------------------------------------------------
protected abstract IntIterator makeUnmodifiableIntIterator();
protected IntIterator makeIntIterator() {
IntList list = new ArrayIntList();
for(int i=0;i<10;i++) {
list.add(i);
}
return list.iterator();
}
// tests
// ------------------------------------------------------------------------
public final void testIntIteratorNotModifiable() {
IntIterator iter = makeUnmodifiableIntIterator();
assertTrue(iter.hasNext());
iter.next();
try {
iter.remove();
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
public final void testIterateIntIterator() {
IntIterator iter = makeUnmodifiableIntIterator();
for(IntIterator expected = makeIntIterator(); expected.hasNext(); ) {
assertTrue(iter.hasNext());
assertEquals(expected.next(),iter.next());
}
assertTrue(! iter.hasNext() );
}
}

View File

@ -0,0 +1,157 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/BaseUnmodifiableIntListIteratorTest.java,v 1.1 2003/05/20 17:05:28 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 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.decorators;
import org.apache.commons.collections.primitives.ArrayIntList;
import org.apache.commons.collections.primitives.IntIterator;
import org.apache.commons.collections.primitives.IntList;
import org.apache.commons.collections.primitives.IntListIterator;
/**
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff
*/
public abstract class BaseUnmodifiableIntListIteratorTest extends BaseUnmodifiableIntIteratorTest {
// conventional
// ------------------------------------------------------------------------
public BaseUnmodifiableIntListIteratorTest(String testName) {
super(testName);
}
// framework
// ------------------------------------------------------------------------
protected abstract IntListIterator makeUnmodifiableIntListIterator();
protected IntIterator makeUnmodifiableIntIterator() {
return makeUnmodifiableIntListIterator();
}
protected IntIterator makeIntIterator() {
return makeIntListIterator();
}
protected IntListIterator makeIntListIterator() {
IntList list = new ArrayIntList();
for(int i=0;i<10;i++) {
list.add(i);
}
return list.listIterator();
}
// tests
// ------------------------------------------------------------------------
public final void testIntListIteratorNotModifiable() {
IntListIterator iter = makeUnmodifiableIntListIterator();
assertTrue(iter.hasNext());
iter.next();
try {
iter.remove();
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
try {
iter.add(1);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
try {
iter.set(3);
fail("Expected UnsupportedOperationException");
} catch(UnsupportedOperationException e) {
// expected
}
}
public final void testIterateIntListIterator() {
IntListIterator iter = makeUnmodifiableIntListIterator();
IntListIterator expected = makeIntListIterator();
assertTrue(! iter.hasPrevious());
while( expected.hasNext() ) {
assertTrue(iter.hasNext());
assertEquals(expected.nextIndex(),iter.nextIndex());
assertEquals(expected.previousIndex(),iter.previousIndex());
assertEquals(expected.next(),iter.next());
assertTrue(iter.hasPrevious());
assertEquals(expected.nextIndex(),iter.nextIndex());
assertEquals(expected.previousIndex(),iter.previousIndex());
}
assertTrue(! iter.hasNext() );
while( expected.hasPrevious() ) {
assertTrue(iter.hasPrevious());
assertEquals(expected.nextIndex(),iter.nextIndex());
assertEquals(expected.previousIndex(),iter.previousIndex());
assertEquals(expected.previous(),iter.previous());
assertTrue(iter.hasNext());
assertEquals(expected.nextIndex(),iter.nextIndex());
assertEquals(expected.previousIndex(),iter.previousIndex());
}
assertTrue(! iter.hasPrevious() );
}
}

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/TestAll.java,v 1.3 2003/05/20 00:44:11 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/TestAll.java,v 1.4 2003/05/20 17:05:28 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -62,7 +62,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
/** /**
* @version $Revision: 1.3 $ $Date: 2003/05/20 00:44:11 $ * @version $Revision: 1.4 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff * @author Rodney Waldhoff
*/ */
public class TestAll extends TestCase { public class TestAll extends TestCase {
@ -81,6 +81,8 @@ public class TestAll extends TestCase {
suite.addTest(TestBaseProxyIntCollection.suite()); suite.addTest(TestBaseProxyIntCollection.suite());
suite.addTest(TestBaseProxyIntList.suite()); suite.addTest(TestBaseProxyIntList.suite());
suite.addTest(TestUnmodifiableIntList.suite()); suite.addTest(TestUnmodifiableIntList.suite());
suite.addTest(TestUnmodifiableIntIterator.suite());
suite.addTest(TestUnmodifiableIntListIterator.suite());
return suite; return suite;
} }

View File

@ -0,0 +1,106 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/TestUnmodifiableIntIterator.java,v 1.1 2003/05/20 17:05:28 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 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.decorators;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.primitives.IntIterator;
/**
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff
*/
public class TestUnmodifiableIntIterator extends BaseUnmodifiableIntIteratorTest {
// conventional
// ------------------------------------------------------------------------
public TestUnmodifiableIntIterator(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestUnmodifiableIntIterator.class);
}
// framework
// ------------------------------------------------------------------------
protected IntIterator makeUnmodifiableIntIterator() {
return UnmodifiableIntIterator.wrap(makeIntIterator());
}
// tests
// ------------------------------------------------------------------------
public void testWrapNotNull() {
assertNotNull(UnmodifiableIntIterator.wrap(makeIntIterator()));
}
public void testWrapNull() {
assertNull(UnmodifiableIntIterator.wrap(null));
}
public void testWrapUnmodifiableIntIterator() {
IntIterator iter = makeUnmodifiableIntIterator();
assertSame(iter,UnmodifiableIntIterator.wrap(iter));
}
}

View File

@ -0,0 +1,106 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/primitives/decorators/Attic/TestUnmodifiableIntListIterator.java,v 1.1 2003/05/20 17:05:28 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 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.decorators;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.primitives.IntListIterator;
/**
* @version $Revision: 1.1 $ $Date: 2003/05/20 17:05:28 $
* @author Rodney Waldhoff
*/
public class TestUnmodifiableIntListIterator extends BaseUnmodifiableIntListIteratorTest {
// conventional
// ------------------------------------------------------------------------
public TestUnmodifiableIntListIterator(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestUnmodifiableIntListIterator.class);
}
// framework
// ------------------------------------------------------------------------
protected IntListIterator makeUnmodifiableIntListIterator() {
return UnmodifiableIntListIterator.wrap(makeIntListIterator());
}
// tests
// ------------------------------------------------------------------------
public void testWrapNotNull() {
assertNotNull(UnmodifiableIntListIterator.wrap(makeIntListIterator()));
}
public void testWrapNull() {
assertNull(UnmodifiableIntListIterator.wrap(null));
}
public void testWrapUnmodifiableIntListIterator() {
IntListIterator iter = makeUnmodifiableIntListIterator();
assertSame(iter,UnmodifiableIntListIterator.wrap(iter));
}
}