From 884baf0ddc6b869d9d4340b6fc9b1ff4d018e7c2 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Thu, 29 Jan 2009 18:48:37 +0000 Subject: [PATCH] finish generics (minus one class) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/branches/collections_jdk5_branch@738956 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/collections/ArrayStack.java | 14 +- .../apache/commons/collections/BagUtils.java | 190 +- .../apache/commons/collections/BidiMap.java | 4 +- .../collections/BoundedCollection.java | 2 +- .../commons/collections/BoundedMap.java | 2 +- .../collections/BufferOverflowException.java | 3 + .../collections/BufferUnderflowException.java | 3 + .../commons/collections/BufferUtils.java | 27 +- .../commons/collections/ClosureUtils.java | 73 +- .../commons/collections/CollectionUtils.java | 96 +- .../commons/collections/ComparatorUtils.java | 48 +- .../commons/collections/EnumerationUtils.java | 19 +- .../commons/collections/FactoryUtils.java | 14 +- .../commons/collections/FunctorException.java | 7 +- .../commons/collections/IteratorUtils.java | 257 +-- .../apache/commons/collections/ListUtils.java | 49 +- .../apache/commons/collections/MapUtils.java | 290 +-- .../apache/commons/collections/MultiMap.java | 12 +- .../commons/collections/OrderedBidiMap.java | 16 +- .../commons/collections/OrderedMap.java | 2 +- .../commons/collections/PredicateUtils.java | 221 ++- .../apache/commons/collections/SetUtils.java | 35 +- .../commons/collections/SortedBidiMap.java | 21 +- .../commons/collections/TransformerUtils.java | 102 +- .../collections/bag/AbstractBagDecorator.java | 3 + .../collections/bag/AbstractMapBag.java | 275 +-- .../bag/AbstractSortedBagDecorator.java | 3 + .../commons/collections/bag/HashBag.java | 10 +- .../collections/bag/SynchronizedBag.java | 3 + .../bag/SynchronizedSortedBag.java | 4 +- .../collections/bag/TransformedBag.java | 25 +- .../collections/bag/TransformedSortedBag.java | 20 +- .../commons/collections/bag/TreeBag.java | 60 +- .../collections/bag/UnmodifiableBag.java | 33 +- .../bag/UnmodifiableSortedBag.java | 7 +- .../bidimap/AbstractBidiMapDecorator.java | 29 +- .../bidimap/AbstractDualBidiMap.java | 436 ++--- .../AbstractOrderedBidiMapDecorator.java | 39 +- .../AbstractSortedBidiMapDecorator.java | 38 +- .../collections/bidimap/DualHashBidiMap.java | 22 +- .../collections/bidimap/DualTreeBidiMap.java | 248 +-- .../collections/bidimap/TreeBidiMap.java | 1595 +++++++++-------- .../bidimap/UnmodifiableBidiMap.java | 54 +- .../bidimap/UnmodifiableOrderedBidiMap.java | 62 +- .../bidimap/UnmodifiableSortedBidiMap.java | 79 +- .../buffer/AbstractBufferDecorator.java | 8 +- .../collections/buffer/BoundedBuffer.java | 26 +- .../collections/buffer/BoundedFifoBuffer.java | 72 +- .../buffer/CircularFifoBuffer.java | 24 +- .../collections/buffer/PriorityBuffer.java | 71 +- .../collections/buffer/TransformedBuffer.java | 16 +- .../buffer/UnboundedFifoBuffer.java | 49 +- .../buffer/UnmodifiableBuffer.java | 23 +- .../AbstractUntypedCollectionDecorator.java | 125 ++ .../collection/CompositeCollection.java | 55 +- .../collection/TransformedCollection.java | 22 +- .../UnmodifiableBoundedCollection.java | 76 +- .../comparators/BooleanComparator.java | 18 +- .../comparators/ComparableComparator.java | 14 +- .../comparators/ComparatorChain.java | 124 +- .../comparators/FixedOrderComparator.java | 149 +- .../comparators/NullComparator.java | 22 +- .../comparators/ReverseComparator.java | 32 +- .../comparators/TransformingComparator.java | 20 +- .../collections/functors/AllPredicate.java | 8 +- .../collections/functors/AndPredicate.java | 35 +- .../collections/functors/AnyPredicate.java | 44 +- .../collections/functors/ChainedClosure.java | 39 +- .../functors/ChainedTransformer.java | 37 +- .../functors/CloneTransformer.java | 11 +- .../functors/ClosureTransformer.java | 14 +- .../collections/functors/ConstantFactory.java | 19 +- .../functors/ConstantTransformer.java | 55 +- .../collections/functors/EqualPredicate.java | 2 +- .../functors/ExceptionClosure.java | 12 +- .../functors/ExceptionFactory.java | 12 +- .../functors/ExceptionPredicate.java | 25 +- .../functors/ExceptionTransformer.java | 22 +- .../functors/FactoryTransformer.java | 14 +- .../collections/functors/FalsePredicate.java | 36 +- .../collections/functors/ForClosure.java | 19 +- .../collections/functors/FunctorUtils.java | 96 +- .../functors/IdentityPredicate.java | 33 +- .../collections/functors/IfClosure.java | 30 +- .../functors/InstanceofPredicate.java | 26 +- .../functors/InstantiateFactory.java | 7 +- .../functors/InstantiateTransformer.java | 47 +- .../functors/InvokerTransformer.java | 24 +- .../collections/functors/MapTransformer.java | 32 +- .../collections/functors/NOPClosure.java | 26 +- .../collections/functors/NOPTransformer.java | 11 +- .../collections/functors/NonePredicate.java | 38 +- .../functors/NotNullPredicate.java | 11 +- .../collections/functors/NotPredicate.java | 15 +- .../functors/NullIsExceptionPredicate.java | 17 +- .../functors/NullIsFalsePredicate.java | 35 +- .../functors/NullIsTruePredicate.java | 17 +- .../collections/functors/OnePredicate.java | 25 +- .../collections/functors/OrPredicate.java | 35 +- .../functors/PredicateTransformer.java | 18 +- .../functors/PrototypeFactory.java | 40 +- .../functors/StringValueTransformer.java | 11 +- .../collections/functors/SwitchClosure.java | 88 +- .../functors/SwitchTransformer.java | 58 +- .../functors/TransformedPredicate.java | 42 +- .../functors/TransformerClosure.java | 16 +- .../functors/TransformerPredicate.java | 41 +- .../collections/functors/UniquePredicate.java | 24 +- .../collections/functors/WhileClosure.java | 18 +- .../iterators/AbstractEmptyIterator.java | 22 +- .../iterators/AbstractEmptyMapIterator.java | 50 + .../iterators/AbstractIteratorDecorator.java | 37 +- .../AbstractMapIteratorDecorator.java | 16 +- .../AbstractOrderedMapIteratorDecorator.java | 18 +- .../AbstractUntypedIteratorDecorator.java | 54 + .../collections/iterators/ArrayIterator.java | 7 +- .../iterators/ArrayListIterator.java | 14 +- .../iterators/CollatingIterator.java | 230 +-- .../collections/iterators/EmptyIterator.java | 27 +- .../iterators/EmptyListIterator.java | 41 +- .../iterators/EmptyMapIterator.java | 16 +- .../iterators/EmptyOrderedIterator.java | 14 +- .../iterators/EmptyOrderedMapIterator.java | 16 +- .../iterators/EntrySetMapIterator.java | 23 +- .../iterators/EnumerationIterator.java | 20 +- .../collections/iterators/FilterIterator.java | 30 +- .../iterators/FilterListIterator.java | 82 +- .../collections/iterators/IteratorChain.java | 196 +- .../iterators/IteratorEnumeration.java | 66 +- .../iterators/ListIteratorWrapper.java | 18 +- .../iterators/LoopingIterator.java | 10 +- .../iterators/LoopingListIterator.java | 27 +- .../iterators/ObjectArrayIterator.java | 18 +- .../iterators/ObjectArrayListIterator.java | 18 +- .../iterators/ObjectGraphIterator.java | 38 +- .../iterators/ReverseListIterator.java | 20 +- .../iterators/SingletonIterator.java | 12 +- .../iterators/SingletonListIterator.java | 14 +- .../iterators/TransformIterator.java | 31 +- .../iterators/UniqueFilterIterator.java | 16 +- .../iterators/UnmodifiableIterator.java | 14 +- .../iterators/UnmodifiableListIterator.java | 18 +- .../iterators/UnmodifiableMapIterator.java | 20 +- .../UnmodifiableOrderedMapIterator.java | 31 +- .../keyvalue/AbstractKeyValue.java | 12 +- .../keyvalue/AbstractMapEntry.java | 9 +- .../keyvalue/AbstractMapEntryDecorator.java | 14 +- .../collections/keyvalue/DefaultKeyValue.java | 21 +- .../collections/keyvalue/DefaultMapEntry.java | 8 +- .../collections/keyvalue/MultiKey.java | 60 +- .../collections/keyvalue/TiedMapEntry.java | 16 +- .../keyvalue/UnmodifiableMapEntry.java | 10 +- .../collections/list/AbstractLinkedList.java | 331 ++-- .../list/AbstractListDecorator.java | 8 +- .../AbstractSerializableListDecorator.java | 9 +- .../list/CursorableLinkedList.java | 99 +- .../collections/list/FixedSizeList.java | 46 +- .../commons/collections/list/GrowthList.java | 24 +- .../commons/collections/list/LazyList.java | 41 +- .../list/NodeCachingLinkedList.java | 29 +- .../collections/list/SetUniqueList.java | 169 +- .../collections/list/SynchronizedList.java | 4 +- .../collections/list/TransformedList.java | 46 +- .../commons/collections/list/TreeList.java | 203 ++- .../collections/list/UnmodifiableList.java | 37 +- .../collections/map/AbstractHashedMap.java | 492 ++--- .../map/AbstractInputCheckedMapDecorator.java | 56 +- .../collections/map/AbstractLinkedMap.java | 227 ++- .../map/AbstractOrderedMapDecorator.java | 26 +- .../collections/map/AbstractReferenceMap.java | 433 ++--- .../map/AbstractSortedMapDecorator.java | 5 +- .../collections/map/CaseInsensitiveMap.java | 11 +- .../commons/collections/map/CompositeMap.java | 145 +- .../commons/collections/map/DefaultedMap.java | 52 +- .../commons/collections/map/FixedSizeMap.java | 38 +- .../collections/map/FixedSizeSortedMap.java | 61 +- .../commons/collections/map/Flat3Map.java | 314 ++-- .../commons/collections/map/HashedMap.java | 28 +- .../commons/collections/map/IdentityMap.java | 58 +- .../commons/collections/map/LRUMap.java | 80 +- .../commons/collections/map/LazyMap.java | 4 +- .../commons/collections/map/LinkedMap.java | 83 +- .../collections/map/ListOrderedMap.java | 237 ++- .../commons/collections/map/MultiKeyMap.java | 292 ++- .../collections/map/MultiValueMap.java | 134 +- .../collections/map/PredicatedMap.java | 42 +- .../collections/map/PredicatedSortedMap.java | 40 +- .../collections/map/ReferenceIdentityMap.java | 23 +- .../commons/collections/map/ReferenceMap.java | 16 +- .../commons/collections/map/SingletonMap.java | 126 +- .../collections/map/StaticBucketMap.java | 127 +- .../collections/map/TransformedMap.java | 50 +- .../collections/map/TransformedSortedMap.java | 52 +- .../collections/map/UnmodifiableEntrySet.java | 56 +- .../collections/map/UnmodifiableMap.java | 42 +- .../map/UnmodifiableOrderedMap.java | 41 +- .../map/UnmodifiableSortedMap.java | 57 +- .../set/AbstractSerializableSetDecorator.java | 9 +- .../collections/set/AbstractSetDecorator.java | 8 +- .../set/AbstractSortedSetDecorator.java | 3 + .../commons/collections/set/CompositeSet.java | 93 +- .../collections/set/ListOrderedSet.java | 139 +- .../commons/collections/set/MapBackedSet.java | 34 +- .../collections/set/SynchronizedSet.java | 4 +- .../set/SynchronizedSortedSet.java | 30 +- .../collections/set/TransformedSet.java | 8 +- .../collections/set/TransformedSortedSet.java | 36 +- .../collections/set/UnmodifiableSet.java | 22 +- .../set/UnmodifiableSortedSet.java | 11 +- .../collections/AbstractTestObject.java | 2 +- .../apache/commons/collections/BulkTest.java | 24 +- .../commons/collections/LocalTestNode.java | 30 +- .../commons/collections/MapPerformance.java | 34 +- .../commons/collections/MockTestCase.java | 7 +- .../commons/collections/TestArrayList.java | 29 +- .../commons/collections/TestArrayStack.java | 28 +- .../commons/collections/TestBagUtils.java | 85 +- .../commons/collections/TestBufferUtils.java | 6 +- .../commons/collections/TestClosureUtils.java | 265 +-- .../collections/TestCollectionUtils.java | 91 +- .../collections/TestEnumerationUtils.java | 18 +- .../commons/collections/TestFactoryUtils.java | 35 +- .../collections/TestIteratorUtils.java | 179 +- .../commons/collections/TestLinkedList.java | 75 +- .../commons/collections/TestListUtils.java | 79 +- .../commons/collections/TestMapUtils.java | 249 ++- .../collections/TestPredicateUtils.java | 435 ++--- .../commons/collections/TestSetUtils.java | 43 +- .../collections/TestTransformerUtils.java | 176 +- .../commons/collections/TestTreeMap.java | 30 +- .../collections/TestTypedCollection.java | 23 +- .../collections/bag/AbstractTestBag.java | 307 ++-- .../bag/AbstractTestSortedBag.java | 12 +- .../commons/collections/bag/TestHashBag.java | 6 +- .../collections/bag/TestPredicatedBag.java | 75 +- .../bag/TestPredicatedSortedBag.java | 80 +- .../collections/bag/TestTransformedBag.java | 25 +- .../bag/TestTransformedSortedBag.java | 27 +- .../commons/collections/bag/TestTreeBag.java | 109 +- .../bidimap/AbstractTestBidiMap.java | 331 ++-- .../bidimap/AbstractTestOrderedBidiMap.java | 104 +- .../bidimap/AbstractTestSortedBidiMap.java | 411 +++-- .../TestAbstractOrderedBidiMapDecorator.java | 43 +- .../bidimap/TestDualHashBidiMap.java | 13 +- .../bidimap/TestDualTreeBidiMap.java | 11 +- .../bidimap/TestDualTreeBidiMap2.java | 31 +- .../collections/bidimap/TestTreeBidiMap.java | 11 +- .../bidimap/TestUnmodifiableBidiMap.java | 38 +- .../TestUnmodifiableOrderedBidiMap.java | 42 +- .../TestUnmodifiableSortedBidiMap.java | 44 +- .../buffer/TestBlockingBuffer.java | 406 ++--- .../collections/buffer/TestBoundedBuffer.java | 120 +- .../buffer/TestBoundedFifoBuffer.java | 86 +- .../buffer/TestBoundedFifoBuffer2.java | 36 +- .../buffer/TestCircularFifoBuffer.java | 306 ++-- .../buffer/TestPredicatedBuffer.java | 70 +- .../buffer/TestPriorityBuffer.java | 214 +-- .../buffer/TestSynchronizedBuffer.java | 41 +- .../buffer/TestTransformedBuffer.java | 4 +- .../buffer/TestUnboundedFifoBuffer.java | 200 ++- .../buffer/TestUnmodifiableBuffer.java | 55 +- .../collection/AbstractTestCollection.java | 756 ++++---- .../collection/TestCompositeCollection.java | 279 +-- .../collection/TestPredicatedCollection.java | 85 +- .../TestSynchronizedCollection.java | 35 +- .../collection/TestTransformedCollection.java | 2 +- .../TestUnmodifiableCollection.java | 41 +- .../comparators/AbstractTestComparator.java | 76 +- .../comparators/TestBooleanComparator.java | 112 +- .../comparators/TestComparableComparator.java | 20 +- .../comparators/TestComparatorChain.java | 122 +- .../comparators/TestFixedOrderComparator.java | 86 +- .../comparators/TestNullComparator.java | 66 +- .../comparators/TestReverseComparator.java | 27 +- .../functors/TestAllPredicate.java | 24 +- .../functors/TestAnyAllOnePredicate.java | 29 +- .../functors/TestCompositePredicate.java | 23 +- .../iterators/AbstractTestIterator.java | 21 +- .../iterators/AbstractTestListIterator.java | 113 +- .../iterators/AbstractTestMapIterator.java | 166 +- .../AbstractTestOrderedMapIterator.java | 71 +- .../iterators/TestArrayIterator.java | 24 +- .../iterators/TestArrayIterator2.java | 55 +- .../iterators/TestArrayListIterator.java | 26 +- .../iterators/TestArrayListIterator2.java | 28 +- .../iterators/TestCollatingIterator.java | 124 +- .../iterators/TestFilterIterator.java | 82 +- .../iterators/TestFilterListIterator.java | 354 ++-- .../iterators/TestIteratorChain.java | 76 +- .../iterators/TestListIteratorWrapper.java | 72 +- .../iterators/TestLoopingIterator.java | 30 +- .../iterators/TestLoopingListIterator.java | 50 +- .../iterators/TestObjectArrayIterator.java | 48 +- .../TestObjectArrayListIterator.java | 30 +- .../TestObjectArrayListIterator2.java | 30 +- .../iterators/TestObjectGraphIterator.java | 106 +- .../iterators/TestReverseListIterator.java | 44 +- .../iterators/TestSingletonIterator.java | 50 +- .../iterators/TestSingletonIterator2.java | 18 +- .../iterators/TestSingletonListIterator.java | 15 +- .../iterators/TestUniqueFilterIterator.java | 48 +- .../iterators/TestUnmodifiableIterator.java | 36 +- .../TestUnmodifiableListIterator.java | 38 +- .../TestUnmodifiableMapIterator.java | 54 +- .../TestUnmodifiableOrderedMapIterator.java | 58 +- .../keyvalue/AbstractTestMapEntry.java | 32 +- .../keyvalue/TestDefaultKeyValue.java | 54 +- .../keyvalue/TestDefaultMapEntry.java | 23 +- .../collections/keyvalue/TestMultiKey.java | 154 +- .../keyvalue/TestTiedMapEntry.java | 42 +- .../keyvalue/TestUnmodifiableMapEntry.java | 34 +- .../collections/list/AbstractTestList.java | 551 +++--- .../list/TestAbstractLinkedList.java | 126 +- .../list/TestCursorableLinkedList.java | 1324 +++++++------- .../collections/list/TestFixedSizeList.java | 18 +- .../collections/list/TestGrowthList.java | 40 +- .../list/TestNodeCachingLinkedList.java | 78 +- .../collections/list/TestPredicatedList.java | 167 +- .../collections/list/TestSetUniqueList.java | 307 ++-- .../list/TestSynchronizedList.java | 19 +- .../collections/list/TestTransformedList.java | 69 +- .../collections/list/TestTreeList.java | 112 +- .../list/TestUnmodifiableList.java | 80 +- .../map/AbstractTestIterableMap.java | 110 +- .../collections/map/AbstractTestMap.java | 935 +++++----- .../map/AbstractTestOrderedMap.java | 142 +- .../map/AbstractTestSortedMap.java | 200 ++- .../map/TestCaseInsensitiveMap.java | 79 +- .../collections/map/TestCompositeMap.java | 127 +- .../collections/map/TestDefaultedMap.java | 68 +- .../collections/map/TestFixedSizeMap.java | 18 +- .../map/TestFixedSizeSortedMap.java | 21 +- .../commons/collections/map/TestFlat3Map.java | 243 +-- .../collections/map/TestHashedMap.java | 29 +- .../collections/map/TestIdentityMap.java | 76 +- .../commons/collections/map/TestLRUMap.java | 335 ++-- .../commons/collections/map/TestLazyMap.java | 30 +- .../collections/map/TestLazySortedMap.java | 8 +- .../collections/map/TestLinkedMap.java | 181 +- .../collections/map/TestListOrderedMap.java | 232 +-- .../collections/map/TestListOrderedMap2.java | 96 +- .../collections/map/TestMultiKeyMap.java | 189 +- .../collections/map/TestMultiValueMap.java | 240 +-- .../collections/map/TestPredicatedMap.java | 88 +- .../map/TestPredicatedSortedMap.java | 122 +- .../map/TestReferenceIdentityMap.java | 124 +- .../collections/map/TestReferenceMap.java | 60 +- .../collections/map/TestSingletonMap.java | 66 +- .../collections/map/TestStaticBucketMap.java | 31 +- .../collections/map/TestTransformedMap.java | 75 +- .../map/TestTransformedSortedMap.java | 95 +- .../collections/map/TestUnmodifiableMap.java | 49 +- .../map/TestUnmodifiableOrderedMap.java | 49 +- .../map/TestUnmodifiableSortedMap.java | 49 +- .../collections/set/AbstractTestSet.java | 73 +- .../set/AbstractTestSortedSet.java | 106 +- .../collections/set/TestCompositeSet.java | 156 +- .../collections/set/TestListOrderedSet.java | 103 +- .../collections/set/TestListOrderedSet2.java | 92 +- .../collections/set/TestMapBackedSet.java | 6 +- .../collections/set/TestMapBackedSet2.java | 26 +- .../collections/set/TestPredicatedSet.java | 110 +- .../set/TestPredicatedSortedSet.java | 107 +- .../collections/set/TestSynchronizedSet.java | 24 +- .../set/TestSynchronizedSortedSet.java | 26 +- .../collections/set/TestTransformedSet.java | 48 +- .../set/TestTransformedSortedSet.java | 40 +- .../collections/set/TestUnmodifiableSet.java | 34 +- .../set/TestUnmodifiableSortedSet.java | 77 +- 369 files changed, 15699 insertions(+), 14685 deletions(-) create mode 100644 src/java/org/apache/commons/collections/collection/AbstractUntypedCollectionDecorator.java create mode 100644 src/java/org/apache/commons/collections/iterators/AbstractEmptyMapIterator.java create mode 100644 src/java/org/apache/commons/collections/iterators/AbstractUntypedIteratorDecorator.java diff --git a/src/java/org/apache/commons/collections/ArrayStack.java b/src/java/org/apache/commons/collections/ArrayStack.java index 530d7641b..891fc70b7 100644 --- a/src/java/org/apache/commons/collections/ArrayStack.java +++ b/src/java/org/apache/commons/collections/ArrayStack.java @@ -42,7 +42,7 @@ import java.util.EmptyStackException; * @author Paul Jack * @author Stephen Colebourne */ -public class ArrayStack extends ArrayList implements Buffer { +public class ArrayStack extends ArrayList implements Buffer { /** Ensure serialization compatibility */ private static final long serialVersionUID = 2130079159931574599L; @@ -84,7 +84,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @return the top item on the stack * @throws EmptyStackException if the stack is empty */ - public Object peek() throws EmptyStackException { + public E peek() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); @@ -102,7 +102,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @throws EmptyStackException if there are not enough items on the * stack to satisfy this request */ - public Object peek(int n) throws EmptyStackException { + public E peek(int n) throws EmptyStackException { int m = (size() - n) - 1; if (m < 0) { throw new EmptyStackException(); @@ -117,7 +117,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @return the top item on the stack * @throws EmptyStackException if the stack is empty */ - public Object pop() throws EmptyStackException { + public E pop() throws EmptyStackException { int n = size(); if (n <= 0) { throw new EmptyStackException(); @@ -133,7 +133,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @param item the item to be added * @return the item just pushed */ - public Object push(Object item) { + public E push(E item) { add(item); return item; } @@ -170,7 +170,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @return the element on the top of the stack * @throws BufferUnderflowException if the stack is empty */ - public Object get() { + public E get() { int size = size(); if (size == 0) { throw new BufferUnderflowException(); @@ -184,7 +184,7 @@ public class ArrayStack extends ArrayList implements Buffer { * @return the removed element * @throws BufferUnderflowException if the stack is empty */ - public Object remove() { + public E remove() { int size = size(); if (size == 0) { throw new BufferUnderflowException(); diff --git a/src/java/org/apache/commons/collections/BagUtils.java b/src/java/org/apache/commons/collections/BagUtils.java index 86e471d4e..af3b02ee1 100644 --- a/src/java/org/apache/commons/collections/BagUtils.java +++ b/src/java/org/apache/commons/collections/BagUtils.java @@ -28,11 +28,12 @@ import org.apache.commons.collections.bag.UnmodifiableBag; import org.apache.commons.collections.bag.UnmodifiableSortedBag; /** - * Provides utility methods and decorators for - * {@link Bag} and {@link SortedBag} instances. - * + * Provides utility methods and decorators for {@link Bag} and {@link SortedBag} + * instances. + * * @since Commons Collections 2.1 - * @version $Revision$ $Date$ + * @version $Revision$ $Date: 2007-07-13 05:39:24 -0500 (Fri, 13 Jul + * 2007) $ * * @author Paul Jack * @author Stephen Colebourne @@ -44,29 +45,29 @@ public class BagUtils { /** * An empty unmodifiable bag. */ - public static final Bag EMPTY_BAG = UnmodifiableBag.decorate(new HashBag()); + public static final Bag EMPTY_BAG = UnmodifiableBag.decorate(new HashBag()); /** * An empty unmodifiable sorted bag. */ - public static final Bag EMPTY_SORTED_BAG = UnmodifiableSortedBag.decorate(new TreeBag()); + public static final Bag EMPTY_SORTED_BAG = UnmodifiableSortedBag.decorate(new TreeBag()); /** - * Instantiation of BagUtils is not intended or required. - * However, some tools require an instance to operate. + * Instantiation of BagUtils is not intended or required. However, some + * tools require an instance to operate. */ public BagUtils() { } //----------------------------------------------------------------------- /** - * Returns a synchronized (thread-safe) bag backed by the given bag. - * In order to guarantee serial access, it is critical that all - * access to the backing bag is accomplished through the returned bag. + * Returns a synchronized (thread-safe) bag backed by the given bag. In + * order to guarantee serial access, it is critical that all access to the + * backing bag is accomplished through the returned bag. *

- * It is imperative that the user manually synchronize on the returned - * bag when iterating over it: - * + * It is imperative that the user manually synchronize on the returned bag + * when iterating over it: + * *

      * Bag bag = BagUtils.synchronizedBag(new HashBag());
      * ...
@@ -77,74 +78,73 @@ public class BagUtils {
      *     }
      * }
      * 
- * - * Failure to follow this advice may result in non-deterministic - * behavior. - * - * @param bag the bag to synchronize, must not be null + * + * Failure to follow this advice may result in non-deterministic behavior. + * + * @param bag the bag to synchronize, must not be null * @return a synchronized bag backed by that bag - * @throws IllegalArgumentException if the Bag is null + * @throws IllegalArgumentException if the Bag is null */ public static Bag synchronizedBag(Bag bag) { return SynchronizedBag.decorate(bag); } /** - * Returns an unmodifiable view of the given bag. Any modification - * attempts to the returned bag will raise an - * {@link UnsupportedOperationException}. - * - * @param bag the bag whose unmodifiable view is to be returned, must not be null + * Returns an unmodifiable view of the given bag. Any modification attempts + * to the returned bag will raise an {@link UnsupportedOperationException}. + * + * @param bag the bag whose unmodifiable view is to be returned, must not be + * null * @return an unmodifiable view of that bag - * @throws IllegalArgumentException if the Bag is null + * @throws IllegalArgumentException if the Bag is null */ public static Bag unmodifiableBag(Bag bag) { return UnmodifiableBag.decorate(bag); } - + /** * Returns a predicated (validating) bag backed by the given bag. *

- * Only objects that pass the test in the given predicate can be added to the bag. - * Trying to add an invalid object results in an IllegalArgumentException. - * It is important not to use the original bag after invoking this method, - * as it is a backdoor for adding invalid objects. - * - * @param bag the bag to predicate, must not be null - * @param predicate the predicate for the bag, must not be null + * Only objects that pass the test in the given predicate can be added to + * the bag. Trying to add an invalid object results in an + * IllegalArgumentException. It is important not to use the original bag + * after invoking this method, as it is a backdoor for adding invalid + * objects. + * + * @param bag the bag to predicate, must not be null + * @param predicate the predicate for the bag, must not be null * @return a predicated bag backed by the given bag - * @throws IllegalArgumentException if the Bag or Predicate is null + * @throws IllegalArgumentException if the Bag or Predicate is null */ public static Bag predicatedBag(Bag bag, Predicate predicate) { return PredicatedBag.decorate(bag, predicate); } - + /** * Returns a transformed bag backed by the given bag. *

- * Each object is passed through the transformer as it is added to the - * Bag. It is important not to use the original bag after invoking this - * method, as it is a backdoor for adding untransformed objects. - * - * @param bag the bag to predicate, must not be null - * @param transformer the transformer for the bag, must not be null + * Each object is passed through the transformer as it is added to the Bag. + * It is important not to use the original bag after invoking this method, + * as it is a backdoor for adding untransformed objects. + * + * @param bag the bag to predicate, must not be null + * @param transformer the transformer for the bag, must not be null * @return a transformed bag backed by the given bag - * @throws IllegalArgumentException if the Bag or Transformer is null + * @throws IllegalArgumentException if the Bag or Transformer is null */ - public static Bag transformedBag(Bag bag, Transformer transformer) { + public static Bag transformedBag(Bag bag, Transformer transformer) { return TransformedBag.decorate(bag, transformer); } - + //----------------------------------------------------------------------- /** - * Returns a synchronized (thread-safe) sorted bag backed by the given - * sorted bag. - * In order to guarantee serial access, it is critical that all + * Returns a synchronized (thread-safe) sorted bag backed by the given + * sorted bag. In order to guarantee serial access, it is critical that all * access to the backing bag is accomplished through the returned bag. *

- * It is imperative that the user manually synchronize on the returned - * bag when iterating over it: - * + * It is imperative that the user manually synchronize on the returned bag + * when iterating over it: + * *

      * SortedBag bag = BagUtils.synchronizedSortedBag(new TreeBag());
      * ...
@@ -155,62 +155,84 @@ public class BagUtils {
      *     }
      * }
      * 
- * - * Failure to follow this advice may result in non-deterministic - * behavior. - * - * @param bag the bag to synchronize, must not be null + * + * Failure to follow this advice may result in non-deterministic behavior. + * + * @param bag the bag to synchronize, must not be null * @return a synchronized bag backed by that bag - * @throws IllegalArgumentException if the SortedBag is null + * @throws IllegalArgumentException if the SortedBag is null */ public static SortedBag synchronizedSortedBag(SortedBag bag) { return SynchronizedSortedBag.decorate(bag); } - + /** - * Returns an unmodifiable view of the given sorted bag. Any modification - * attempts to the returned bag will raise an + * Returns an unmodifiable view of the given sorted bag. Any modification + * attempts to the returned bag will raise an * {@link UnsupportedOperationException}. - * - * @param bag the bag whose unmodifiable view is to be returned, must not be null + * + * @param bag the bag whose unmodifiable view is to be returned, must not be + * null * @return an unmodifiable view of that bag - * @throws IllegalArgumentException if the SortedBag is null + * @throws IllegalArgumentException if the SortedBag is null */ public static SortedBag unmodifiableSortedBag(SortedBag bag) { return UnmodifiableSortedBag.decorate(bag); } - + /** - * Returns a predicated (validating) sorted bag backed by the given sorted bag. + * Returns a predicated (validating) sorted bag backed by the given sorted + * bag. *

- * Only objects that pass the test in the given predicate can be added to the bag. - * Trying to add an invalid object results in an IllegalArgumentException. - * It is important not to use the original bag after invoking this method, - * as it is a backdoor for adding invalid objects. - * - * @param bag the sorted bag to predicate, must not be null - * @param predicate the predicate for the bag, must not be null + * Only objects that pass the test in the given predicate can be added to + * the bag. Trying to add an invalid object results in an + * IllegalArgumentException. It is important not to use the original bag + * after invoking this method, as it is a backdoor for adding invalid + * objects. + * + * @param bag the sorted bag to predicate, must not be null + * @param predicate the predicate for the bag, must not be null * @return a predicated bag backed by the given bag - * @throws IllegalArgumentException if the SortedBag or Predicate is null + * @throws IllegalArgumentException if the SortedBag or Predicate is null */ - public static SortedBag predicatedSortedBag(SortedBag bag, Predicate predicate) { + public static SortedBag predicatedSortedBag(SortedBag bag, + Predicate predicate) { return PredicatedSortedBag.decorate(bag, predicate); } - + /** * Returns a transformed sorted bag backed by the given bag. *

- * Each object is passed through the transformer as it is added to the - * Bag. It is important not to use the original bag after invoking this - * method, as it is a backdoor for adding untransformed objects. - * - * @param bag the bag to predicate, must not be null - * @param transformer the transformer for the bag, must not be null + * Each object is passed through the transformer as it is added to the Bag. + * It is important not to use the original bag after invoking this method, + * as it is a backdoor for adding untransformed objects. + * + * @param bag the bag to predicate, must not be null + * @param transformer the transformer for the bag, must not be null * @return a transformed bag backed by the given bag - * @throws IllegalArgumentException if the Bag or Transformer is null + * @throws IllegalArgumentException if the Bag or Transformer is null */ - public static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer) { + public static SortedBag transformedSortedBag(SortedBag bag, Transformer transformer) { return TransformedSortedBag.decorate(bag, transformer); } - + + /** + * Get an empty Bag. + * @param + * @return Bag + */ + @SuppressWarnings("unchecked") + public static Bag emptyBag() { + return (Bag) EMPTY_BAG; + } + + /** + * Get an empty SortedBag. + * @param + * @return SortedBag + */ + @SuppressWarnings("unchecked") + public static SortedBag emptySortedBag() { + return (SortedBag) EMPTY_SORTED_BAG; + } } diff --git a/src/java/org/apache/commons/collections/BidiMap.java b/src/java/org/apache/commons/collections/BidiMap.java index 125f6d7e9..860b81c12 100644 --- a/src/java/org/apache/commons/collections/BidiMap.java +++ b/src/java/org/apache/commons/collections/BidiMap.java @@ -88,7 +88,7 @@ public interface BidiMap extends IterableMap { * @throws NullPointerException (optional) if the map limits the values to * non-null and null was specified */ - K getKey(V value); + K getKey(Object value); /** * Removes the key-value pair that is currently mapped to the specified @@ -109,7 +109,7 @@ public interface BidiMap extends IterableMap { * @throws UnsupportedOperationException if this method is not supported * by the implementation */ - K removeValue(V value); + K removeValue(Object value); /** * Gets a view of this map where the keys and values are reversed. diff --git a/src/java/org/apache/commons/collections/BoundedCollection.java b/src/java/org/apache/commons/collections/BoundedCollection.java index d5a54b5be..1eb78a3a8 100644 --- a/src/java/org/apache/commons/collections/BoundedCollection.java +++ b/src/java/org/apache/commons/collections/BoundedCollection.java @@ -34,7 +34,7 @@ import java.util.Collection; * @author Herve Quiroz * @author Stephen Colebourne */ -public interface BoundedCollection extends Collection { +public interface BoundedCollection extends Collection { /** * Returns true if this collection is full and no new elements can be added. diff --git a/src/java/org/apache/commons/collections/BoundedMap.java b/src/java/org/apache/commons/collections/BoundedMap.java index 525fe2ffb..0a8123fa8 100644 --- a/src/java/org/apache/commons/collections/BoundedMap.java +++ b/src/java/org/apache/commons/collections/BoundedMap.java @@ -30,7 +30,7 @@ import java.util.Map; * * @author Stephen Colebourne */ -public interface BoundedMap extends Map { +public interface BoundedMap extends Map { /** * Returns true if this map is full and no new elements can be added. diff --git a/src/java/org/apache/commons/collections/BufferOverflowException.java b/src/java/org/apache/commons/collections/BufferOverflowException.java index b4cc029f5..024f1b5b9 100644 --- a/src/java/org/apache/commons/collections/BufferOverflowException.java +++ b/src/java/org/apache/commons/collections/BufferOverflowException.java @@ -31,6 +31,9 @@ package org.apache.commons.collections; */ public class BufferOverflowException extends RuntimeException { + /** Serialization version */ + private static final long serialVersionUID = -3992254982265755876L; + /** The root cause throwable */ private final Throwable throwable; diff --git a/src/java/org/apache/commons/collections/BufferUnderflowException.java b/src/java/org/apache/commons/collections/BufferUnderflowException.java index fbb52b72c..79cb94e11 100644 --- a/src/java/org/apache/commons/collections/BufferUnderflowException.java +++ b/src/java/org/apache/commons/collections/BufferUnderflowException.java @@ -34,6 +34,9 @@ import java.util.NoSuchElementException; */ public class BufferUnderflowException extends NoSuchElementException { + /** Serialization version */ + private static final long serialVersionUID = 4054570024234606028L; + /** The root cause throwable */ private final Throwable throwable; diff --git a/src/java/org/apache/commons/collections/BufferUtils.java b/src/java/org/apache/commons/collections/BufferUtils.java index 625743458..0e09fe804 100644 --- a/src/java/org/apache/commons/collections/BufferUtils.java +++ b/src/java/org/apache/commons/collections/BufferUtils.java @@ -37,7 +37,7 @@ public class BufferUtils { /** * An empty unmodifiable buffer. */ - public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.decorate(new ArrayStack(1)); + public static final Buffer EMPTY_BUFFER = UnmodifiableBuffer.decorate(new ArrayStack(1)); /** * BufferUtils should not normally be instantiated. @@ -66,7 +66,7 @@ public class BufferUtils { * @return a synchronized buffer backed by that buffer * @throws IllegalArgumentException if the Buffer is null */ - public static Buffer synchronizedBuffer(Buffer buffer) { + public static Buffer synchronizedBuffer(Buffer buffer) { return SynchronizedBuffer.decorate(buffer); } @@ -82,7 +82,7 @@ public class BufferUtils { * @return a blocking buffer backed by that buffer * @throws IllegalArgumentException if the Buffer is null */ - public static Buffer blockingBuffer(Buffer buffer) { + public static Buffer blockingBuffer(Buffer buffer) { return BlockingBuffer.decorate(buffer); } @@ -100,7 +100,7 @@ public class BufferUtils { * @throws IllegalArgumentException if the Buffer is null * @since Commons Collections 3.2 */ - public static Buffer blockingBuffer(Buffer buffer, long timeoutMillis) { + public static Buffer blockingBuffer(Buffer buffer, long timeoutMillis) { return BlockingBuffer.decorate(buffer, timeoutMillis); } @@ -117,7 +117,7 @@ public class BufferUtils { * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ - public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { + public static Buffer boundedBuffer(Buffer buffer, int maximumSize) { return BoundedBuffer.decorate(buffer, maximumSize); } @@ -135,7 +135,7 @@ public class BufferUtils { * @throws IllegalArgumentException if the given buffer is null * @since Commons Collections 3.2 */ - public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { + public static Buffer boundedBuffer(Buffer buffer, int maximumSize, long timeoutMillis) { return BoundedBuffer.decorate(buffer, maximumSize, timeoutMillis); } @@ -146,7 +146,7 @@ public class BufferUtils { * @return an unmodifiable buffer backed by that buffer * @throws IllegalArgumentException if the Buffer is null */ - public static Buffer unmodifiableBuffer(Buffer buffer) { + public static Buffer unmodifiableBuffer(Buffer buffer) { return UnmodifiableBuffer.decorate(buffer); } @@ -163,7 +163,7 @@ public class BufferUtils { * @return a predicated buffer * @throws IllegalArgumentException if the Buffer or Predicate is null */ - public static Buffer predicatedBuffer(Buffer buffer, Predicate predicate) { + public static Buffer predicatedBuffer(Buffer buffer, Predicate predicate) { return PredicatedBuffer.decorate(buffer, predicate); } @@ -179,8 +179,17 @@ public class BufferUtils { * @return a transformed buffer backed by the given buffer * @throws IllegalArgumentException if the Buffer or Transformer is null */ - public static Buffer transformedBuffer(Buffer buffer, Transformer transformer) { + public static Buffer transformedBuffer(Buffer buffer, Transformer transformer) { return TransformedBuffer.decorate(buffer, transformer); } + /** + * Get an empty Buffer. + * @param + * @return Buffer + */ + @SuppressWarnings("unchecked") + public static Buffer emptyBuffer() { + return (Buffer) EMPTY_BUFFER; + } } diff --git a/src/java/org/apache/commons/collections/ClosureUtils.java b/src/java/org/apache/commons/collections/ClosureUtils.java index ff0270dc7..750c284b2 100644 --- a/src/java/org/apache/commons/collections/ClosureUtils.java +++ b/src/java/org/apache/commons/collections/ClosureUtils.java @@ -17,7 +17,6 @@ package org.apache.commons.collections; import java.util.Collection; -import java.util.Iterator; import java.util.Map; import org.apache.commons.collections.functors.ChainedClosure; @@ -71,8 +70,8 @@ public class ClosureUtils { * * @return the closure */ - public static Closure exceptionClosure() { - return ExceptionClosure.INSTANCE; + public static Closure exceptionClosure() { + return ExceptionClosure.getInstance(); } /** @@ -83,8 +82,8 @@ public class ClosureUtils { * * @return the closure */ - public static Closure nopClosure() { - return NOPClosure.INSTANCE; + public static Closure nopClosure() { + return NOPClosure.getInstance(); } /** @@ -97,7 +96,7 @@ public class ClosureUtils { * @param transformer the transformer to run each time in the closure, null means nop * @return the closure */ - public static Closure asClosure(Transformer transformer) { + public static Closure asClosure(Transformer transformer) { return TransformerClosure.getInstance(transformer); } @@ -112,7 +111,7 @@ public class ClosureUtils { * @param closure the closure to call repeatedly * @return the for closure */ - public static Closure forClosure(int count, Closure closure) { + public static Closure forClosure(int count, Closure closure) { return ForClosure.getInstance(count, closure); } @@ -127,8 +126,8 @@ public class ClosureUtils { * @return the while closure * @throws IllegalArgumentException if either argument is null */ - public static Closure whileClosure(Predicate predicate, Closure closure) { - return WhileClosure.getInstance(predicate, closure, false); + public static Closure whileClosure(Predicate predicate, Closure closure) { + return WhileClosure.getInstance(predicate, closure, false); } /** @@ -142,8 +141,8 @@ public class ClosureUtils { * @return the do-while closure * @throws IllegalArgumentException if either argument is null */ - public static Closure doWhileClosure(Closure closure, Predicate predicate) { - return WhileClosure.getInstance(predicate, closure, true); + public static Closure doWhileClosure(Closure closure, Predicate predicate) { + return WhileClosure.getInstance(predicate, closure, true); } /** @@ -157,9 +156,9 @@ public class ClosureUtils { * @return the invoker closure * @throws IllegalArgumentException if the method name is null */ - public static Closure invokerClosure(String methodName) { + public static Closure invokerClosure(String methodName) { // reuse transformer as it has caching - this is lazy really, should have inner class here - return asClosure(InvokerTransformer.getInstance(methodName)); + return asClosure(InvokerTransformer.getInstance(methodName)); } /** @@ -176,9 +175,9 @@ public class ClosureUtils { * @throws IllegalArgumentException if the method name is null * @throws IllegalArgumentException if the paramTypes and args don't match */ - public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args) { + public static Closure invokerClosure(String methodName, Class[] paramTypes, Object[] args) { // reuse transformer as it has caching - this is lazy really, should have inner class here - return asClosure(InvokerTransformer.getInstance(methodName, paramTypes, args)); + return asClosure(InvokerTransformer.getInstance(methodName, paramTypes, args)); } /** @@ -192,8 +191,8 @@ public class ClosureUtils { * @return the chained closure * @throws IllegalArgumentException if either closure is null */ - public static Closure chainedClosure(Closure closure1, Closure closure2) { - return ChainedClosure.getInstance(closure1, closure2); + public static Closure chainedClosure(Closure closure1, Closure closure2) { + return ChainedClosure.getInstance(closure1, closure2); } /** @@ -207,7 +206,7 @@ public class ClosureUtils { * @throws IllegalArgumentException if the closures array is null * @throws IllegalArgumentException if any closure in the array is null */ - public static Closure chainedClosure(Closure[] closures) { + public static Closure chainedClosure(Closure[] closures) { return ChainedClosure.getInstance(closures); } @@ -224,7 +223,7 @@ public class ClosureUtils { * @throws IllegalArgumentException if the closures collection is empty * @throws IllegalArgumentException if any closure in the collection is null */ - public static Closure chainedClosure(Collection closures) { + public static Closure chainedClosure(Collection> closures) { return ChainedClosure.getInstance(closures); } @@ -241,8 +240,8 @@ public class ClosureUtils { * @throws IllegalArgumentException if the closure is null * @since Commons Collections 3.2 */ - public static Closure ifClosure(Predicate predicate, Closure trueClosure) { - return IfClosure.getInstance(predicate, trueClosure); + public static Closure ifClosure(Predicate predicate, Closure trueClosure) { + return IfClosure.getInstance(predicate, trueClosure); } /** @@ -258,8 +257,8 @@ public class ClosureUtils { * @throws IllegalArgumentException if the predicate is null * @throws IllegalArgumentException if either closure is null */ - public static Closure ifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) { - return IfClosure.getInstance(predicate, trueClosure, falseClosure); + public static Closure ifClosure(Predicate predicate, Closure trueClosure, Closure falseClosure) { + return IfClosure.getInstance(predicate, trueClosure, falseClosure); } /** @@ -279,8 +278,8 @@ public class ClosureUtils { * @throws IllegalArgumentException if any element in the arrays is null * @throws IllegalArgumentException if the arrays are different sizes */ - public static Closure switchClosure(Predicate[] predicates, Closure[] closures) { - return SwitchClosure.getInstance(predicates, closures, null); + public static Closure switchClosure(Predicate[] predicates, Closure[] closures) { + return SwitchClosure.getInstance(predicates, closures, null); } /** @@ -302,8 +301,8 @@ public class ClosureUtils { * @throws IllegalArgumentException if any element in the arrays is null * @throws IllegalArgumentException if the arrays are different sizes */ - public static Closure switchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { - return SwitchClosure.getInstance(predicates, closures, defaultClosure); + public static Closure switchClosure(Predicate[] predicates, Closure[] closures, Closure defaultClosure) { + return SwitchClosure.getInstance(predicates, closures, defaultClosure); } /** @@ -326,7 +325,7 @@ public class ClosureUtils { * @throws IllegalArgumentException if any closure in the map is null * @throws ClassCastException if the map elements are of the wrong type */ - public static Closure switchClosure(Map predicatesAndClosures) { + public static Closure switchClosure(Map, Closure> predicatesAndClosures) { return SwitchClosure.getInstance(predicatesAndClosures); } @@ -347,24 +346,24 @@ public class ClosureUtils { * @throws IllegalArgumentException if the map is empty * @throws IllegalArgumentException if any closure in the map is null */ - public static Closure switchMapClosure(Map objectsAndClosures) { - Closure[] trs = null; - Predicate[] preds = null; + @SuppressWarnings("unchecked") + public static Closure switchMapClosure(Map> objectsAndClosures) { + Closure[] trs = null; + Predicate[] preds = null; if (objectsAndClosures == null) { throw new IllegalArgumentException("The object and closure map must not be null"); } - Closure def = (Closure) objectsAndClosures.remove(null); + Closure def = objectsAndClosures.remove(null); int size = objectsAndClosures.size(); trs = new Closure[size]; preds = new Predicate[size]; int i = 0; - for (Iterator it = objectsAndClosures.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = (Map.Entry) it.next(); - preds[i] = EqualPredicate.equalPredicate(entry.getKey()); - trs[i] = (Closure) entry.getValue(); + for (Map.Entry> entry : objectsAndClosures.entrySet()) { + preds[i] = EqualPredicate.equalPredicate(entry.getKey()); + trs[i] = entry.getValue(); i++; } - return switchClosure(preds, trs, def); + return ClosureUtils.switchClosure(preds, trs, def); } } diff --git a/src/java/org/apache/commons/collections/CollectionUtils.java b/src/java/org/apache/commons/collections/CollectionUtils.java index 3e9613227..1208eb4c9 100644 --- a/src/java/org/apache/commons/collections/CollectionUtils.java +++ b/src/java/org/apache/commons/collections/CollectionUtils.java @@ -63,9 +63,9 @@ public class CollectionUtils { private static class CardinalityHelper { final Map cardinalityA, cardinalityB; - public CardinalityHelper(Iterable a, Iterable b) { - cardinalityA = CollectionUtils.getCardinalityMap(a); - cardinalityB = CollectionUtils.getCardinalityMap(b); + public CardinalityHelper(Iterable a, Iterable b) { + cardinalityA = CollectionUtils.getCardinalityMap(a); + cardinalityB = CollectionUtils.getCardinalityMap(b); } public final int max(Object obj) { @@ -119,7 +119,6 @@ public class CollectionUtils { return newList; } - } /** @@ -292,9 +291,9 @@ public class CollectionUtils { * super type of . * @return the populated cardinality map */ - public static Map getCardinalityMap(final Iterable coll) { + public static Map getCardinalityMap(final Iterable coll) { Map count = new HashMap(); - for (I obj : coll) { + for (O obj : coll) { Integer c = count.get(obj); if (c == null) { count.put(obj, 1); @@ -490,7 +489,8 @@ public class CollectionUtils { * @param transformer * the transformer to perform, may be null */ - public static void transform(Collection collection, Transformer transformer) { + public static void transform(Collection collection, + Transformer transformer) { if (collection != null && transformer != null) { if (collection instanceof List) { List list = (List) collection; @@ -567,7 +567,8 @@ public class CollectionUtils { * @throws NullPointerException * if the input collection is null */ - public static Collection select(Collection inputCollection, Predicate predicate) { + public static Collection select(Collection inputCollection, + Predicate predicate) { return select(inputCollection, predicate, new ArrayList(inputCollection.size())); } @@ -586,9 +587,10 @@ public class CollectionUtils { * the collection to output into, may not be null * @return outputCollection */ - public static > R select(Collection inputCollection, Predicate predicate, R outputCollection) { + public static > R select(Collection inputCollection, + Predicate predicate, R outputCollection) { if (inputCollection != null && predicate != null) { - for (I item : inputCollection) { + for (O item : inputCollection) { if (predicate.evaluate(item)) { outputCollection.add(item); } @@ -612,7 +614,8 @@ public class CollectionUtils { * @throws NullPointerException * if the input collection is null */ - public static Collection selectRejected(Collection inputCollection, Predicate predicate) { + public static Collection selectRejected(Collection inputCollection, + Predicate predicate) { return selectRejected(inputCollection, predicate, new ArrayList(inputCollection.size())); } @@ -631,9 +634,10 @@ public class CollectionUtils { * the collection to output into, may not be null * @return outputCollection */ - public static > R selectRejected(Collection inputCollection, Predicate predicate, R outputCollection) { + public static > R selectRejected( + Collection inputCollection, Predicate predicate, R outputCollection) { if (inputCollection != null && predicate != null) { - for (I item : inputCollection) { + for (O item : inputCollection) { if (!predicate.evaluate(item)) { outputCollection.add(item); } @@ -658,7 +662,8 @@ public class CollectionUtils { * @throws NullPointerException * if the input collection is null */ - public static Collection collect(Iterable inputCollection, Transformer transformer) { + public static Collection collect(Iterable inputCollection, + Transformer transformer) { ArrayList answer = new ArrayList(); collect(inputCollection, transformer, answer); return answer; @@ -679,7 +684,8 @@ public class CollectionUtils { * @param the type of object in the output collection * @return the transformed result (new list) */ - public static Collection collect(Iterator inputIterator, Transformer transformer) { + public static Collection collect(Iterator inputIterator, + Transformer transformer) { ArrayList answer = new ArrayList(); collect(inputIterator, transformer, answer); return answer; @@ -701,7 +707,8 @@ public class CollectionUtils { * @return the outputCollection with the transformed input added * @throws NullPointerException if the output collection is null */ - public static > R collect(Iterable inputCollection, final Transformer transformer, final R outputCollection) { + public static > R collect(Iterable inputCollection, + final Transformer transformer, final R outputCollection) { if (inputCollection != null) { return collect(inputCollection.iterator(), transformer, outputCollection); } @@ -725,11 +732,12 @@ public class CollectionUtils { * @throws NullPointerException if the output collection is null */ //TODO - deprecate and replace with IteratorIterable - public static > R collect(Iterator inputIterator, final Transformer transformer, final R outputCollection) { + public static > R collect(Iterator inputIterator, + final Transformer transformer, final R outputCollection) { if (inputIterator != null && transformer != null) { while (inputIterator.hasNext()) { I item = inputIterator.next(); - T value = transformer.transform(item); + O value = transformer.transform(item); outputCollection.add(value); } } @@ -813,7 +821,7 @@ public class CollectionUtils { * @throws NullPointerException * if the collection or array is null */ - public static void addAll(Collection collection, T[] elements) { + public static void addAll(Collection collection, C[] elements) { for (int i = 0, size = elements.length; i < size; i++) { collection.add(elements[i]); } @@ -913,13 +921,13 @@ public class CollectionUtils { throw new IndexOutOfBoundsException("Index cannot be negative: " + i); } if (object instanceof Map) { - Map map = (Map) object; - Iterator iterator = map.entrySet().iterator(); + Map map = (Map) object; + Iterator iterator = map.entrySet().iterator(); return get(iterator, i); } else if (object instanceof Object[]) { return ((Object[]) object)[i]; } else if (object instanceof Iterator) { - Iterator it = (Iterator) object; + Iterator it = (Iterator) object; while (it.hasNext()) { i--; if (i == -1) { @@ -929,10 +937,10 @@ public class CollectionUtils { } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } else if (object instanceof Collection) { - Iterator iterator = ((Collection) object).iterator(); + Iterator iterator = ((Collection) object).iterator(); return get(iterator, i); } else if (object instanceof Enumeration) { - Enumeration it = (Enumeration) object; + Enumeration it = (Enumeration) object; while (it.hasMoreElements()) { i--; if (i == -1) { @@ -987,19 +995,19 @@ public class CollectionUtils { public static int size(Object object) { int total = 0; if (object instanceof Map) { - total = ((Map) object).size(); + total = ((Map) object).size(); } else if (object instanceof Collection) { - total = ((Collection) object).size(); + total = ((Collection) object).size(); } else if (object instanceof Object[]) { total = ((Object[]) object).length; } else if (object instanceof Iterator) { - Iterator it = (Iterator) object; + Iterator it = (Iterator) object; while (it.hasNext()) { total++; it.next(); } } else if (object instanceof Enumeration) { - Enumeration it = (Enumeration) object; + Enumeration it = (Enumeration) object; while (it.hasMoreElements()) { total++; it.nextElement(); @@ -1038,15 +1046,15 @@ public class CollectionUtils { */ public static boolean sizeIsEmpty(Object object) { if (object instanceof Collection) { - return ((Collection) object).isEmpty(); + return ((Collection) object).isEmpty(); } else if (object instanceof Map) { - return ((Map) object).isEmpty(); + return ((Map) object).isEmpty(); } else if (object instanceof Object[]) { return ((Object[]) object).length == 0; } else if (object instanceof Iterator) { - return ((Iterator) object).hasNext() == false; + return ((Iterator) object).hasNext() == false; } else if (object instanceof Enumeration) { - return ((Enumeration) object).hasMoreElements() == false; + return ((Enumeration) object).hasMoreElements() == false; } else if (object == null) { throw new IllegalArgumentException("Unsupported object type: null"); } else { @@ -1068,7 +1076,7 @@ public class CollectionUtils { * @return true if empty or null * @since Commons Collections 3.2 */ - public static boolean isEmpty(Collection coll) { + public static boolean isEmpty(Collection coll) { return (coll == null || coll.isEmpty()); } @@ -1081,7 +1089,7 @@ public class CollectionUtils { * @return true if non-null and non-empty * @since Commons Collections 3.2 */ - public static boolean isNotEmpty(Collection coll) { + public static boolean isNotEmpty(Collection coll) { return !isEmpty(coll); } @@ -1120,17 +1128,17 @@ public class CollectionUtils { * @return true if the BoundedCollection is full * @throws NullPointerException if the collection is null */ - public static boolean isFull(Collection coll) { + @SuppressWarnings("unchecked") + public static boolean isFull(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { - return ((BoundedCollection) coll).isFull(); + return ((BoundedCollection) coll).isFull(); } try { - BoundedCollection bcoll = UnmodifiableBoundedCollection.decorateUsing(coll); + BoundedCollection bcoll = UnmodifiableBoundedCollection.decorateUsing((Collection) coll); return bcoll.isFull(); - } catch (IllegalArgumentException ex) { return false; } @@ -1151,17 +1159,17 @@ public class CollectionUtils { * @return the maximum size of the BoundedCollection, -1 if no maximum size * @throws NullPointerException if the collection is null */ - public static int maxSize(Collection coll) { + @SuppressWarnings("unchecked") + public static int maxSize(Collection coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { - return ((BoundedCollection) coll).maxSize(); + return ((BoundedCollection) coll).maxSize(); } try { - BoundedCollection bcoll = UnmodifiableBoundedCollection.decorateUsing(coll); + BoundedCollection bcoll = UnmodifiableBoundedCollection.decorateUsing((Collection) coll); return bcoll.maxSize(); - } catch (IllegalArgumentException ex) { return -1; } @@ -1203,7 +1211,7 @@ public class CollectionUtils { * @throws NullPointerException if either parameter is null * @since Commons Collections 3.3 (method existed in 3.2 but was completely broken) */ - public static Collection removeAll(Collection collection, Collection remove) { + public static Collection removeAll(Collection collection, Collection remove) { return ListUtils.removeAll(collection, remove); } @@ -1277,7 +1285,7 @@ public class CollectionUtils { * @return a transformed collection backed by the given collection * @throws IllegalArgumentException if the Collection or Transformer is null */ - public static Collection transformedCollection(Collection collection, Transformer transformer) { + public static Collection transformedCollection(Collection collection, Transformer transformer) { return TransformedCollection.decorate(collection, transformer); } diff --git a/src/java/org/apache/commons/collections/ComparatorUtils.java b/src/java/org/apache/commons/collections/ComparatorUtils.java index 2fed50fc8..c62574585 100644 --- a/src/java/org/apache/commons/collections/ComparatorUtils.java +++ b/src/java/org/apache/commons/collections/ComparatorUtils.java @@ -54,14 +54,16 @@ public class ComparatorUtils { * * @see ComparableComparator#getInstance */ - public static final Comparator NATURAL_COMPARATOR = ComparableComparator.getInstance(); + @SuppressWarnings("unchecked") + public static final Comparator NATURAL_COMPARATOR = ComparableComparator.getInstance(); /** * Gets a comparator that uses the natural order of the objects. * * @return a comparator which uses natural order */ - public static Comparator naturalComparator() { + @SuppressWarnings("unchecked") + public static > Comparator naturalComparator() { return NATURAL_COMPARATOR; } @@ -76,7 +78,8 @@ public class ComparatorUtils { * @throws NullPointerException if either comparator is null * @see ComparatorChain */ - public static Comparator chainedComparator(Comparator comparator1, Comparator comparator2) { + @SuppressWarnings("unchecked") + public static > Comparator chainedComparator(Comparator comparator1, Comparator comparator2) { return chainedComparator(new Comparator[] {comparator1, comparator2}); } @@ -89,8 +92,8 @@ public class ComparatorUtils { * @throws NullPointerException if comparators array is null or contains a null * @see ComparatorChain */ - public static Comparator chainedComparator(Comparator[] comparators) { - ComparatorChain chain = new ComparatorChain(); + public static > Comparator chainedComparator(Comparator[] comparators) { + ComparatorChain chain = new ComparatorChain(); for (int i = 0; i < comparators.length; i++) { if (comparators[i] == null) { throw new NullPointerException("Comparator cannot be null"); @@ -111,9 +114,10 @@ public class ComparatorUtils { * @throws ClassCastException if the comparators collection contains the wrong object type * @see ComparatorChain */ - public static Comparator chainedComparator(Collection comparators) { + @SuppressWarnings("unchecked") + public static > Comparator chainedComparator(Collection> comparators) { return chainedComparator( - (Comparator[]) comparators.toArray(new Comparator[comparators.size()]) + (Comparator[]) comparators.toArray(new Comparator[comparators.size()]) ); } @@ -124,11 +128,8 @@ public class ComparatorUtils { * @return a comparator that reverses the order of the input comparator * @see ReverseComparator */ - public static Comparator reversedComparator(Comparator comparator) { - if (comparator == null) { - comparator = NATURAL_COMPARATOR; - } - return new ReverseComparator(comparator); + public static Comparator reversedComparator(Comparator comparator) { + return new ReverseComparator(comparator); } /** @@ -143,7 +144,7 @@ public class ComparatorUtils { * false {@link Boolean}s. * @return a comparator that sorts booleans */ - public static Comparator booleanComparator(boolean trueFirst) { + public static Comparator booleanComparator(boolean trueFirst) { return BooleanComparator.getBooleanComparator(trueFirst); } @@ -158,11 +159,12 @@ public class ComparatorUtils { * @return a version of that comparator that allows nulls * @see NullComparator */ - public static Comparator nullLowComparator(Comparator comparator) { + @SuppressWarnings("unchecked") + public static Comparator nullLowComparator(Comparator comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } - return new NullComparator(comparator, false); + return new NullComparator(comparator, false); } /** @@ -176,11 +178,12 @@ public class ComparatorUtils { * @return a version of that comparator that allows nulls * @see NullComparator */ - public static Comparator nullHighComparator(Comparator comparator) { + @SuppressWarnings("unchecked") + public static Comparator nullHighComparator(Comparator comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } - return new NullComparator(comparator, true); + return new NullComparator(comparator, true); } /** @@ -195,11 +198,12 @@ public class ComparatorUtils { * @return a comparator that transforms its input objects before comparing them * @see TransformingComparator */ - public static Comparator transformedComparator(Comparator comparator, Transformer transformer) { + @SuppressWarnings("unchecked") + public static Comparator transformedComparator(Comparator comparator, Transformer transformer) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } - return new TransformingComparator(transformer, comparator); + return new TransformingComparator(transformer, comparator); } /** @@ -212,7 +216,8 @@ public class ComparatorUtils { * @param comparator the sort order to use * @return the smaller of the two objects */ - public static Object min(Object o1, Object o2, Comparator comparator) { + @SuppressWarnings("unchecked") + public static E min(E o1, E o2, Comparator comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } @@ -230,7 +235,8 @@ public class ComparatorUtils { * @param comparator the sort order to use * @return the larger of the two objects */ - public static Object max(Object o1, Object o2, Comparator comparator) { + @SuppressWarnings("unchecked") + public static E max(E o1, E o2, Comparator comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } diff --git a/src/java/org/apache/commons/collections/EnumerationUtils.java b/src/java/org/apache/commons/collections/EnumerationUtils.java index ec3b6e7ed..1a7b52fde 100644 --- a/src/java/org/apache/commons/collections/EnumerationUtils.java +++ b/src/java/org/apache/commons/collections/EnumerationUtils.java @@ -16,8 +16,10 @@ */ package org.apache.commons.collections; +import java.util.ArrayList; import java.util.Enumeration; import java.util.List; +import java.util.StringTokenizer; import org.apache.commons.collections.iterators.EnumerationIterator; @@ -47,8 +49,21 @@ public class EnumerationUtils { * @param enumeration the enumeration to traverse, which should not be null. * @throws NullPointerException if the enumeration parameter is null. */ - public static List toList(Enumeration enumeration) { - return IteratorUtils.toList(new EnumerationIterator(enumeration)); + public static List toList(Enumeration enumeration) { + return IteratorUtils.toList(new EnumerationIterator(enumeration)); } + /** + * Override toList(Enumeration) for StringTokenizer as it implements Enumeration + * for the sake of backward compatibility. + * @param stringTokenizer + * @return List + */ + public static List toList(StringTokenizer stringTokenizer) { + List result = new ArrayList(stringTokenizer.countTokens()); + while (stringTokenizer.hasMoreTokens()) { + result.add(stringTokenizer.nextToken()); + } + return result; + } } diff --git a/src/java/org/apache/commons/collections/FactoryUtils.java b/src/java/org/apache/commons/collections/FactoryUtils.java index bdd991f9f..59b02fc04 100644 --- a/src/java/org/apache/commons/collections/FactoryUtils.java +++ b/src/java/org/apache/commons/collections/FactoryUtils.java @@ -55,8 +55,8 @@ public class FactoryUtils { * * @return the factory */ - public static Factory exceptionFactory() { - return ExceptionFactory.INSTANCE; + public static Factory exceptionFactory() { + return ExceptionFactory.getInstance(); } /** @@ -68,7 +68,7 @@ public class FactoryUtils { * @return the factory */ public static Factory nullFactory() { - return ConstantFactory.NULL_INSTANCE; + return ConstantFactory.getInstance(null); } /** @@ -82,7 +82,7 @@ public class FactoryUtils { * @param constantToReturn the constant object to return each time in the factory * @return the constant factory. */ - public static Factory constantFactory(Object constantToReturn) { + public static Factory constantFactory(T constantToReturn) { return ConstantFactory.getInstance(constantToReturn); } @@ -103,8 +103,8 @@ public class FactoryUtils { * @throws IllegalArgumentException if the prototype is null * @throws IllegalArgumentException if the prototype cannot be cloned */ - public static Factory prototypeFactory(Object prototype) { - return PrototypeFactory.getInstance(prototype); + public static Factory prototypeFactory(T prototype) { + return PrototypeFactory.getInstance(prototype); } /** @@ -135,7 +135,7 @@ public class FactoryUtils { * @throws IllegalArgumentException if the paramTypes and args don't match * @throws IllegalArgumentException if the constructor doesn't exist */ - public static Factory instantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { + public static Factory instantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) { return InstantiateFactory.getInstance(classToInstantiate, paramTypes, args); } diff --git a/src/java/org/apache/commons/collections/FunctorException.java b/src/java/org/apache/commons/collections/FunctorException.java index 6651fc818..ce9166a53 100644 --- a/src/java/org/apache/commons/collections/FunctorException.java +++ b/src/java/org/apache/commons/collections/FunctorException.java @@ -30,11 +30,14 @@ import java.io.PrintWriter; */ public class FunctorException extends RuntimeException { + /** Serialization version */ + private static final long serialVersionUID = 9139387246344345475L; + /** * Does JDK support nested exceptions */ private static final boolean JDK_SUPPORTS_NESTED; - + static { boolean flag = false; try { @@ -45,7 +48,7 @@ public class FunctorException extends RuntimeException { } JDK_SUPPORTS_NESTED = flag; } - + /** * Root cause of the exception */ diff --git a/src/java/org/apache/commons/collections/IteratorUtils.java b/src/java/org/apache/commons/collections/IteratorUtils.java index c84957fe9..eba8e37fe 100644 --- a/src/java/org/apache/commons/collections/IteratorUtils.java +++ b/src/java/org/apache/commons/collections/IteratorUtils.java @@ -81,26 +81,30 @@ public class IteratorUtils { * WARNING: This constant is binary incompatible with Commons Collections 2.1 and 2.1.1. * Use EmptyIterator.INSTANCE for compatability with Commons Collections 2.1.1. */ - public static final ResettableIterator EMPTY_ITERATOR = EmptyIterator.RESETTABLE_INSTANCE; + public static final ResettableIterator EMPTY_ITERATOR = EmptyIterator.RESETTABLE_INSTANCE; + /** * A list iterator over no elements. *

* WARNING: This constant is binary incompatible with Commons Collections 2.1 and 2.1.1. * Use EmptyListIterator.INSTANCE for compatability with Commons Collections 2.1.1. */ - public static final ResettableListIterator EMPTY_LIST_ITERATOR = EmptyListIterator.RESETTABLE_INSTANCE; + public static final ResettableListIterator EMPTY_LIST_ITERATOR = EmptyListIterator.RESETTABLE_INSTANCE; + /** * An ordered iterator over no elements. */ - public static final OrderedIterator EMPTY_ORDERED_ITERATOR = EmptyOrderedIterator.INSTANCE; + public static final OrderedIterator EMPTY_ORDERED_ITERATOR = EmptyOrderedIterator.INSTANCE; + /** * A map iterator over no elements. */ - public static final MapIterator EMPTY_MAP_ITERATOR = EmptyMapIterator.INSTANCE; + public static final MapIterator EMPTY_MAP_ITERATOR = EmptyMapIterator.INSTANCE; + /** * An ordered map iterator over no elements. */ - public static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR = EmptyOrderedMapIterator.INSTANCE; + public static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR = EmptyOrderedMapIterator.INSTANCE; /** * IteratorUtils is not normally instantiated. @@ -121,8 +125,8 @@ public class IteratorUtils { * * @return an iterator over nothing */ - public static ResettableIterator emptyIterator() { - return EMPTY_ITERATOR; + public static ResettableIterator emptyIterator() { + return EmptyIterator.getResettableInstance(); } /** @@ -136,8 +140,8 @@ public class IteratorUtils { * * @return a list iterator over nothing */ - public static ResettableListIterator emptyListIterator() { - return EMPTY_LIST_ITERATOR; + public static ResettableListIterator emptyListIterator() { + return EmptyListIterator.getResettableInstance(); } /** @@ -148,8 +152,8 @@ public class IteratorUtils { * * @return an ordered iterator over nothing */ - public static OrderedIterator emptyOrderedIterator() { - return EMPTY_ORDERED_ITERATOR; + public static OrderedIterator emptyOrderedIterator() { + return EmptyOrderedIterator.getInstance(); } /** @@ -160,8 +164,8 @@ public class IteratorUtils { * * @return a map iterator over nothing */ - public static MapIterator emptyMapIterator() { - return EMPTY_MAP_ITERATOR; + public static MapIterator emptyMapIterator() { + return EmptyMapIterator.getInstance(); } /** @@ -172,8 +176,8 @@ public class IteratorUtils { * * @return a map iterator over nothing */ - public static OrderedMapIterator emptyOrderedMapIterator() { - return EMPTY_ORDERED_MAP_ITERATOR; + public static OrderedMapIterator emptyOrderedMapIterator() { + return EmptyOrderedMapIterator.getInstance(); } // Singleton @@ -190,8 +194,8 @@ public class IteratorUtils { * @param object the single object over which to iterate * @return a singleton iterator over the object */ - public static ResettableIterator singletonIterator(Object object) { - return new SingletonIterator(object); + public static ResettableIterator singletonIterator(E object) { + return new SingletonIterator(object); } /** @@ -203,8 +207,8 @@ public class IteratorUtils { * @param object the single object over which to iterate * @return a singleton list iterator over the object */ - public static ListIterator singletonListIterator(Object object) { - return new SingletonListIterator(object); + public static ListIterator singletonListIterator(E object) { + return new SingletonListIterator(object); } // Arrays @@ -219,8 +223,8 @@ public class IteratorUtils { * @return an iterator over the array * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object[] array) { - return new ObjectArrayIterator(array); + public static ResettableIterator arrayIterator(E[] array) { + return new ObjectArrayIterator(array); } /** @@ -234,8 +238,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if the array is not an array * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object array) { - return new ArrayIterator(array); + public static ResettableIterator arrayIterator(Object array) { + return new ArrayIterator(array); } /** @@ -251,8 +255,8 @@ public class IteratorUtils { * than the length of the array * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object[] array, int start) { - return new ObjectArrayIterator(array, start); + public static ResettableIterator arrayIterator(E[] array, int start) { + return new ObjectArrayIterator(array, start); } /** @@ -269,8 +273,8 @@ public class IteratorUtils { * than the length of the array * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object array, int start) { - return new ArrayIterator(array, start); + public static ResettableIterator arrayIterator(Object array, int start) { + return new ArrayIterator(array, start); } /** @@ -287,8 +291,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if end is before start * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object[] array, int start, int end) { - return new ObjectArrayIterator(array, start, end); + public static ResettableIterator arrayIterator(E[] array, int start, int end) { + return new ObjectArrayIterator(array, start, end); } /** @@ -306,8 +310,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if end is before start * @throws NullPointerException if array is null */ - public static ResettableIterator arrayIterator(Object array, int start, int end) { - return new ArrayIterator(array, start, end); + public static ResettableIterator arrayIterator(Object array, int start, int end) { + return new ArrayIterator(array, start, end); } //----------------------------------------------------------------------- @@ -318,8 +322,8 @@ public class IteratorUtils { * @return a list iterator over the array * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object[] array) { - return new ObjectArrayListIterator(array); + public static ResettableListIterator arrayListIterator(E[] array) { + return new ObjectArrayListIterator(array); } /** @@ -333,8 +337,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if the array is not an array * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object array) { - return new ArrayListIterator(array); + public static ResettableListIterator arrayListIterator(Object array) { + return new ArrayListIterator(array); } /** @@ -346,8 +350,8 @@ public class IteratorUtils { * @throws IndexOutOfBoundsException if start is less than zero * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object[] array, int start) { - return new ObjectArrayListIterator(array, start); + public static ResettableListIterator arrayListIterator(E[] array, int start) { + return new ObjectArrayListIterator(array, start); } /** @@ -363,8 +367,8 @@ public class IteratorUtils { * @throws IndexOutOfBoundsException if start is less than zero * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object array, int start) { - return new ArrayListIterator(array, start); + public static ResettableListIterator arrayListIterator(Object array, int start) { + return new ArrayListIterator(array, start); } /** @@ -378,8 +382,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if end is before start * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object[] array, int start, int end) { - return new ObjectArrayListIterator(array, start, end); + public static ResettableListIterator arrayListIterator(E[] array, int start, int end) { + return new ObjectArrayListIterator(array, start, end); } /** @@ -397,8 +401,8 @@ public class IteratorUtils { * @throws IllegalArgumentException if end is before start * @throws NullPointerException if array is null */ - public static ResettableListIterator arrayListIterator(Object array, int start, int end) { - return new ArrayListIterator(array, start, end); + public static ResettableListIterator arrayListIterator(Object array, int start, int end) { + return new ArrayListIterator(array, start, end); } // Unmodifiable @@ -411,7 +415,7 @@ public class IteratorUtils { * @param iterator the iterator to make immutable * @return an immutable version of the iterator */ - public static Iterator unmodifiableIterator(Iterator iterator) { + public static Iterator unmodifiableIterator(Iterator iterator) { return UnmodifiableIterator.decorate(iterator); } @@ -424,7 +428,7 @@ public class IteratorUtils { * @param listIterator the iterator to make immutable * @return an immutable version of the iterator */ - public static ListIterator unmodifiableListIterator(ListIterator listIterator) { + public static ListIterator unmodifiableListIterator(ListIterator listIterator) { return UnmodifiableListIterator.decorate(listIterator); } @@ -436,7 +440,7 @@ public class IteratorUtils { * @param mapIterator the iterator to make immutable * @return an immutable version of the iterator */ - public static MapIterator unmodifiableMapIterator(MapIterator mapIterator) { + public static MapIterator unmodifiableMapIterator(MapIterator mapIterator) { return UnmodifiableMapIterator.decorate(mapIterator); } @@ -451,8 +455,8 @@ public class IteratorUtils { * @return a combination iterator over the iterators * @throws NullPointerException if either iterator is null */ - public static Iterator chainedIterator(Iterator iterator1, Iterator iterator2) { - return new IteratorChain(iterator1, iterator2); + public static Iterator chainedIterator(Iterator iterator1, Iterator iterator2) { + return new IteratorChain(iterator1, iterator2); } /** @@ -463,8 +467,8 @@ public class IteratorUtils { * @return a combination iterator over the iterators * @throws NullPointerException if iterators array is null or contains a null */ - public static Iterator chainedIterator(Iterator[] iterators) { - return new IteratorChain(iterators); + public static Iterator chainedIterator(Iterator[] iterators) { + return new IteratorChain(iterators); } /** @@ -476,8 +480,8 @@ public class IteratorUtils { * @throws NullPointerException if iterators collection is null or contains a null * @throws ClassCastException if the iterators collection contains the wrong object type */ - public static Iterator chainedIterator(Collection iterators) { - return new IteratorChain(iterators); + public static Iterator chainedIterator(Collection> iterators) { + return new IteratorChain(iterators); } // Collated @@ -498,8 +502,8 @@ public class IteratorUtils { * @return a combination iterator over the iterators * @throws NullPointerException if either iterator is null */ - public static Iterator collatedIterator(Comparator comparator, Iterator iterator1, Iterator iterator2) { - return new CollatingIterator(comparator, iterator1, iterator2); + public static Iterator collatedIterator(Comparator comparator, Iterator iterator1, Iterator iterator2) { + return new CollatingIterator(comparator, iterator1, iterator2); } /** @@ -517,8 +521,8 @@ public class IteratorUtils { * @return a combination iterator over the iterators * @throws NullPointerException if iterators array is null or contains a null */ - public static Iterator collatedIterator(Comparator comparator, Iterator[] iterators) { - return new CollatingIterator(comparator, iterators); + public static Iterator collatedIterator(Comparator comparator, Iterator[] iterators) { + return new CollatingIterator(comparator, iterators); } /** @@ -537,8 +541,9 @@ public class IteratorUtils { * @throws NullPointerException if iterators collection is null or contains a null * @throws ClassCastException if the iterators collection contains the wrong object type */ - public static Iterator collatedIterator(Comparator comparator, Collection iterators) { - return new CollatingIterator(comparator, iterators); + public static Iterator collatedIterator(Comparator comparator, + Collection> iterators) { + return new CollatingIterator(comparator, iterators); } // Object Graph @@ -596,8 +601,8 @@ public class IteratorUtils { * @return a new object graph iterator * @since Commons Collections 3.1 */ - public static Iterator objectGraphIterator(Object root, Transformer transformer) { - return new ObjectGraphIterator(root, transformer); + public static Iterator objectGraphIterator(E root, Transformer transformer) { + return new ObjectGraphIterator(root, transformer); } // Transformed @@ -613,14 +618,14 @@ public class IteratorUtils { * @return a new transforming iterator * @throws NullPointerException if either parameter is null */ - public static Iterator transformedIterator(Iterator iterator, Transformer transform) { + public static Iterator transformedIterator(Iterator iterator, Transformer transform) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (transform == null) { throw new NullPointerException("Transformer must not be null"); } - return new TransformIterator(iterator, transform); + return new TransformIterator(iterator, transform); } // Filtered @@ -636,14 +641,14 @@ public class IteratorUtils { * @return a new filtered iterator * @throws NullPointerException if either parameter is null */ - public static Iterator filteredIterator(Iterator iterator, Predicate predicate) { + public static Iterator filteredIterator(Iterator iterator, Predicate predicate) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } - return new FilterIterator(iterator, predicate); + return new FilterIterator(iterator, predicate); } /** @@ -657,14 +662,14 @@ public class IteratorUtils { * @return a new filtered iterator * @throws NullPointerException if either parameter is null */ - public static ListIterator filteredListIterator(ListIterator listIterator, Predicate predicate) { + public static ListIterator filteredListIterator(ListIterator listIterator, Predicate predicate) { if (listIterator == null) { throw new NullPointerException("ListIterator must not be null"); } if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } - return new FilterListIterator(listIterator, predicate); + return new FilterListIterator(listIterator, predicate); } // Looping @@ -680,11 +685,11 @@ public class IteratorUtils { * @return a new looping iterator * @throws NullPointerException if the collection is null */ - public static ResettableIterator loopingIterator(Collection coll) { + public static ResettableIterator loopingIterator(Collection coll) { if (coll == null) { throw new NullPointerException("Collection must not be null"); } - return new LoopingIterator(coll); + return new LoopingIterator(coll); } /** @@ -698,13 +703,13 @@ public class IteratorUtils { * @throws NullPointerException if the list is null * @since Commons Collections 3.2 */ - public static ResettableListIterator loopingListIterator(List list) { + public static ResettableListIterator loopingListIterator(List list) { if (list == null) { throw new NullPointerException("List must not be null"); } - return new LoopingListIterator(list); + return new LoopingListIterator(list); } - + // Views //----------------------------------------------------------------------- /** @@ -713,11 +718,11 @@ public class IteratorUtils { * @param enumeration the enumeration to use * @return a new iterator */ - public static Iterator asIterator(Enumeration enumeration) { + public static Iterator asIterator(Enumeration enumeration) { if (enumeration == null) { throw new NullPointerException("Enumeration must not be null"); } - return new EnumerationIterator(enumeration); + return new EnumerationIterator(enumeration); } /** @@ -728,14 +733,14 @@ public class IteratorUtils { * @param removeCollection the collection to remove elements from * @return a new iterator */ - public static Iterator asIterator(Enumeration enumeration, Collection removeCollection) { + public static Iterator asIterator(Enumeration enumeration, Collection removeCollection) { if (enumeration == null) { throw new NullPointerException("Enumeration must not be null"); } if (removeCollection == null) { throw new NullPointerException("Collection must not be null"); } - return new EnumerationIterator(enumeration, removeCollection); + return new EnumerationIterator(enumeration, removeCollection); } /** @@ -745,11 +750,11 @@ public class IteratorUtils { * @return a new enumeration * @throws NullPointerException if iterator is null */ - public static Enumeration asEnumeration(Iterator iterator) { + public static Enumeration asEnumeration(Iterator iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } - return new IteratorEnumeration(iterator); + return new IteratorEnumeration(iterator); } /** @@ -762,11 +767,11 @@ public class IteratorUtils { * @return a new iterator * @throws NullPointerException if iterator parameter is null */ - public static ListIterator toListIterator(Iterator iterator) { + public static ListIterator toListIterator(Iterator iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } - return new ListIteratorWrapper(iterator); + return new ListIteratorWrapper(iterator); } /** @@ -779,14 +784,14 @@ public class IteratorUtils { * @return an array of the iterator contents * @throws NullPointerException if iterator parameter is null */ - public static Object[] toArray(Iterator iterator) { + public static Object[] toArray(Iterator iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } - List list = toList(iterator, 100); + List list = toList(iterator, 100); return list.toArray(); } - + /** * Gets an array based on an iterator. *

@@ -800,15 +805,16 @@ public class IteratorUtils { * @throws NullPointerException if arrayClass is null * @throws ClassCastException if the arrayClass is invalid */ - public static Object[] toArray(Iterator iterator, Class arrayClass) { + @SuppressWarnings("unchecked") + public static E[] toArray(Iterator iterator, Class arrayClass) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (arrayClass == null) { throw new NullPointerException("Array class must not be null"); } - List list = toList(iterator, 100); - return list.toArray((Object[]) Array.newInstance(arrayClass, list.size())); + List list = toList(iterator, 100); + return list.toArray((E[]) Array.newInstance(arrayClass, list.size())); } /** @@ -821,10 +827,10 @@ public class IteratorUtils { * @return a list of the iterator contents * @throws NullPointerException if iterator parameter is null */ - public static List toList(Iterator iterator) { + public static List toList(Iterator iterator) { return toList(iterator, 10); } - + /** * Gets a list based on an iterator. *

@@ -837,14 +843,14 @@ public class IteratorUtils { * @throws NullPointerException if iterator parameter is null * @throws IllegalArgumentException if the size is less than 1 */ - public static List toList(Iterator iterator, int estimatedSize) { + public static List toList(Iterator iterator, int estimatedSize) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (estimatedSize < 1) { throw new IllegalArgumentException("Estimated size must be greater than 0"); } - List list = new ArrayList(estimatedSize); + List list = new ArrayList(estimatedSize); while (iterator.hasNext()) { list.add(iterator.next()); } @@ -854,7 +860,7 @@ public class IteratorUtils { /** * Gets a suitable Iterator for the given object. *

- * This method can handles objects as follows + * This method can handle objects as follows *