diff --git a/src/java/org/apache/commons/collections/comparators/NullComparator.java b/src/java/org/apache/commons/collections/comparators/NullComparator.java index 322746b97..1334ea496 100644 --- a/src/java/org/apache/commons/collections/comparators/NullComparator.java +++ b/src/java/org/apache/commons/collections/comparators/NullComparator.java @@ -19,6 +19,8 @@ package org.apache.commons.collections.comparators; import java.io.Serializable; import java.util.Comparator; +import org.apache.commons.collections.ComparatorUtils; + /** * A Comparator that will compare nulls to be either lower or higher than * other objects. @@ -28,7 +30,7 @@ import java.util.Comparator; * * @author Michael A. Smith */ -public class NullComparator implements Comparator, Serializable { +public class NullComparator implements Comparator, Serializable { /** Serialization version. */ private static final long serialVersionUID = -5820772575483504339L; @@ -36,7 +38,7 @@ public class NullComparator implements Comparator, Serializable { /** * The comparator to use when comparing two non-null objects. **/ - private Comparator nonNullComparator; + private Comparator nonNullComparator; /** * Specifies whether a null are compared as higher than @@ -51,8 +53,9 @@ public class NullComparator implements Comparator, Serializable { * non-null objects, the {@link ComparableComparator} is * used. **/ + @SuppressWarnings("unchecked") public NullComparator() { - this(ComparableComparator.getInstance(), true); + this(ComparatorUtils.NATURAL_COMPARATOR, true); } /** @@ -68,7 +71,7 @@ public class NullComparator implements Comparator, Serializable { * @exception NullPointerException if nonNullComparator is * null **/ - public NullComparator(Comparator nonNullComparator) { + public NullComparator(Comparator nonNullComparator) { this(nonNullComparator, true); } @@ -84,8 +87,9 @@ public class NullComparator implements Comparator, Serializable { * that null should be compared as lower than a * non-null object. **/ + @SuppressWarnings("unchecked") public NullComparator(boolean nullsAreHigh) { - this(ComparableComparator.getInstance(), nullsAreHigh); + this(ComparatorUtils.NATURAL_COMPARATOR, nullsAreHigh); } /** @@ -107,11 +111,11 @@ public class NullComparator implements Comparator, Serializable { * @exception NullPointerException if nonNullComparator is * null **/ - public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) { + public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) { this.nonNullComparator = nonNullComparator; this.nullsAreHigh = nullsAreHigh; - if(nonNullComparator == null) { + if (nonNullComparator == null) { throw new NullPointerException("null nonNullComparator"); } } @@ -133,7 +137,7 @@ public class NullComparator implements Comparator, Serializable { * "higher" than (greater than, after, etc.) o2; or * 0 if o1 and o2 are equal. **/ - public int compare(Object o1, Object o2) { + public int compare(E o1, E o2) { if(o1 == o2) { return 0; } if(o1 == null) { return (this.nullsAreHigh ? 1 : -1); } if(o2 == null) { return (this.nullsAreHigh ? -1 : 1); } @@ -167,8 +171,8 @@ public class NullComparator implements Comparator, Serializable { if(obj == this) { return true; } if(!obj.getClass().equals(this.getClass())) { return false; } - NullComparator other = (NullComparator)obj; - + NullComparator other = (NullComparator) obj; + return ((this.nullsAreHigh == other.nullsAreHigh) && (this.nonNullComparator.equals(other.nonNullComparator))); } diff --git a/src/java/org/apache/commons/collections/iterators/ArrayIterator.java b/src/java/org/apache/commons/collections/iterators/ArrayIterator.java index d14a69d12..e912d6a61 100644 --- a/src/java/org/apache/commons/collections/iterators/ArrayIterator.java +++ b/src/java/org/apache/commons/collections/iterators/ArrayIterator.java @@ -41,7 +41,7 @@ import org.apache.commons.collections.ResettableIterator; * @author Neil O'Toole * @author Stephen Colebourne */ -public class ArrayIterator implements ResettableIterator { +public class ArrayIterator implements ResettableIterator { /** The array to iterate over */ protected Object array; @@ -159,11 +159,12 @@ public class ArrayIterator implements ResettableIterator { * @throws NoSuchElementException if all the elements in the array * have already been returned */ - public Object next() { + @SuppressWarnings("unchecked") + public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } - return Array.get(array, index++); + return (E) Array.get(array, index++); } /** diff --git a/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java b/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java index 929a278fd..8a2d9f674 100644 --- a/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java +++ b/src/java/org/apache/commons/collections/iterators/ArrayListIterator.java @@ -44,8 +44,8 @@ import org.apache.commons.collections.ResettableListIterator; * @author Stephen Colebourne * @author Phil Steitz */ -public class ArrayListIterator extends ArrayIterator - implements ListIterator, ResettableListIterator { +public class ArrayListIterator extends ArrayIterator + implements ListIterator, ResettableListIterator { /** * Holds the index of the last item returned by a call to next() @@ -129,12 +129,13 @@ public class ArrayListIterator extends ArrayIterator * @return the previous element * @throws NoSuchElementException if there is no previous element */ - public Object previous() { + @SuppressWarnings("unchecked") + public E previous() { if (hasPrevious() == false) { throw new NoSuchElementException(); } this.lastItemIndex = --this.index; - return Array.get(this.array, this.index); + return (E) Array.get(this.array, this.index); } /** @@ -143,12 +144,13 @@ public class ArrayListIterator extends ArrayIterator * @return the next element * @throws NoSuchElementException if there is no next element */ - public Object next() { + @SuppressWarnings("unchecked") + public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } this.lastItemIndex = this.index; - return Array.get(this.array, this.index++); + return (E) Array.get(this.array, this.index++); } /** diff --git a/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java b/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java index 910d9cbb5..1c8fe3925 100644 --- a/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java +++ b/src/java/org/apache/commons/collections/iterators/ObjectArrayListIterator.java @@ -41,8 +41,8 @@ import org.apache.commons.collections.ResettableListIterator; * @author Stephen Colebourne * @author Phil Steitz */ -public class ObjectArrayListIterator extends ObjectArrayIterator - implements ListIterator, ResettableListIterator { +public class ObjectArrayListIterator extends ObjectArrayIterator + implements ListIterator, ResettableListIterator { /** * Holds the index of the last item returned by a call to next() @@ -69,7 +69,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @param array the array to iterate over * @throws NullPointerException if array is null */ - public ObjectArrayListIterator(Object[] array) { + public ObjectArrayListIterator(E[] array) { super(array); } @@ -82,7 +82,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @throws NullPointerException if array is null * @throws IndexOutOfBoundsException if the start index is out of bounds */ - public ObjectArrayListIterator(Object[] array, int start) { + public ObjectArrayListIterator(E[] array, int start) { super(array, start); } @@ -97,7 +97,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @throws IllegalArgumentException if end index is before the start * @throws NullPointerException if array is null */ - public ObjectArrayListIterator(Object[] array, int start, int end) { + public ObjectArrayListIterator(E[] array, int start, int end) { super(array, start, end); } @@ -119,7 +119,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @return the previous element * @throws NoSuchElementException if there is no previous element */ - public Object previous() { + public E previous() { if (hasPrevious() == false) { throw new NoSuchElementException(); } @@ -133,7 +133,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @return the next element * @throws NoSuchElementException if there is no next element */ - public Object next() { + public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } @@ -166,7 +166,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @param obj the object to add * @throws UnsupportedOperationException always thrown. */ - public void add(Object obj) { + public void add(E obj) { throw new UnsupportedOperationException("add() method is not supported"); } @@ -187,7 +187,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * @throws IllegalStateException if next() has not yet been called. * @throws ClassCastException if the object type is unsuitable for the array */ - public void set(Object obj) { + public void set(E obj) { if (this.lastItemIndex == -1) { throw new IllegalStateException("must call next() or previous() before a call to set()"); } diff --git a/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java b/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java index e94bb248b..c275cf17e 100644 --- a/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java +++ b/src/java/org/apache/commons/collections/iterators/ObjectGraphIterator.java @@ -75,23 +75,23 @@ import org.apache.commons.collections.Transformer; * * @author Stephen Colebourne */ -public class ObjectGraphIterator implements Iterator { +public class ObjectGraphIterator implements Iterator { /** The stack of iterators */ - protected final ArrayStack stack = new ArrayStack(8); + protected final ArrayStack> stack = new ArrayStack>(8); /** The root object in the tree */ - protected Object root; + protected E root; /** The transformer to use */ - protected Transformer transformer; + protected Transformer transformer; /** Whether there is another element in the iteration */ - protected boolean hasNext = false; + protected boolean hasNext = false; /** The current iterator */ - protected Iterator currentIterator; + protected Iterator currentIterator; /** The current value */ - protected Object currentValue; + protected E currentValue; /** The last used iterator, needed for remove() */ - protected Iterator lastUsedIterator; + protected Iterator lastUsedIterator; //----------------------------------------------------------------------- /** @@ -103,10 +103,11 @@ public class ObjectGraphIterator implements Iterator { * @param root the root object, null will result in an empty iterator * @param transformer the transformer to use, null will use a no effect transformer */ - public ObjectGraphIterator(Object root, Transformer transformer) { + @SuppressWarnings("unchecked") + public ObjectGraphIterator(E root, Transformer transformer) { super(); if (root instanceof Iterator) { - this.currentIterator = (Iterator) root; + this.currentIterator = (Iterator) root; } else { this.root = root; } @@ -123,7 +124,7 @@ public class ObjectGraphIterator implements Iterator { * * @param rootIterator the root iterator, null will result in an empty iterator */ - public ObjectGraphIterator(Iterator rootIterator) { + public ObjectGraphIterator(Iterator rootIterator) { super(); this.currentIterator = rootIterator; this.transformer = null; @@ -158,10 +159,11 @@ public class ObjectGraphIterator implements Iterator { * * @param value the value to start from */ - protected void findNext(Object value) { + @SuppressWarnings("unchecked") + protected void findNext(E value) { if (value instanceof Iterator) { // need to examine this iterator - findNextByIterator((Iterator) value); + findNextByIterator((Iterator) value); } else { // next value found currentValue = value; @@ -174,7 +176,7 @@ public class ObjectGraphIterator implements Iterator { * * @param iterator the iterator to start from */ - protected void findNextByIterator(Iterator iterator) { + protected void findNextByIterator(Iterator iterator) { if (iterator != currentIterator) { // recurse a level if (currentIterator != null) { @@ -184,7 +186,7 @@ public class ObjectGraphIterator implements Iterator { } while (currentIterator.hasNext() && hasNext == false) { - Object next = currentIterator.next(); + E next = currentIterator.next(); if (transformer != null) { next = transformer.transform(next); } @@ -196,7 +198,7 @@ public class ObjectGraphIterator implements Iterator { // all iterators exhausted } else { // current iterator exhausted, go up a level - currentIterator = (Iterator) stack.pop(); + currentIterator = stack.pop(); findNextByIterator(currentIterator); } } @@ -218,13 +220,13 @@ public class ObjectGraphIterator implements Iterator { * @return the next element from the iteration * @throws NoSuchElementException if all the Iterators are exhausted */ - public Object next() { + public E next() { updateCurrentIterator(); if (hasNext == false) { throw new NoSuchElementException("No more elements in the iteration"); } lastUsedIterator = currentIterator; - Object result = currentValue; + E result = currentValue; currentValue = null; hasNext = false; return result; diff --git a/src/java/org/apache/commons/collections/iterators/SingletonIterator.java b/src/java/org/apache/commons/collections/iterators/SingletonIterator.java index 5e4671d7d..cb565fe50 100644 --- a/src/java/org/apache/commons/collections/iterators/SingletonIterator.java +++ b/src/java/org/apache/commons/collections/iterators/SingletonIterator.java @@ -32,8 +32,8 @@ import org.apache.commons.collections.ResettableIterator; * @author Stephen Colebourne * @author Rodney Waldhoff */ -public class SingletonIterator - implements Iterator, ResettableIterator { +public class SingletonIterator + implements Iterator, ResettableIterator { /** Whether remove is allowed */ private final boolean removeAllowed; @@ -42,7 +42,7 @@ public class SingletonIterator /** Has the element been removed */ private boolean removed = false; /** The object */ - private Object object; + private E object; /** * Constructs a new SingletonIterator where remove @@ -50,7 +50,7 @@ public class SingletonIterator * * @param object the single object to return from the iterator */ - public SingletonIterator(Object object) { + public SingletonIterator(E object) { this(object, true); } @@ -62,7 +62,7 @@ public class SingletonIterator * @param removeAllowed true if remove is allowed * @since Commons Collections 3.1 */ - public SingletonIterator(Object object, boolean removeAllowed) { + public SingletonIterator(E object, boolean removeAllowed) { super(); this.object = object; this.removeAllowed = removeAllowed; @@ -89,7 +89,7 @@ public class SingletonIterator * @throws NoSuchElementException if the single object has already * been returned */ - public Object next() { + public E next() { if (!beforeFirst || removed) { throw new NoSuchElementException(); } diff --git a/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java b/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java index b47e86554..2d825c9d1 100644 --- a/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java +++ b/src/test/org/apache/commons/collections/comparators/AbstractTestComparator.java @@ -34,7 +34,7 @@ import org.apache.commons.collections.AbstractTestObject; * * @author Stephen Colebourne */ -public abstract class AbstractTestComparator extends AbstractTestObject { +public abstract class AbstractTestComparator extends AbstractTestObject { /** * JUnit constructor. @@ -46,19 +46,13 @@ public abstract class AbstractTestComparator extends AbstractTestObject { } //----------------------------------------------------------------------- - /** - * Implement this method to return the comparator to test. - * - * @return the comparator to test - */ - public abstract Comparator makeComparator(); /** * Implement this method to return a list of sorted objects. * * @return sorted objects */ - public abstract List getComparableObjectsOrdered(); + public abstract List getComparableObjectsOrdered(); //----------------------------------------------------------------------- /** @@ -66,9 +60,7 @@ public abstract class AbstractTestComparator extends AbstractTestObject { * * @return a full iterator */ - public Object makeObject() { - return makeComparator(); - } + public abstract Comparator makeObject(); /** * Overrides superclass to block tests. @@ -96,23 +88,22 @@ public abstract class AbstractTestComparator extends AbstractTestObject { /** * Reverse the list. */ - protected void reverseObjects(List list) { + protected void reverseObjects(List list) { Collections.reverse(list); } /** * Randomize the list. */ - protected void randomizeObjects(List list) { + protected void randomizeObjects(List list) { Collections.shuffle(list); } /** * Sort the list. */ - protected void sortObjects(List list, Comparator comparator) { - Collections.sort(list,comparator); - + protected void sortObjects(List list, Comparator comparator) { + Collections.sort(list, comparator); } //----------------------------------------------------------------------- @@ -120,43 +111,41 @@ public abstract class AbstractTestComparator extends AbstractTestObject { * Test sorting an empty list */ public void testEmptyListSort() { - List list = new LinkedList(); - sortObjects(list, makeComparator()); + List list = new LinkedList(); + sortObjects(list, makeObject()); - List list2 = new LinkedList(); - - assertTrue("Comparator cannot sort empty lists", - list2.equals(list)); + List list2 = new LinkedList(); + + assertTrue("Comparator cannot sort empty lists", list2.equals(list)); } /** * Test sorting a reversed list. */ public void testReverseListSort() { - Comparator comparator = makeComparator(); + Comparator comparator = makeObject(); - List randomList = getComparableObjectsOrdered(); + List randomList = getComparableObjectsOrdered(); reverseObjects(randomList); - sortObjects(randomList,comparator); + sortObjects(randomList, comparator); - List orderedList = getComparableObjectsOrdered(); + List orderedList = getComparableObjectsOrdered(); assertTrue("Comparator did not reorder the List correctly", orderedList.equals(randomList)); - } /** * Test sorting a random list. */ public void testRandomListSort() { - Comparator comparator = makeComparator(); + Comparator comparator = makeObject(); - List randomList = getComparableObjectsOrdered(); + List randomList = getComparableObjectsOrdered(); randomizeObjects(randomList); sortObjects(randomList,comparator); - List orderedList = getComparableObjectsOrdered(); + List orderedList = getComparableObjectsOrdered(); /* debug Iterator i = randomList.iterator(); @@ -174,7 +163,7 @@ public abstract class AbstractTestComparator extends AbstractTestObject { * Nearly all Comparators should be Serializable. */ public void testComparatorIsSerializable() { - Comparator comparator = makeComparator(); + Comparator comparator = makeObject(); assertTrue("This comparator should be Serializable.", comparator instanceof Serializable); } @@ -195,37 +184,38 @@ public abstract class AbstractTestComparator extends AbstractTestObject { * Compare the current serialized form of the Comparator * against the canonical version in SVN. */ + @SuppressWarnings("unchecked") public void testComparatorCompatibility() throws IOException, ClassNotFoundException { - if(!skipSerializedCanonicalTests()) { - Comparator comparator = null; + if (!skipSerializedCanonicalTests()) { + Comparator comparator = null; // test to make sure the canonical form has been preserved try { - comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeComparator())); + comparator = (Comparator) readExternalFormFromDisk(getCanonicalComparatorName(makeObject())); } catch (FileNotFoundException exception) { boolean autoCreateSerialized = false; - if(autoCreateSerialized) { - comparator = makeComparator(); + if (autoCreateSerialized) { + comparator = makeObject(); String fileName = getCanonicalComparatorName(comparator); writeExternalFormToDisk((Serializable) comparator, fileName); - fail("Serialized form could not be found. A serialized version " + - "has now been written (and should be added to SVN): " + fileName); + fail("Serialized form could not be found. A serialized version " + + "has now been written (and should be added to CVS): " + fileName); } else { - fail("The Serialized form could be located to test serialization " + - "compatibility: " + exception.getMessage()); + fail("The Serialized form could be located to test serialization " + + "compatibility: " + exception.getMessage()); } } // make sure the canonical form produces the ordering we currently // expect - List randomList = getComparableObjectsOrdered(); + List randomList = getComparableObjectsOrdered(); reverseObjects(randomList); - sortObjects(randomList,comparator); + sortObjects(randomList, comparator); - List orderedList = getComparableObjectsOrdered(); + List orderedList = getComparableObjectsOrdered(); assertTrue("Comparator did not reorder the List correctly", orderedList.equals(randomList)); diff --git a/src/test/org/apache/commons/collections/comparators/TestNullComparator.java b/src/test/org/apache/commons/collections/comparators/TestNullComparator.java index e040c687f..14ffe7712 100644 --- a/src/test/org/apache/commons/collections/comparators/TestNullComparator.java +++ b/src/test/org/apache/commons/collections/comparators/TestNullComparator.java @@ -30,7 +30,7 @@ import junit.framework.TestSuite; * * @author Michael A. Smith */ -public abstract class TestNullComparator extends AbstractTestComparator { +public abstract class TestNullComparator extends AbstractTestComparator { public TestNullComparator(String testName) { super(testName); @@ -52,12 +52,12 @@ public abstract class TestNullComparator extends AbstractTestComparator { super(testName); } - public Comparator makeComparator() { - return new NullComparator(); + public Comparator makeObject() { + return new NullComparator(); } - - public List getComparableObjectsOrdered() { - List list = new LinkedList(); + + public List getComparableObjectsOrdered() { + List list = new LinkedList(); list.add(new Integer(1)); list.add(new Integer(2)); list.add(new Integer(3)); @@ -76,17 +76,17 @@ public abstract class TestNullComparator extends AbstractTestComparator { * Test the NullComparator with nulls low using the comparable comparator **/ public static class TestNullComparator2 extends TestNullComparator { - + public TestNullComparator2(String testName) { super(testName); } - - public Comparator makeComparator() { - return new NullComparator(false); + + public Comparator makeObject() { + return new NullComparator(false); } - - public List getComparableObjectsOrdered() { - List list = new LinkedList(); + + public List getComparableObjectsOrdered() { + List list = new LinkedList(); list.add(null); list.add(new Integer(1)); list.add(new Integer(2)); @@ -95,7 +95,7 @@ public abstract class TestNullComparator extends AbstractTestComparator { list.add(new Integer(5)); return list; } - + public String getCanonicalComparatorName(Object object) { return super.getCanonicalComparatorName(object) + "2"; } diff --git a/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java b/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java index 68ca6396e..455b8bacc 100644 --- a/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java +++ b/src/test/org/apache/commons/collections/iterators/TestSingletonListIterator.java @@ -31,7 +31,7 @@ import org.apache.commons.collections.ResettableListIterator; * * @author Stephen Colebourne */ -public class TestSingletonListIterator extends AbstractTestListIterator { +public class TestSingletonListIterator extends AbstractTestListIterator { private static final Object testValue = "foo"; @@ -47,16 +47,17 @@ public class TestSingletonListIterator extends AbstractTestListIterator { * Returns a SingletonListIterator from which * the element has already been removed. */ - public ListIterator makeEmptyListIterator() { - SingletonListIterator iter = (SingletonListIterator)makeFullIterator(); + public SingletonListIterator makeEmptyIterator() { + SingletonListIterator iter = makeObject(); iter.next(); iter.remove(); iter.reset(); return iter; } - public ListIterator makeFullListIterator() { - return new SingletonListIterator( testValue ); + @SuppressWarnings("unchecked") + public SingletonListIterator makeObject() { + return new SingletonListIterator((E) testValue); } public boolean supportsAdd() { @@ -72,7 +73,7 @@ public class TestSingletonListIterator extends AbstractTestListIterator { } public void testIterator() { - ListIterator iter = (ListIterator) makeObject(); + ListIterator iter = makeObject(); assertTrue( "Iterator should have next item", iter.hasNext() ); assertTrue( "Iterator should have no previous item", !iter.hasPrevious() ); assertEquals( "Iteration next index", 0, iter.nextIndex() ); @@ -118,7 +119,7 @@ public class TestSingletonListIterator extends AbstractTestListIterator { } public void testReset() { - ResettableListIterator it = (ResettableListIterator) makeObject(); + ResettableListIterator it = makeObject(); assertEquals(true, it.hasNext()); assertEquals(false, it.hasPrevious()); diff --git a/src/test/org/apache/commons/collections/list/TestTreeList.java b/src/test/org/apache/commons/collections/list/TestTreeList.java index 46ec9a110..9d950acd8 100644 --- a/src/test/org/apache/commons/collections/list/TestTreeList.java +++ b/src/test/org/apache/commons/collections/list/TestTreeList.java @@ -31,8 +31,8 @@ import org.apache.commons.collections.BulkTest; * * @author Joerg Schmuecker */ -public class TestTreeList extends AbstractTestList { - +public class TestTreeList extends AbstractTestList { + public TestTreeList(String name) { super(name); } @@ -53,49 +53,49 @@ public class TestTreeList extends AbstractTestList { return BulkTest.makeSuite(TestTreeList.class); } - public static void benchmark(List l) { + public static void benchmark(List l) { long start = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { l.add(new Integer(i)); } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 200; i++) { l.toArray(); } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 100; i++) { - java.util.Iterator it = l.iterator(); + java.util.Iterator it = l.iterator(); while (it.hasNext()) { it.next(); } } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { int j = (int) (Math.random() * 100000); l.add(j, new Integer(-j)); } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 50000; i++) { int j = (int) (Math.random() * 110000); l.get(j); } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 200; i++) { int j = (int) (Math.random() * 100000); l.indexOf(new Integer(j)); } System.out.print(System.currentTimeMillis() - start + ";"); - + start = System.currentTimeMillis(); for (int i = 0; i < 10000; i++) { int j = (int) (Math.random() * 100000); @@ -105,18 +105,19 @@ public class TestTreeList extends AbstractTestList { } //----------------------------------------------------------------------- - public List makeEmptyList() { - return new TreeList(); + public TreeList makeObject() { + return new TreeList(); } //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") public void testAddMultiple() { - List l = makeEmptyList(); - l.add("hugo"); - l.add("erna"); - l.add("daniel"); - l.add("andres"); - l.add("harald"); + List l = makeObject(); + l.add((E) "hugo"); + l.add((E) "erna"); + l.add((E) "daniel"); + l.add((E) "andres"); + l.add((E) "harald"); l.add(0, null); assertEquals(null, l.get(0)); assertEquals("hugo", l.get(1)); @@ -126,13 +127,14 @@ public class TestTreeList extends AbstractTestList { assertEquals("harald", l.get(5)); } + @SuppressWarnings("unchecked") public void testRemove() { - List l = makeEmptyList(); - l.add("hugo"); - l.add("erna"); - l.add("daniel"); - l.add("andres"); - l.add("harald"); + List l = makeObject(); + l.add((E) "hugo"); + l.add((E) "erna"); + l.add((E) "daniel"); + l.add((E) "andres"); + l.add((E) "harald"); l.add(0, null); int i = 0; assertEquals(null, l.get(i++)); @@ -164,23 +166,25 @@ public class TestTreeList extends AbstractTestList { assertEquals("harald", l.get(i++)); } + @SuppressWarnings("unchecked") public void testInsertBefore() { - List l = makeEmptyList(); - l.add("erna"); - l.add(0, "hugo"); + List l = makeObject(); + l.add((E) "erna"); + l.add(0, (E) "hugo"); assertEquals("hugo", l.get(0)); assertEquals("erna", l.get(1)); } + @SuppressWarnings("unchecked") public void testIndexOf() { - List l = makeEmptyList(); - l.add("0"); - l.add("1"); - l.add("2"); - l.add("3"); - l.add("4"); - l.add("5"); - l.add("6"); + List l = makeObject(); + l.add((E) "0"); + l.add((E) "1"); + l.add((E) "2"); + l.add((E) "3"); + l.add((E) "4"); + l.add((E) "5"); + l.add((E) "6"); assertEquals(0, l.indexOf("0")); assertEquals(1, l.indexOf("1")); assertEquals(2, l.indexOf("2")); @@ -188,17 +192,17 @@ public class TestTreeList extends AbstractTestList { assertEquals(4, l.indexOf("4")); assertEquals(5, l.indexOf("5")); assertEquals(6, l.indexOf("6")); - - l.set(1, "0"); + + l.set(1, (E) "0"); assertEquals(0, l.indexOf("0")); - - l.set(3, "3"); + + l.set(3, (E) "3"); assertEquals(3, l.indexOf("3")); - l.set(2, "3"); + l.set(2, (E) "3"); assertEquals(2, l.indexOf("3")); - l.set(1, "3"); + l.set(1, (E) "3"); assertEquals(1, l.indexOf("3")); - l.set(0, "3"); + l.set(0, (E) "3"); assertEquals(0, l.indexOf("3")); } @@ -214,18 +218,18 @@ public class TestTreeList extends AbstractTestList { public void testBug35258() { Object objectToRemove = new Integer(3); - - List treelist = new TreeList(); + + List treelist = new TreeList(); treelist.add(new Integer(0)); treelist.add(new Integer(1)); treelist.add(new Integer(2)); treelist.add(new Integer(3)); treelist.add(new Integer(4)); - + // this cause inconsistence of ListIterator() treelist.remove(objectToRemove); - - ListIterator li = treelist.listIterator(); + + ListIterator li = treelist.listIterator(); assertEquals(new Integer(0), li.next()); assertEquals(new Integer(0), li.previous()); assertEquals(new Integer(0), li.next());