Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/listeners/SWTListenerWrapperDelegate.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/NewNameDialogBuilder.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF36
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/Deque.java34
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/InputRestrictedDeque.java59
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/OutputRestrictedDeque.java53
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java38
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/NameTools.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Range.java2
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/AbstractRepeatingElementList.java15
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java667
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayQueue.java139
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/HashBag.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/IdentityHashBag.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java153
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java172
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/NullList.java14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/PriorityQueue.java62
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/QueueTools.java403
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedBag.java16
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandContext.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandContext.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandContext.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractArrayDeque.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayQueue.java)153
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractPriorityDeque.java396
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ArrayDeque.java85
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/DequeTools.java799
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/EmptyDeque.java74
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityArrayDeque.java76
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityPriorityDeque.java69
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/LinkedDeque.java321
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ListDeque.java98
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/PriorityDeque.java87
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ReverseDeque.java77
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/SynchronizedDeque.java984
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/enumeration/EnumerationTools.java18
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ChainIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeListIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/FilteringIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/GraphIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java22
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/QueueIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ReadOnlyCompositeListIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/StackIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationListIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TreeIterable.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/CloneListIterator.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java42
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/QueueIterator.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/ReverseIterator.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/StackIterator.java5
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java20
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTPropertyChangeListenerWrapper.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTStateChangeListenerWrapper.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractTreeNodeValueModel.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ExtendedListValueModelWrapper.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemAspectListValueModelAdapter.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/AbstractArrayQueue.java172
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ArrayQueue.java78
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/DequeQueue.java69
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/EmptyQueue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyQueue.java)4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/FixedCapacityArrayQueue.java65
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/LinkedQueue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedQueue.java)14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ListQueue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListQueue.java)4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/PriorityQueue.java249
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/QueueTools.java534
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/StackQueue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackQueue.java)6
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/SynchronizedQueue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedQueue.java)262
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ArrayStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayStack.java)67
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/DequeStack.java77
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/EmptyStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyStack.java)4
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/FixedCapacityArrayStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayStack.java)35
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/LinkedStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedStack.java)14
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ListStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListStack.java)11
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/StackTools.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackTools.java)279
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/SynchronizedStack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedStack.java)276
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/queue/Queue.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Queue.java)12
-rw-r--r--common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/stack/Stack.java (renamed from common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Stack.java)10
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/TreeContentProviderUiTest.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/AbstractRepeatingElementListTests.java26
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/BagTests.java811
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/CollectionToolsTests.java247
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/EmptyBagTests.java84
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/HashBagTests.java511
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashBagTests.java320
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashSetTests.java44
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java14
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedQueueTests.java108
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedStackTests.java108
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListToolsTests.java461
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/MapToolsTests.java217
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/NullListTests.java247
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/SynchronizedBagTests.java78
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/SynchronizedQueueTests.java260
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/SynchronizedStackTests.java260
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/TightMapTests.java124
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/AbstractPriorityDequeTests.java370
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/ArrayDequeTests.java366
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/DequeTests.java290
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/DequeToolsTests.java832
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/EmptyDequeTests.java113
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/FixedCapacityArrayDequeTests.java341
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/FixedCapacityPriorityDequeTests.java108
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/JptCommonUtilityDequeTests.java41
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/LinkedDequeTests.java263
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/ListDequeTests.java32
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/PriorityDequeTests.java121
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/ReverseDequeTests.java282
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/deque/SynchronizedDequeTests.java1255
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/eol/CheckWinEOL.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/io/FileToolsTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/iterable/GraphIterableTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/iterable/QueueIterableTests.java7
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/iterable/StackIterableTests.java7
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/iterator/GraphIteratorTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/iterator/ReadOnlyCompositeListIteratorTests.java6
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionAspectAdapterTests.java28
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java8
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java34
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java8
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListAspectAdapterTests.java42
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java26
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/ListCuratorTests.java36
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyListValueModelAdapterTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/SetCollectionValueModelTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/SimpleListValueModelTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/SortedListValueModelWrapperTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticCollectionValueModelTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/StaticListValueModelTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/TransformationListValueModelTests.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TableModelAdapterTests.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java4
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/ArrayQueueTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ArrayQueueTests.java)68
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/DequeQueueTests.java32
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/EmptyQueueTests.java76
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/FixedCapacityArrayQueueTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/FixedSizeArrayQueueTests.java)20
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/JptCommonUtilityQueueTests.java41
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/LinkedQueueTests.java230
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/ListQueueTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListQueueTests.java)6
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/PriorityQueueTests.java444
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/QueueTests.java)15
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/QueueToolsTests.java506
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/StackQueueTests.java163
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/queue/SynchronizedQueueTests.java793
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ArrayStackTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ArrayStackTests.java)59
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/DequeStackTests.java32
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/EmptyStackTests.java77
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/FixedCapacityArrayStackTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/FixedSizeArrayStackTests.java)38
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/JptCommonUtilityStackTests.java39
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/LinkedStackTests.java214
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/ListStackTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListStackTests.java)8
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackTests.java (renamed from common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/StackTests.java)23
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/StackToolsTests.java465
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/stack/SynchronizedStackTests.java792
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/AbstractJaxbNode.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/SchemaLibraryImpl.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/AbstractJaxbContextRoot.java22
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/ContextContainerTools.java11
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaAttributesContainer.java22
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaClassMapping.java10
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaXmlNs.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/ELJaxbContextRootImpl.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.eclipselink.core/src/org/eclipse/jpt/jaxb/eclipselink/core/internal/context/java/ELJavaXmlJoinNode.java4
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.ui/src/org/eclipse/jpt/jaxb/ui/internal/properties/JaxbSchemasPropertiesPage.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/AbstractJpaContextModel.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/ContextContainerTools.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/SpecifiedOrmPersistentType.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java16
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/facet/JpaFacetDataModelProvider.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericContextRoot.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTableGenerator.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTableGenerator.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/GenericMetamodelSynchronizer2_0.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/context/java/GenericJavaNamedStoredProcedureQuery2_1.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2_1/context/orm/GenericOrmNamedStoredProcedureQuery2_1.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/jpql/spi/JpaMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/EclipseLinkJavaObjectTypeConverter.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/EclipseLinkOrmObjectTypeConverter.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/persistence/EclipseLinkCustomization.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/details/EclipseLinkConversionValueDialog.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/customization/EclipseLinkProfilerClassChooser.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/options/EclipseLinkLoggerClassChooser.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/src/org/eclipse/jpt/jpa/eclipselink/ui/internal/persistence/options/EclipseLinkPersistenceUnitOptionsEditorPage.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaJavaCompletionProposalComputer.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JpaXmlCompletionProposalComputer.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/BaseJoinColumnStateObject.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/JoinColumnInJoiningStrategyStateObject.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/TemporalTypeCombo.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/properties/JpaProjectPropertiesPage.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/DatabaseGroup.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/gen/TablesSelectorWizardPage.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/java/JavaAttributeOverrideTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmSecondaryTableTests.java4
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/jpa2/context/persistence/Generic2_0JpaMetadataConversionTests.java6
-rw-r--r--jpa/tests/org.eclipse.jpt.jpa.eclipselink.core.tests/src/org/eclipse/jpt/jpa/eclipselink/core/tests/internal/context/persistence/EclipseLink2_2JpaMetadataConversionTests.java4
220 files changed, 16874 insertions, 4048 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
index b2af0c2b43..52ceef8163 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/libval/LibraryValidatorTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -76,7 +76,7 @@ public class LibraryValidatorTools {
private static IStatus validateClassesInLibraries(Iterable<IPath> libraryPaths, Iterable<String> classNames) {
HashMap<String, Boolean> flags = new HashMap<String, Boolean>();
HashMap<String, String> classFileNameToClassName = new HashMap<String, String>();
- for (String className : CollectionTools.set(classNames)) {
+ for (String className : CollectionTools.hashSet(classNames)) {
String classFileName = className.replace('.', '/') + ".class"; //$NON-NLS-1$
flags.put(classFileName, Boolean.FALSE);
classFileNameToClassName.put(classFileName, className);
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java
index a8e9073dc9..fb346a6258 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -57,7 +57,7 @@ final class BinaryPackageFragment
private Collection<JavaResourceClassFile> buildClassFiles() {
IJavaElement[] children = this.getJDTChildren();
ArrayList<JavaResourceClassFile> result = new ArrayList<JavaResourceClassFile>(children.length);
- Collection<String> annotationNames = CollectionTools.collection(this.getAnnotationProvider().getAnnotationNames());
+ Collection<String> annotationNames = CollectionTools.hashBag(this.getAnnotationProvider().getAnnotationNames());
for (IJavaElement child : children) {
IClassFile jdtClassFile = (IClassFile) child;
IType jdtType = jdtClassFile.getType();
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/listeners/SWTListenerWrapperDelegate.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/listeners/SWTListenerWrapperDelegate.java
index fb4eaef299..4a8aabda14 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/listeners/SWTListenerWrapperDelegate.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/listeners/SWTListenerWrapperDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,7 +14,8 @@ import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools;
import org.eclipse.jpt.common.utility.exception.ExceptionHandler;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
-import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
+import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
+import org.eclipse.jpt.common.utility.internal.queue.SynchronizedQueue;
import org.eclipse.swt.widgets.Display;
/**
@@ -36,7 +37,7 @@ final class SWTListenerWrapperDelegate<E extends EventObject> {
private final Display display;
private final Runnable forwardEventsRunnable = new ForwardEventsRunnable();
private final ExceptionHandler exceptionHandler;
- private final SynchronizedQueue<E> events = new SynchronizedQueue<E>();
+ private final SynchronizedQueue<E> events = QueueTools.synchronizedQueue();
SWTListenerWrapperDelegate(Wrapper<E> wrapper, Display display, ExceptionHandler exceptionHandler) {
diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/NewNameDialogBuilder.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/NewNameDialogBuilder.java
index f06df8851d..47bb464a29 100644
--- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/NewNameDialogBuilder.java
+++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/widgets/NewNameDialogBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -145,7 +145,7 @@ public final class NewNameDialogBuilder {
* @param names The collection of names that can't be used
*/
public void setExistingNames(Iterator<String> names) {
- this.names = CollectionTools.collection(names);
+ this.names = CollectionTools.hashBag(names);
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
index 4836dae3a4..3815dfdfb9 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
+++ b/common/plugins/org.eclipse.jpt.common.utility/META-INF/MANIFEST.MF
@@ -14,6 +14,7 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.common.utility.closure,
org.eclipse.jpt.common.utility.collection,
org.eclipse.jpt.common.utility.command,
+ org.eclipse.jpt.common.utility.deque,
org.eclipse.jpt.common.utility.exception,
org.eclipse.jpt.common.utility.factory,
org.eclipse.jpt.common.utility.internal;
@@ -73,6 +74,17 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.jpa.gen,
org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.utility.internal.deque;
+ x-friends:="org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.ui,
+ org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.enumeration;
x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
@@ -225,6 +237,17 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.jpa.gen,
org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.utility.internal.queue;
+ x-friends:="org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.ui,
+ org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.reference;
x-friends:="org.eclipse.jpt.common.core,
org.eclipse.jpt.common.ui,
@@ -236,6 +259,17 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.jpa.gen,
org.eclipse.jpt.jpa.annotate,
org.eclipse.jpt.jpa.ui",
+ org.eclipse.jpt.common.utility.internal.stack;
+ x-friends:="org.eclipse.jpt.common.core,
+ org.eclipse.jpt.common.ui,
+ org.eclipse.jpt.jaxb.core,
+ org.eclipse.jpt.jaxb.ui,
+ org.eclipse.jpt.jpa.core,
+ org.eclipse.jpt.jpa.db,
+ org.eclipse.jpt.jpa.db.ui,
+ org.eclipse.jpt.jpa.gen,
+ org.eclipse.jpt.jpa.annotate,
+ org.eclipse.jpt.jpa.ui",
org.eclipse.jpt.common.utility.internal.swing;
x-friends:="org.eclipse.jpt.common.ui,
org.eclipse.jpt.jaxb.ui,
@@ -260,5 +294,7 @@ Export-Package: org.eclipse.jpt.common.utility,
org.eclipse.jpt.common.utility.model.value,
org.eclipse.jpt.common.utility.node,
org.eclipse.jpt.common.utility.predicate,
+ org.eclipse.jpt.common.utility.queue,
org.eclipse.jpt.common.utility.reference,
+ org.eclipse.jpt.common.utility.stack,
org.eclipse.jpt.common.utility.transformer
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/Deque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/Deque.java
new file mode 100644
index 0000000000..4283b32f11
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/Deque.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.deque;
+
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Interface defining the classic double-ended queue behavior,
+ * without the backdoors allowed by {@link java.util.Deque}.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @param <E> the type of elements contained by the deque
+ * @see org.eclipse.jpt.common.utility.internal.deque.ArrayDeque
+ * @see org.eclipse.jpt.common.utility.internal.deque.LinkedDeque
+ * @see org.eclipse.jpt.common.utility.internal.deque.DequeTools
+ * @see Queue Queue - for an interface without the semantic baggage of {@link java.util.Queue}
+ */
+public interface Deque<E>
+ extends InputRestrictedDeque<E>, OutputRestrictedDeque<E>
+{
+ // combine the "restricted" interfaces
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/InputRestrictedDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/InputRestrictedDeque.java
new file mode 100644
index 0000000000..b15cb365fd
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/InputRestrictedDeque.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.deque;
+
+/**
+ * Interface defining a input-restricted double-ended queue.
+ * Elements can be removed from either end of the queue,
+ * but added to only the tail of the queue.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @param <E> the type of elements contained by the deque
+ * @see Deque
+ */
+public interface InputRestrictedDeque<E> {
+
+ /**
+ * "Enqueue" the specified item to the tail of the deque.
+ */
+ void enqueueTail(E element);
+
+ /**
+ * "Dequeue" an item from the head of the deque.
+ */
+ E dequeueHead();
+
+ /**
+ * "Dequeue" an item from the tail of the deque.
+ */
+ E dequeueTail();
+
+ /**
+ * Return the item on the head of the deque
+ * without removing it from the deque.
+ */
+ E peekHead();
+
+ /**
+ * Return the item on the tail of the deque
+ * without removing it from the deque.
+ */
+ E peekTail();
+
+ /**
+ * Return whether the deque is empty.
+ */
+ boolean isEmpty();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/OutputRestrictedDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/OutputRestrictedDeque.java
new file mode 100644
index 0000000000..b2a42dca96
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/deque/OutputRestrictedDeque.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.deque;
+
+/**
+ * Interface defining a output-restricted double-ended queue.
+ * Elements can be added to either end of the queue,
+ * but removed from only the head of the queue.
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @param <E> the type of elements contained by the deque
+ * @see Deque
+ */
+public interface OutputRestrictedDeque<E> {
+
+ /**
+ * "Enqueue" the specified item to the head of the queue.
+ */
+ void enqueueHead(E element);
+
+ /**
+ * "Enqueue" the specified item to the tail of the deque.
+ */
+ void enqueueTail(E element);
+
+ /**
+ * "Dequeue" an item from the head of the deque.
+ */
+ E dequeueHead();
+
+ /**
+ * Return the item on the head of the deque
+ * without removing it from the deque.
+ */
+ E peekHead();
+
+ /**
+ * Return whether the deque is empty.
+ */
+ boolean isEmpty();
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java
index 7e09f76b44..7a7b1a0dd4 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ArrayTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -160,7 +160,7 @@ public final class ArrayTools {
*/
public static Object[] array(Iterator<?> iterator) {
return iterator.hasNext() ?
- ListTools.list(iterator).toArray() :
+ ListTools.arrayList(iterator).toArray() :
ObjectTools.EMPTY_OBJECT_ARRAY;
}
@@ -171,7 +171,7 @@ public final class ArrayTools {
*/
public static Object[] array(Iterator<?> iterator, int iteratorSize) {
return iterator.hasNext() ?
- ListTools.list(iterator, iteratorSize).toArray() :
+ ListTools.arrayList(iterator, iteratorSize).toArray() :
ObjectTools.EMPTY_OBJECT_ARRAY;
}
@@ -183,7 +183,7 @@ public final class ArrayTools {
public static <E> E[] array(Iterator<?> iterator, Class<E> componentType) {
E[] array = newInstance(componentType, 0);
return iterator.hasNext() ?
- ListTools.list(iterator).toArray(array) :
+ ListTools.arrayList(iterator).toArray(array) :
array;
}
@@ -195,7 +195,7 @@ public final class ArrayTools {
*/
public static <E> E[] array(Iterator<?> iterator, int iteratorSize, Class<E> componentType) {
return iterator.hasNext() ?
- ListTools.list(iterator, iteratorSize).toArray(newInstance(componentType, iteratorSize)) :
+ ListTools.arrayList(iterator, iteratorSize).toArray(newInstance(componentType, iteratorSize)) :
newInstance(componentType, 0);
}
@@ -209,7 +209,7 @@ public final class ArrayTools {
*/
public static <E> E[] array(Iterator<? extends E> iterator, E[] array) {
return iterator.hasNext() ?
- ListTools.list(iterator).toArray(array) :
+ ListTools.arrayList(iterator).toArray(array) :
emptyArray(array);
}
@@ -224,7 +224,7 @@ public final class ArrayTools {
*/
public static <E> E[] array(Iterator<? extends E> iterator, int iteratorSize, E[] array) {
return iterator.hasNext() ?
- ListTools.list(iterator, iteratorSize).toArray(array) :
+ ListTools.arrayList(iterator, iteratorSize).toArray(array) :
emptyArray(array);
}
@@ -423,7 +423,7 @@ public final class ArrayTools {
* in the specified iterator.
*/
public static <E> E[] addAll(E[] array, Iterator<? extends E> iterator) {
- return iterator.hasNext() ? addAll_(array, ListTools.list(iterator)) : array;
+ return iterator.hasNext() ? addAll_(array, ListTools.arrayList(iterator)) : array;
}
/**
@@ -433,7 +433,7 @@ public final class ArrayTools {
* The specified iterator size is a performance hint.
*/
public static <E> E[] addAll(E[] array, Iterator<? extends E> iterator, int iteratorSize) {
- return iterator.hasNext() ? addAll_(array, ListTools.list(iterator, iteratorSize)) : array;
+ return iterator.hasNext() ? addAll_(array, ListTools.arrayList(iterator, iteratorSize)) : array;
}
/**
@@ -597,7 +597,7 @@ public final class ArrayTools {
* in the specified iterator inserted at the specified index.
*/
public static <E> E[] addAll(E[] array, int index, Iterator<? extends E> iterator) {
- return iterator.hasNext() ? addAll_(array, index, ListTools.list(iterator)) : array;
+ return iterator.hasNext() ? addAll_(array, index, ListTools.arrayList(iterator)) : array;
}
/**
@@ -607,7 +607,7 @@ public final class ArrayTools {
* The specified iterator size is a performance hint.
*/
public static <E> E[] addAll(E[] array, int index, Iterator<? extends E> iterator, int iteratorSize) {
- return iterator.hasNext() ? addAll_(array, index, ListTools.list(iterator, iteratorSize)) : array;
+ return iterator.hasNext() ? addAll_(array, index, ListTools.arrayList(iterator, iteratorSize)) : array;
}
/**
@@ -1025,7 +1025,7 @@ public final class ArrayTools {
*/
public static boolean containsAll(Object[] array, Iterator<?> iterator) {
// use hashed lookup
- HashSet<Object> set = CollectionTools.set(array);
+ HashSet<Object> set = CollectionTools.hashSet(array);
while (iterator.hasNext()) {
if ( ! set.contains(iterator.next())) {
return false;
@@ -1040,7 +1040,7 @@ public final class ArrayTools {
*/
public static boolean containsAll(Object[] array1, Object... array2) {
// use hashed lookup
- HashSet<Object> set = CollectionTools.set(array1);
+ HashSet<Object> set = CollectionTools.hashSet(array1);
for (int i = array2.length; i-- > 0; ) {
if ( ! set.contains(array2[i])) {
return false;
@@ -2054,7 +2054,7 @@ public final class ArrayTools {
*/
public static <E> E[] removeAll(E[] array, Iterator<?> iterator) {
// convert to a set to take advantage of hashed look-up
- return iterator.hasNext() ? removeAll_(array, CollectionTools.set(iterator)) : array;
+ return iterator.hasNext() ? removeAll_(array, CollectionTools.hashSet(iterator)) : array;
}
/**
@@ -2064,7 +2064,7 @@ public final class ArrayTools {
*/
public static <E> E[] removeAll(E[] array, Iterator<?> iterator, int iteratorSize) {
// convert to a set to take advantage of hashed look-up
- return iterator.hasNext() ? removeAll_(array, CollectionTools.set(iterator, iteratorSize)) : array;
+ return iterator.hasNext() ? removeAll_(array, CollectionTools.hashSet(iterator, iteratorSize)) : array;
}
/**
@@ -2118,7 +2118,7 @@ public final class ArrayTools {
*/
public static <E> E[] removeAll(E[] array1, Object... array2) {
// convert to a set to take advantage of hashed look-up
- return (array2.length == 0) ? array1 : removeAll_(array1, CollectionTools.set(array2));
+ return (array2.length == 0) ? array1 : removeAll_(array1, CollectionTools.hashSet(array2));
}
/**
@@ -2553,7 +2553,7 @@ public final class ArrayTools {
*/
private static <E> E[] retainAll(E[] array, int arrayLength, Iterator<?> iterator) {
return iterator.hasNext() ?
- retainAll_(array, CollectionTools.set(iterator), arrayLength) :
+ retainAll_(array, CollectionTools.hashSet(iterator), arrayLength) :
newInstance(array, 0);
}
@@ -2562,7 +2562,7 @@ public final class ArrayTools {
*/
private static <E> E[] retainAll(E[] array, int arrayLength, Iterator<?> iterator, int iteratorSize) {
return iterator.hasNext() ?
- retainAll_(array, CollectionTools.set(iterator, iteratorSize), arrayLength) :
+ retainAll_(array, CollectionTools.hashSet(iterator, iteratorSize), arrayLength) :
newInstance(array, 0);
}
@@ -2616,7 +2616,7 @@ public final class ArrayTools {
array1 :
(array2.length == 0) ?
newInstance(array1, 0) :
- retainAll(array1, CollectionTools.set(array2), array1Length);
+ retainAll(array1, CollectionTools.hashSet(array2), array1Length);
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/NameTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/NameTools.java
index 5167b26185..ff08df4810 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/NameTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/NameTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -28,7 +28,7 @@ public final class NameTools {
* @see #uniqueName(String, Collection)
*/
public static String uniqueName(String rootName, Iterable<String> existingNames) {
- return uniqueName(rootName, CollectionTools.set(existingNames));
+ return uniqueName(rootName, CollectionTools.hashSet(existingNames));
}
/**
@@ -46,7 +46,7 @@ public final class NameTools {
* @see #uniqueNameIgnoreCase(String, Collection)
*/
public static String uniqueNameIgnoreCase(String rootName, Iterable<String> existingNames) {
- return uniqueNameIgnoreCase(rootName, CollectionTools.set(existingNames));
+ return uniqueNameIgnoreCase(rootName, CollectionTools.hashSet(existingNames));
}
/**
@@ -193,7 +193,7 @@ public final class NameTools {
* Java Language Keywords</a>
*/
public static final SortedSet<String> JAVA_RESERVED_WORDS =
- Collections.unmodifiableSortedSet(CollectionTools.sortedSet(JAVA_RESERVED_WORDS_ARRAY));
+ Collections.unmodifiableSortedSet(CollectionTools.treeSet(JAVA_RESERVED_WORDS_ARRAY));
/**
* Return whether the specified string consists of Java identifier
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Range.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Range.java
index c52a936cf5..756a823e59 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Range.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/Range.java
@@ -43,7 +43,7 @@ public class Range
/**
* Construct a range with the specified start and end, both of which are
- * mmutable. If the specified end is less than the specified start, the
+ * immutable. If the specified end is less than the specified start, the
* values will be swapped in the range.
*/
public Range(int start, int end) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/AbstractRepeatingElementList.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/AbstractRepeatingElementList.java
index 47287f3ff3..fa93b49112 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/AbstractRepeatingElementList.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/AbstractRepeatingElementList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,7 +14,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
-
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
@@ -217,7 +216,17 @@ public abstract class AbstractRepeatingElementList<E>
@Override
public String toString() {
- return ObjectTools.toString(this, this.size);
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (int i = this.size; i-- > 0; ) {
+ sb.append(this.getElement());
+ sb.append(", "); //$NON-NLS-1$
+ }
+ if (sb.length() > 1) {
+ sb.setLength(sb.length() - 2);
+ }
+ sb.append(']');
+ return sb.toString();
}
private static final long serialVersionUID = 1L;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java
index cd51bb3d59..a1f52a2862 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,12 +16,9 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.TreeSet;
import java.util.Vector;
import org.eclipse.jpt.common.utility.collection.Bag;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.predicate.Predicate;
import org.eclipse.jpt.common.utility.transformer.Transformer;
@@ -67,11 +64,11 @@ public final class CollectionTools {
/**
* assume the iterator is not empty
*/
- private static <E> boolean addAll_(Collection<? super E> collection, Iterator<? extends E> iterator) {
+ /* package */ static <E> boolean addAll_(Collection<? super E> collection, Iterator<? extends E> iterator) {
boolean modified = false;
- while (iterator.hasNext()) {
+ do {
modified |= collection.add(iterator.next());
- }
+ } while (iterator.hasNext());
return modified;
}
@@ -82,7 +79,7 @@ public final class CollectionTools {
* The specified iterator size is a performance hint.
*/
public static <E> boolean addAll(Collection<? super E> collection, Iterator<? extends E> iterator, int iteratorSize) {
- return iterator.hasNext() && collection.addAll(ListTools.list(iterator, iteratorSize));
+ return iterator.hasNext() && collection.addAll(ListTools.arrayList(iterator, iteratorSize));
}
/**
@@ -91,69 +88,20 @@ public final class CollectionTools {
* Return whether the collection changed as a result.
*/
public static <E> boolean addAll(Collection<? super E> collection, E... array) {
- return (array.length != 0) && collection.addAll(Arrays.asList(array));
+ return (array.length != 0) && addAll_(collection, array);
}
/**
- * Dequeue all the elements from the specified queue and add them
- * to the specified collection.
- * Return whether the collection changed as a result.
+ * assume the array is not empty
*/
- public static <E> boolean addAll(Collection<? super E> collection, Queue<? extends E> queue) {
- return ( ! queue.isEmpty()) && addAll_(collection, queue);
- }
-
- /**
- * assume the queue is not empty
- */
- private static <E> boolean addAll_(Collection<? super E> collection, Queue<? extends E> queue) {
+ private static <E> boolean addAll_(Collection<? super E> collection, E... array) {
boolean modified = false;
- while ( ! queue.isEmpty()) {
- modified |= collection.add(queue.dequeue());
+ for (E element : array) {
+ modified |= collection.add(element);
}
return modified;
}
- /**
- * Dequeue all the elements from the specified queue and add them
- * to the specified collection.
- * Return whether the collection changed as a result.
- * The specified queue size is a performance hint.
- */
- public static <E> boolean addAll(Collection<? super E> collection, Queue<? extends E> queue, int queueSize) {
- return ( ! queue.isEmpty()) && collection.addAll(ListTools.list(queue, queueSize));
- }
-
- /**
- * Pop all the elements from the specified stack and add them
- * to the specified collection.
- * Return whether the collection changed as a result.
- */
- public static <E> boolean addAll(Collection<? super E> collection, Stack<? extends E> stack) {
- return ( ! stack.isEmpty()) && addAll_(collection, stack);
- }
-
- /**
- * assume the stack is not empty
- */
- private static <E> boolean addAll_(Collection<? super E> collection, Stack<? extends E> stack) {
- boolean modified = false;
- while ( ! stack.isEmpty()) {
- modified |= collection.add(stack.pop());
- }
- return modified;
- }
-
- /**
- * Pop all the elements from the specified stack and add them
- * to the specified collection.
- * Return whether the collection changed as a result.
- * The specified stack size is a performance hint.
- */
- public static <E> boolean addAll(Collection<? super E> collection, Stack<? extends E> stack, int stackSize) {
- return ( ! stack.isEmpty()) && collection.addAll(ListTools.list(stack, stackSize));
- }
-
// ********** contains all **********
@@ -192,34 +140,6 @@ public final class CollectionTools {
return true;
}
- /**
- * Return whether the specified collection contains all of the
- * elements in the specified queue, dequeueing elements from the queue
- * until one is not found in the collection.
- */
- public static boolean containsAll(Collection<?> collection, Queue<?> queue) {
- while ( ! queue.isEmpty()) {
- if ( ! collection.contains(queue.dequeue())) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Return whether the specified collection contains all of the
- * elements in the specified stack, popping elements from the stack
- * until one is not found in the collection.
- */
- public static boolean containsAll(Collection<?> collection, Stack<?> stack) {
- while ( ! stack.isEmpty()) {
- if ( ! collection.contains(stack.pop())) {
- return false;
- }
- }
- return true;
- }
-
// ********** filter **********
@@ -228,7 +148,7 @@ public final class CollectionTools {
* elements of the specified collection.
*/
public static <E> HashBag<E> filter(Collection<? extends E> collection, Predicate<? super E> filter) {
- HashBag<E> result = new HashBag<E>(collection.size());
+ HashBag<E> result = hashBag(collection.size());
for (E e : collection) {
if (filter.evaluate(e)) {
result.add(e);
@@ -314,7 +234,7 @@ public final class CollectionTools {
* Return whether the collection changed as a result.
*/
public static boolean removeAll(Collection<?> collection, Iterator<?> iterator) {
- return iterator.hasNext() && collection.removeAll(set(iterator));
+ return iterator.hasNext() && collection.removeAll(hashSet(iterator));
}
/**
@@ -324,7 +244,7 @@ public final class CollectionTools {
* The specified iterator size is a performance hint.
*/
public static boolean removeAll(Collection<?> collection, Iterator<?> iterator, int iteratorSize) {
- return iterator.hasNext() && collection.removeAll(set(iterator, iteratorSize));
+ return iterator.hasNext() && collection.removeAll(hashSet(iterator, iteratorSize));
}
/**
@@ -333,45 +253,7 @@ public final class CollectionTools {
* Return whether the collection changed as a result.
*/
public static boolean removeAll(Collection<?> collection, Object... array) {
- return (array.length != 0) && collection.removeAll(set(array));
- }
-
- /**
- * Remove all the elements dequeued from the specified queue
- * from the specified collection, draining the queue in the process.
- * Return whether the collection changed as a result.
- */
- public static boolean removeAll(Collection<?> collection, Queue<?> queue) {
- return ( ! queue.isEmpty()) && collection.removeAll(set(queue));
- }
-
- /**
- * Remove all the elements dequeued from the specified queue
- * from the specified collection, draining the queue in the process.
- * Return whether the collection changed as a result.
- * The specified queue size is a performance hint.
- */
- public static boolean removeAll(Collection<?> collection, Queue<?> queue, int queueSize) {
- return ( ! queue.isEmpty()) && collection.removeAll(set(queue, queueSize));
- }
-
- /**
- * Remove all the elements from the specified stack
- * from the specified collection, draining the stack in the process.
- * Return whether the collection changed as a result.
- */
- public static boolean removeAll(Collection<?> collection, Stack<?> stack) {
- return ( ! stack.isEmpty()) && collection.removeAll(set(stack));
- }
-
- /**
- * Remove all the elements from the specified stack
- * from the specified collection, draining the stack in the process.
- * Return whether the collection changed as a result.
- * The specified stack size is a performance hint.
- */
- public static boolean removeAll(Collection<?> collection, Stack<?> stack, int stackSize) {
- return ( ! stack.isEmpty()) && collection.removeAll(set(stack, stackSize));
+ return (array.length != 0) && collection.removeAll(hashSet(array));
}
@@ -432,7 +314,7 @@ public final class CollectionTools {
*/
public static boolean retainAll(Collection<?> collection, Iterator<?> iterator) {
if (iterator.hasNext()) {
- return collection.retainAll(set(iterator));
+ return collection.retainAll(hashSet(iterator));
}
if (collection.isEmpty()) {
return false;
@@ -449,7 +331,7 @@ public final class CollectionTools {
*/
public static boolean retainAll(Collection<?> collection, Iterator<?> iterator, int iteratorSize) {
if (iterator.hasNext()) {
- return collection.retainAll(set(iterator, iteratorSize));
+ return collection.retainAll(hashSet(iterator, iteratorSize));
}
if (collection.isEmpty()) {
return false;
@@ -465,73 +347,7 @@ public final class CollectionTools {
*/
public static boolean retainAll(Collection<?> collection, Object... array) {
if (array.length > 0) {
- return collection.retainAll(set(array));
- }
- if (collection.isEmpty()) {
- return false;
- }
- collection.clear();
- return true;
- }
-
- /**
- * Retain only the elements in the specified queue
- * in the specified collection, draining the queue in the process.
- * Return whether the collection changed as a result.
- */
- public static boolean retainAll(Collection<?> collection, Queue<?> queue) {
- if ( ! queue.isEmpty()) {
- return collection.retainAll(set(queue));
- }
- if (collection.isEmpty()) {
- return false;
- }
- collection.clear();
- return true;
- }
-
- /**
- * Retain only the elements in the specified queue
- * in the specified collection, draining the queue in the process.
- * Return whether the collection changed as a result.
- * The specified queue size is a performance hint.
- */
- public static boolean retainAll(Collection<?> collection, Queue<?> queue, int queueSize) {
- if ( ! queue.isEmpty()) {
- return collection.retainAll(set(queue, queueSize));
- }
- if (collection.isEmpty()) {
- return false;
- }
- collection.clear();
- return true;
- }
-
- /**
- * Retain only the elements in the specified stack
- * in the specified collection, draining the stack in the process.
- * Return whether the collection changed as a result.
- */
- public static boolean retainAll(Collection<?> collection, Stack<?> stack) {
- if ( ! stack.isEmpty()) {
- return collection.retainAll(set(stack));
- }
- if (collection.isEmpty()) {
- return false;
- }
- collection.clear();
- return true;
- }
-
- /**
- * Retain only the elements in the specified stack
- * in the specified collection, draining the stack in the process.
- * Return whether the collection changed as a result.
- * The specified stack size is a performance hint.
- */
- public static boolean retainAll(Collection<?> collection, Stack<?> stack, int stackSize) {
- if ( ! stack.isEmpty()) {
- return collection.retainAll(set(stack, stackSize));
+ return collection.retainAll(hashSet(array));
}
if (collection.isEmpty()) {
return false;
@@ -561,7 +377,7 @@ public final class CollectionTools {
* elements in the specified collection.
*/
public static <E1, E2> HashBag<E2> transform(Collection<E1> collection, Transformer<? super E1, ? extends E2> transformer) {
- HashBag<E2> result = new HashBag<E2>(collection.size());
+ HashBag<E2> result = hashBag(collection.size());
for (E1 e : collection) {
result.add(transformer.transform(e));
}
@@ -569,39 +385,63 @@ public final class CollectionTools {
}
- // ********** bag factory methods **********
+ // ********** hash bag factory methods **********
+
+ /**
+ * Return a new hash bag.
+ */
+ public static <E> HashBag<E> hashBag() {
+ return new HashBag<E>();
+ }
+
+ /**
+ * Return a new hash bag with the specified initial capacity.
+ */
+ public static <E> HashBag<E> hashBag(int initialCapacity) {
+ return new HashBag<E>(initialCapacity);
+ }
+
+ /**
+ * Return a new hash bag with the specified initial capacity
+ * and load factor.
+ */
+ public static <E> HashBag<E> hashBag(int initialCapacity, float loadFactor) {
+ return new HashBag<E>(initialCapacity, loadFactor);
+ }
/**
- * Return a bag corresponding to the specified iterable.
+ * Return a new hash bag corresponding to the specified iterable.
*/
- public static <E> HashBag<E> bag(Iterable<? extends E> iterable) {
- return bag(iterable.iterator());
+ public static <E> HashBag<E> hashBag(Iterable<? extends E> iterable) {
+ return hashBag(iterable.iterator());
}
/**
- * Return a bag corresponding to the specified iterable.
+ * Return a new hash bag corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E> HashBag<E> bag(Iterable<? extends E> iterable, int iterableSize) {
- return bag(iterable.iterator(), iterableSize);
+ public static <E> HashBag<E> hashBag(Iterable<? extends E> iterable, int iterableSize) {
+ return hashBag(iterable.iterator(), iterableSize);
}
/**
- * Return a bag corresponding to the specified iterator.
+ * Return a new hash bag corresponding to the specified iterator.
*/
- public static <E> HashBag<E> bag(Iterator<? extends E> iterator) {
- return bag(iterator, new HashBag<E>());
+ public static <E> HashBag<E> hashBag(Iterator<? extends E> iterator) {
+ HashBag<E> bag = hashBag();
+ return hashBag(iterator, bag);
}
/**
- * Return a bag corresponding to the specified iterator.
+ * Return a new hash bag corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E> HashBag<E> bag(Iterator<? extends E> iterator, int iteratorSize) {
- return bag(iterator, new HashBag<E>(iteratorSize));
+ public static <E> HashBag<E> hashBag(Iterator<? extends E> iterator, int iteratorSize) {
+ HashBag<E> bag = hashBag(iteratorSize);
+ return hashBag(iterator, bag);
}
- private static <E> HashBag<E> bag(Iterator<? extends E> iterator, HashBag<E> bag) {
+ private static <E> HashBag<E> hashBag(Iterator<? extends E> iterator, HashBag<E> bag) {
while (iterator.hasNext()) {
bag.add(iterator.next());
}
@@ -609,63 +449,49 @@ public final class CollectionTools {
}
/**
- * Return a bag corresponding to the specified array.
+ * Return a new hash bag corresponding to the specified array.
*/
- public static <E> HashBag<E> bag(E... array) {
+ public static <E> HashBag<E> hashBag(E... array) {
int len = array.length;
- HashBag<E> bag = new HashBag<E>(len);
+ HashBag<E> bag = hashBag(len);
for (E item : array) {
bag.add(item);
}
return bag;
}
+
+ // ********** synchronized bag factory methods **********
+
/**
- * Return a bag corresponding to the specified queue, draining the queue
- * in the process.
+ * Return a synchronized bag.
*/
- public static <E> HashBag<E> bag(Queue<? extends E> queue) {
- return bag(queue, new HashBag<E>());
+ public static <E> SynchronizedBag<E> synchronizedBag() {
+ HashBag<E> bag = hashBag();
+ return synchronizedBag(bag);
}
/**
- * Return a bag corresponding to the specified queue, draining the queue
- * in the process.
- * The specified queue size is a performance hint.
+ * Return a bag that synchronizes with specified mutex.
*/
- public static <E> HashBag<E> bag(Queue<? extends E> queue, int queueSize) {
- return bag(queue, new HashBag<E>(queueSize));
- }
-
- private static <E> HashBag<E> bag(Queue<? extends E> queue, HashBag<E> set) {
- while ( ! queue.isEmpty()) {
- set.add(queue.dequeue());
- }
- return set;
+ public static <E> SynchronizedBag<E> synchronizedBag(Object mutex) {
+ HashBag<E> bag = hashBag();
+ return synchronizedBag(bag, mutex);
}
/**
- * Return a bag corresponding to the specified stack, draining the stack
- * in the process.
+ * Return a bag that synchronizes the specified bag.
*/
- public static <E> HashBag<E> bag(Stack<? extends E> stack) {
- return bag(stack, new HashBag<E>());
+ public static <E> SynchronizedBag<E> synchronizedBag(Bag<E> bag) {
+ return new SynchronizedBag<E>(bag);
}
/**
- * Return a bag corresponding to the specified stack, draining the stack
- * in the process.
- * The specified stack size is a performance hint.
+ * Return a bag that synchronizes the specified bag
+ * with specified mutex.
*/
- public static <E> HashBag<E> bag(Stack<? extends E> stack, int stackSize) {
- return bag(stack, new HashBag<E>(stackSize));
- }
-
- private static <E> HashBag<E> bag(Stack<? extends E> stack, HashBag<E> set) {
- while ( ! stack.isEmpty()) {
- set.add(stack.pop());
- }
- return set;
+ public static <E> SynchronizedBag<E> synchronizedBag(Bag<E> bag, Object mutex) {
+ return new SynchronizedBag<E>(bag, mutex);
}
/**
@@ -674,169 +500,119 @@ public final class CollectionTools {
* The specified stack size is a performance hint.
*/
public static <E> Bag<E> emptyBag() {
- return EmptyBag.<E>instance();
+ return EmptyBag.instance();
}
- // ********** identity bag factory methods **********
+ // ********** identity hash bag factory methods **********
/**
- * Return an identity bag corresponding to the specified iterable.
+ * Return a new identity hash bag.
*/
- public static <E> IdentityHashBag<E> identityBag(Iterable<? extends E> iterable) {
- return identityBag(iterable.iterator());
+ public static <E> IdentityHashBag<E> identityHashBag() {
+ return new IdentityHashBag<E>();
}
/**
- * Return an identity bag corresponding to the specified iterable.
- * The specified iterable size is a performance hint.
- */
- public static <E> IdentityHashBag<E> identityBag(Iterable<? extends E> iterable, int iterableSize) {
- return identityBag(iterable.iterator(), iterableSize);
- }
-
- /**
- * Return an identity bag corresponding to the specified iterator.
- */
- public static <E> IdentityHashBag<E> identityBag(Iterator<? extends E> iterator) {
- return identityBag(iterator, new IdentityHashBag<E>());
- }
-
- /**
- * Return an identity bag corresponding to the specified iterator.
- * The specified iterator size is a performance hint.
+ * Return a new identity hash bag with the specified initial capacity.
*/
- public static <E> IdentityHashBag<E> identityBag(Iterator<? extends E> iterator, int iteratorSize) {
- return identityBag(iterator, new IdentityHashBag<E>(iteratorSize));
- }
-
- private static <E> IdentityHashBag<E> identityBag(Iterator<? extends E> iterator, IdentityHashBag<E> bag) {
- while (iterator.hasNext()) {
- bag.add(iterator.next());
- }
- return bag;
+ public static <E> IdentityHashBag<E> identityHashBag(int initialCapacity) {
+ return new IdentityHashBag<E>(initialCapacity);
}
/**
- * Return an identity bag corresponding to the specified array.
+ * Return a new identity hash bag with the specified initial capacity
+ * and load factor.
*/
- public static <E> IdentityHashBag<E> identityBag(E... array) {
- int len = array.length;
- IdentityHashBag<E> bag = new IdentityHashBag<E>(len);
- for (E item : array) {
- bag.add(item);
- }
- return bag;
+ public static <E> IdentityHashBag<E> identityHashBag(int initialCapacity, float loadFactor) {
+ return new IdentityHashBag<E>(initialCapacity, loadFactor);
}
-
- // ********** collection factory methods **********
-
/**
- * Return a collection corresponding to the specified iterable.
+ * Return a new identity hash bag corresponding to the specified iterable.
*/
- public static <E> HashBag<E> collection(Iterable<? extends E> iterable) {
- return collection(iterable.iterator());
+ public static <E> IdentityHashBag<E> identityHashBag(Iterable<? extends E> iterable) {
+ return identityHashBag(iterable.iterator());
}
/**
- * Return a collection corresponding to the specified iterable.
+ * Return a new identity hash bag corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E> HashBag<E> collection(Iterable<? extends E> iterable, int iterableSize) {
- return collection(iterable.iterator(), iterableSize);
+ public static <E> IdentityHashBag<E> identityHashBag(Iterable<? extends E> iterable, int iterableSize) {
+ return identityHashBag(iterable.iterator(), iterableSize);
}
/**
- * Return a collection corresponding to the specified iterator.
+ * Return a new identity hash bag corresponding to the specified iterator.
*/
- public static <E> HashBag<E> collection(Iterator<? extends E> iterator) {
- return bag(iterator);
+ public static <E> IdentityHashBag<E> identityHashBag(Iterator<? extends E> iterator) {
+ IdentityHashBag<E> bag = identityHashBag();
+ return identityHashBag(iterator, bag);
}
/**
- * Return a collection corresponding to the specified iterator.
+ * Return a new identity hash bag corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E> HashBag<E> collection(Iterator<? extends E> iterator, int iteratorSize) {
- return bag(iterator, iteratorSize);
+ public static <E> IdentityHashBag<E> identityHashBag(Iterator<? extends E> iterator, int iteratorSize) {
+ IdentityHashBag<E> bag = identityHashBag(iteratorSize);
+ return identityHashBag(iterator, bag);
}
- /**
- * Return a collection corresponding to the specified array.
- */
- public static <E> HashBag<E> collection(E... array) {
- return bag(array);
- }
-
- /**
- * Return a collection corresponding to the specified queue, draining the queue
- * in the process.
- */
- public static <E> HashBag<E> collection(Queue<? extends E> queue) {
- return bag(queue);
- }
-
- /**
- * Return a collection corresponding to the specified queue, draining the queue
- * in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> HashBag<E> collection(Queue<? extends E> queue, int queueSize) {
- return bag(queue, queueSize);
- }
-
- /**
- * Return a collection corresponding to the specified stack, draining the stack
- * in the process.
- */
- public static <E> HashBag<E> collection(Stack<? extends E> stack) {
- return bag(stack);
+ private static <E> IdentityHashBag<E> identityHashBag(Iterator<? extends E> iterator, IdentityHashBag<E> bag) {
+ while (iterator.hasNext()) {
+ bag.add(iterator.next());
+ }
+ return bag;
}
/**
- * Return a collection corresponding to the specified stack, draining the stack
- * in the process.
- * The specified stack size is a performance hint.
+ * Return a new identity hash bag corresponding to the specified array.
*/
- public static <E> HashBag<E> collection(Stack<? extends E> stack, int stackSize) {
- return bag(stack, stackSize);
+ public static <E> IdentityHashBag<E> identityHashBag(E... array) {
+ int len = array.length;
+ IdentityHashBag<E> bag = identityHashBag(len);
+ for (E item : array) {
+ bag.add(item);
+ }
+ return bag;
}
- // ********** set factory methods **********
+ // ********** hash set factory methods **********
/**
- * Return a set corresponding to the specified iterable.
+ * Return a new hash set corresponding to the specified iterable.
*/
- public static <E> HashSet<E> set(Iterable<? extends E> iterable) {
- return set(iterable.iterator());
+ public static <E> HashSet<E> hashSet(Iterable<? extends E> iterable) {
+ return hashSet(iterable.iterator());
}
/**
- * Return a set corresponding to the specified iterable.
+ * Return a new hash set corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E> HashSet<E> set(Iterable<? extends E> iterable, int iterableSize) {
- return set(iterable.iterator(), iterableSize);
+ public static <E> HashSet<E> hashSet(Iterable<? extends E> iterable, int iterableSize) {
+ return hashSet(iterable.iterator(), iterableSize);
}
/**
- * Return a set corresponding to the specified iterator.
+ * Return a new hash set corresponding to the specified iterator.
*/
- public static <E> HashSet<E> set(Iterator<? extends E> iterator) {
- return set(iterator, new HashSet<E>());
+ public static <E> HashSet<E> hashSet(Iterator<? extends E> iterator) {
+ return hashSet(iterator, new HashSet<E>());
}
/**
- * Return a set corresponding to the specified iterator.
+ * Return a new hash set corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E> HashSet<E> set(Iterator<? extends E> iterator, int iteratorSize) {
- return set(iterator, new HashSet<E>(iteratorSize));
+ public static <E> HashSet<E> hashSet(Iterator<? extends E> iterator, int iteratorSize) {
+ return hashSet(iterator, new HashSet<E>(iteratorSize));
}
- private static <E> HashSet<E> set(Iterator<? extends E> iterator, HashSet<E> set) {
+ private static <E> HashSet<E> hashSet(Iterator<? extends E> iterator, HashSet<E> set) {
while (iterator.hasNext()) {
set.add(iterator.next());
}
@@ -844,9 +620,9 @@ public final class CollectionTools {
}
/**
- * Return a set corresponding to the specified array.
+ * Return a new hash set corresponding to the specified array.
*/
- public static <E> HashSet<E> set(E... array) {
+ public static <E> HashSet<E> hashSet(E... array) {
HashSet<E> set = new HashSet<E>(array.length);
for (int i = array.length; i-- > 0;) {
set.add(array[i]);
@@ -854,213 +630,96 @@ public final class CollectionTools {
return set;
}
- /**
- * Return a set corresponding to the specified queue, draining the queue
- * in the process.
- */
- public static <E> HashSet<E> set(Queue<? extends E> queue) {
- return set(queue, new HashSet<E>());
- }
- /**
- * Return a set corresponding to the specified queue, draining the queue
- * in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> HashSet<E> set(Queue<? extends E> queue, int queueSize) {
- return set(queue, new HashSet<E>(queueSize));
- }
-
- private static <E> HashSet<E> set(Queue<? extends E> queue, HashSet<E> set) {
- while ( ! queue.isEmpty()) {
- set.add(queue.dequeue());
- }
- return set;
- }
+ // ********** tree (sorted) set factory methods **********
/**
- * Return a set corresponding to the specified stack, draining the stack
- * in the process.
+ * Return a new tree (sorted) set corresponding to the specified iterable.
*/
- public static <E> HashSet<E> set(Stack<? extends E> stack) {
- return set(stack, new HashSet<E>());
+ public static <E extends Comparable<? super E>> TreeSet<E> treeSet(Iterable<? extends E> iterable) {
+ return treeSet(iterable.iterator());
}
/**
- * Return a set corresponding to the specified stack, draining the stack
- * in the process.
- * The specified stack size is a performance hint.
- */
- public static <E> HashSet<E> set(Stack<? extends E> stack, int stackSize) {
- return set(stack, new HashSet<E>(stackSize));
- }
-
- private static <E> HashSet<E> set(Stack<? extends E> stack, HashSet<E> set) {
- while ( ! stack.isEmpty()) {
- set.add(stack.pop());
- }
- return set;
- }
-
-
- // ********** sorted set factory methods **********
-
- /**
- * Return a sorted set corresponding to the specified iterable.
- */
- public static <E extends Comparable<? super E>> TreeSet<E> sortedSet(Iterable<? extends E> iterable) {
- return sortedSet(iterable.iterator());
- }
-
- /**
- * Return a sorted set corresponding to the specified iterable.
+ * Return a new tree (sorted) set corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E extends Comparable<? super E>> TreeSet<E> sortedSet(Iterable<? extends E> iterable, int iterableSize) {
- return sortedSet(iterable.iterator(), iterableSize);
+ public static <E extends Comparable<? super E>> TreeSet<E> treeSet(Iterable<? extends E> iterable, int iterableSize) {
+ return treeSet(iterable.iterator(), iterableSize);
}
/**
- * Return a sorted set corresponding to the specified iterable
+ * Return a new tree (sorted) set corresponding to the specified iterable
* and comparator.
*/
- public static <E> TreeSet<E> sortedSet(Iterable<? extends E> iterable, Comparator<? super E> comparator) {
- return sortedSet(iterable.iterator(), comparator);
+ public static <E> TreeSet<E> treeSet(Iterable<? extends E> iterable, Comparator<? super E> comparator) {
+ return treeSet(iterable.iterator(), comparator);
}
/**
- * Return a sorted set corresponding to the specified iterable
+ * Return a new tree (sorted) set corresponding to the specified iterable
* and comparator.
* The specified iterable size is a performance hint.
*/
- public static <E> TreeSet<E> sortedSet(Iterable<? extends E> iterable, Comparator<? super E> comparator, int iterableSize) {
- return sortedSet(iterable.iterator(), comparator, iterableSize);
+ public static <E> TreeSet<E> treeSet(Iterable<? extends E> iterable, Comparator<? super E> comparator, int iterableSize) {
+ return treeSet(iterable.iterator(), comparator, iterableSize);
}
/**
- * Return a sorted set corresponding to the specified iterator.
+ * Return a new tree (sorted) set corresponding to the specified iterator.
*/
- public static <E extends Comparable<? super E>> TreeSet<E> sortedSet(Iterator<? extends E> iterator) {
- return sortedSet(iterator, null);
+ public static <E extends Comparable<? super E>> TreeSet<E> treeSet(Iterator<? extends E> iterator) {
+ return treeSet(iterator, null);
}
/**
- * Return a sorted set corresponding to the specified iterator.
+ * Return a new tree (sorted) set corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E extends Comparable<? super E>> TreeSet<E> sortedSet(Iterator<? extends E> iterator, int iteratorSize) {
- return sortedSet(iterator, null, iteratorSize);
+ public static <E extends Comparable<? super E>> TreeSet<E> treeSet(Iterator<? extends E> iterator, int iteratorSize) {
+ return treeSet(iterator, null, iteratorSize);
}
/**
- * Return a sorted set corresponding to the specified iterator
+ * Return a new tree (sorted) set corresponding to the specified iterator
* and comparator.
*/
- public static <E> TreeSet<E> sortedSet(Iterator<? extends E> iterator, Comparator<? super E> comparator) {
- return sortedSet(ListTools.list(iterator), comparator);
+ public static <E> TreeSet<E> treeSet(Iterator<? extends E> iterator, Comparator<? super E> comparator) {
+ return treeSet(ListTools.arrayList(iterator), comparator);
}
/**
- * Return a sorted set corresponding to the specified iterator
+ * Return a new tree (sorted) set corresponding to the specified iterator
* and comparator.
* The specified iterator size is a performance hint.
*/
- public static <E> TreeSet<E> sortedSet(Iterator<? extends E> iterator, Comparator<? super E> comparator, int iteratorSize) {
- return sortedSet(ListTools.list(iterator, iteratorSize), comparator);
+ public static <E> TreeSet<E> treeSet(Iterator<? extends E> iterator, Comparator<? super E> comparator, int iteratorSize) {
+ return treeSet(ListTools.arrayList(iterator, iteratorSize), comparator);
}
- private static <E> TreeSet<E> sortedSet(List<E> list, Comparator<? super E> comparator) {
+ private static <E> TreeSet<E> treeSet(ArrayList<E> list, Comparator<? super E> comparator) {
TreeSet<E> sortedSet = new TreeSet<E>(comparator);
sortedSet.addAll(list);
return sortedSet;
}
/**
- * Return a sorted set corresponding to the specified array.
+ * Return a new tree (sorted) set corresponding to the specified array.
*/
- public static <E extends Comparable<? super E>> TreeSet<E> sortedSet(E... array) {
- return sortedSet(array, null);
+ public static <E extends Comparable<? super E>> TreeSet<E> treeSet(E... array) {
+ return treeSet(array, null);
}
/**
- * Return a sorted set corresponding to the specified array
+ * Return a new tree (sorted) set corresponding to the specified array
* and comparator.
*/
- public static <E> TreeSet<E> sortedSet(E[] array, Comparator<? super E> comparator) {
+ public static <E> TreeSet<E> treeSet(E[] array, Comparator<? super E> comparator) {
TreeSet<E> sortedSet = new TreeSet<E>(comparator);
sortedSet.addAll(Arrays.asList(array));
return sortedSet;
}
- /**
- * Return a sorted set corresponding to the specified queue,
- * draining the queue in the process.
- */
- public static <E> TreeSet<E> sortedSet(Queue<? extends E> queue) {
- return sortedSet(queue, null);
- }
-
- /**
- * Return a sorted set corresponding to the specified queue,
- * draining the queue in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> TreeSet<E> sortedSet(Queue<? extends E> queue, int queueSize) {
- return sortedSet(queue, null, queueSize);
- }
-
- /**
- * Return a sorted set corresponding to the specified queue and comparator,
- * draining the queue in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> TreeSet<E> sortedSet(Queue<? extends E> queue, Comparator<? super E> comparator) {
- return sortedSet(ListTools.list(queue), comparator);
- }
-
- /**
- * Return a sorted set corresponding to the specified queue and comparator,
- * draining the queue in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> TreeSet<E> sortedSet(Queue<? extends E> queue, Comparator<? super E> comparator, int queueSize) {
- return sortedSet(ListTools.list(queue, queueSize), comparator);
- }
-
- /**
- * Return a sorted set corresponding to the specified stack,
- * draining the stack in the process.
- */
- public static <E> TreeSet<E> sortedSet(Stack<? extends E> stack) {
- return sortedSet(stack, null);
- }
-
- /**
- * Return a sorted set corresponding to the specified stack,
- * draining the stack in the process.
- * The specified stack size is a performance hint.
- */
- public static <E> TreeSet<E> sortedSet(Stack<? extends E> stack, int stackSize) {
- return sortedSet(stack, null, stackSize);
- }
-
- /**
- * Return a sorted set corresponding to the specified stack and comparator,
- * draining the stack in the process.
- */
- public static <E> TreeSet<E> sortedSet(Stack<? extends E> stack, Comparator<? super E> comparator) {
- return sortedSet(ListTools.list(stack), comparator);
- }
-
- /**
- * Return a sorted set corresponding to the specified stack and comparator,
- * draining the stack in the process.
- * The specified stack size is a performance hint.
- */
- public static <E> TreeSet<E> sortedSet(Stack<? extends E> stack, Comparator<? super E> comparator, int stackSize) {
- return sortedSet(ListTools.list(stack, stackSize), comparator);
- }
-
// ********** Old School Vector factory methods **********
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayQueue.java
deleted file mode 100644
index 1308adf523..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayQueue.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2015 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-
-/**
- * Fixed-sized array FIFO implementation of the {@link Queue} interface.
- * This implementation will throw an exception if its capacity is exceeded.
- * @param <E> the type of elements maintained by the queue
- * @see ArrayQueue
- * @see QueueTools
- */
-public class FixedSizeArrayQueue<E>
- implements Queue<E>, Cloneable, Serializable
-{
- private final E[] elements;
-
- /** Index of next element to be "dequeued". */
- private int head = 0;
-
- /** Index of next element to be "enqueued". */
- private int tail = 0;
-
- private int size = 0;
-
- private static final long serialVersionUID = 1L;
-
-
- // ********** constructors **********
-
- /**
- * Construct an empty queue with the specified capacity.
- */
- @SuppressWarnings("unchecked")
- public FixedSizeArrayQueue(int capacity) {
- super();
- if (capacity < 0) {
- throw new IllegalArgumentException("Illegal capacity: " + capacity); //$NON-NLS-1$
- }
- this.elements = (E[]) new Object[capacity];
- }
-
-
- // ********** Queue implementation **********
-
- /**
- * @exception IllegalStateException if the queue is full
- */
- public void enqueue(E element) {
- if (this.isFull()) {
- throw new IllegalStateException("Queue is full."); //$NON-NLS-1$
- }
- this.elements[this.tail] = element;
- if (++this.tail == this.elements.length) {
- this.tail = 0;
- }
- this.size++;
- }
-
- public E dequeue() {
- if (this.size == 0) {
- throw new NoSuchElementException();
- }
- E element = this.elements[this.head];
- this.elements[this.head] = null; // allow GC to work
- if (++this.head == this.elements.length) {
- this.head = 0;
- }
- this.size--;
- return element;
- }
-
- public E peek() {
- if (this.size == 0) {
- throw new NoSuchElementException();
- }
- return this.elements[this.head];
- }
-
- public boolean isEmpty() {
- return this.size == 0;
- }
-
- /**
- * Return whether the queue is full,
- * as its capacity is fixed.
- */
- public boolean isFull() {
- return this.size == this.elements.length;
- }
-
-
- // ********** standard methods **********
-
- @Override
- public FixedSizeArrayQueue<E> clone() {
- int len = this.elements.length;
- FixedSizeArrayQueue<E> clone = new FixedSizeArrayQueue<E>(len);
- System.arraycopy(this.elements, 0, clone.elements, 0, len);
- clone.head = this.head;
- clone.tail = this.tail;
- clone.size = this.size;
- return clone;
- }
-
- @Override
- public String toString() {
- return Arrays.toString(this.copyElements());
- }
-
- private Object[] copyElements() {
- if (this.size == 0) {
- return ObjectTools.EMPTY_OBJECT_ARRAY;
- }
- Object[] result = new Object[this.size];
- if ((this.head == 0) || (this.head < this.tail) || (this.tail == 0)) {
- // elements are contiguous
- System.arraycopy(this.elements, this.head, result, 0, this.size);
- } else {
- // elements wrap past end of array
- int fragmentSize = this.elements.length - this.head;
- System.arraycopy(this.elements, this.head, result, 0, fragmentSize);
- System.arraycopy(this.elements, 0, result, fragmentSize, (this.size - fragmentSize));
- }
- return result;
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/HashBag.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/HashBag.java
index cacf9d5715..4c98665bfb 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/HashBag.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/HashBag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -76,7 +76,7 @@ public class HashBag<E>
implements Bag<E>, Cloneable, Serializable
{
/** The hash table. Resized as necessary. Length MUST Always be a power of two. */
- transient Entry<E>[] table;
+ transient Entry[] table;
/** The total number of entries in the bag. */
transient int size = 0;
@@ -254,7 +254,7 @@ public class HashBag<E>
private void add_(E o, int cnt) {
int hash = this.hash(o);
int index = this.index(hash);
- for (Entry<E> e = this.table[index]; e != null; e = e.next) {
+ for (Entry e = this.table[index]; e != null; e = e.next) {
Object eo;
if ((e.hash == hash) && (((eo = e.object) == o) || ((o != null) && o.equals(eo)))) {
e.count += cnt;
@@ -264,7 +264,7 @@ public class HashBag<E>
}
// create the new entry and put it in the table
- Entry<E> e = this.buildEntry(hash, o, cnt, this.table[index]);
+ Entry e = this.buildEntry(hash, o, cnt, this.table[index]);
this.table[index] = e;
this.size += cnt;
this.uniqueCount++;
@@ -291,9 +291,9 @@ public class HashBag<E>
* the object's hash code and examining the entries in the corresponding hash
* table bucket.
*/
- private Entry<E> getEntry(Object o) {
+ private Entry getEntry(Object o) {
int hash = this.hash(o);
- for (Entry<E> e = this.table[this.index(hash)]; e != null; e = e.next) {
+ for (Entry e = this.table[this.index(hash)]; e != null; e = e.next) {
Object eo;
if ((e.hash == hash) && (((eo = e.object) == o) || ((o != null) && o.equals(eo)))) {
return e;
@@ -308,7 +308,7 @@ public class HashBag<E>
}
public int count(Object o) {
- Entry<E> e = this.getEntry(o);
+ Entry e = this.getEntry(o);
return (e == null) ? 0 : e.count;
}
@@ -319,7 +319,7 @@ public class HashBag<E>
* capacity and load factor.
*/
private void rehash() {
- Entry<E>[] oldTable = this.table;
+ Entry[] oldTable = this.table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
@@ -328,11 +328,11 @@ public class HashBag<E>
}
int newCapacity = 2 * oldCapacity;
- Entry<E>[] newTable = this.buildTable(newCapacity);
+ Entry[] newTable = this.buildTable(newCapacity);
for (int i = oldCapacity; i-- > 0; ) {
- for (Entry<E> old = oldTable[i]; old != null; ) {
- Entry<E> e = old;
+ for (Entry old = oldTable[i]; old != null; ) {
+ Entry e = old;
old = old.next;
int index = this.index(e.hash, newCapacity);
@@ -347,8 +347,8 @@ public class HashBag<E>
// minimize scope of suppressed warnings
@SuppressWarnings("unchecked")
- private Entry<E>[] buildTable(int capacity) {
- return new Entry[capacity];
+ private Entry[] buildTable(int capacity) {
+ return new HashBag.Entry[capacity];
}
/**
@@ -375,7 +375,7 @@ public class HashBag<E>
int index = this.index(hash);
// if the object is already in the bag, simply bump its count
- for (Entry<E> e = this.table[index]; e != null; e = e.next) {
+ for (Entry e = this.table[index]; e != null; e = e.next) {
Object eo;
if ((e.hash == hash) && (((eo = e.object) == o) || ((o != null) && o.equals(eo)))) {
e.count += cnt;
@@ -391,7 +391,7 @@ public class HashBag<E>
}
// create the new entry and put it in the table
- Entry<E> e = this.buildEntry(hash, o, cnt, this.table[index]);
+ Entry e = this.buildEntry(hash, o, cnt, this.table[index]);
this.table[index] = e;
this.size += cnt;
this.uniqueCount++;
@@ -399,9 +399,9 @@ public class HashBag<E>
}
// minimize scope of suppressed warnings
- @SuppressWarnings({ "rawtypes", "unchecked" } )
- private Entry<E> buildEntry(int hash, Object o, int cnt, Entry next) {
- return new Entry<E>(hash, (E) o, cnt, (Entry<E>) next);
+ @SuppressWarnings("unchecked")
+ private Entry buildEntry(int hash, Object o, int cnt, Entry next) {
+ return new Entry(hash, (E) o, cnt, next);
}
/**
@@ -426,7 +426,7 @@ public class HashBag<E>
int hash = this.hash(o);
int index = this.index(hash);
- for (Entry<E> e = this.table[index], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = this.table[index], prev = null; e != null; prev = e, e = e.next) {
Object eo;
if ((e.hash == hash) && (((eo = e.object) == o) || ((o != null) && o.equals(eo)))) {
this.modCount++;
@@ -454,7 +454,7 @@ public class HashBag<E>
*/
@Override
public void clear() {
- Entry<E>[] tab = this.table;
+ Entry[] tab = this.table;
this.modCount++;
for (int i = tab.length; i-- > 0; ) {
tab[i] = null;
@@ -489,15 +489,15 @@ public class HashBag<E>
/**
* Hash table collision list entry.
*/
- private static class Entry<E>
+ private class Entry
implements Bag.Entry<E>
{
final int hash;
final E object;
int count;
- Entry<E> next;
+ Entry next;
- Entry(int hash, E object, int count, Entry<E> next) {
+ Entry(int hash, E object, int count, Entry next) {
this.hash = hash;
this.object = object;
this.count = count;
@@ -519,6 +519,7 @@ public class HashBag<E>
}
int old = this.count;
this.count = count;
+ HashBag.this.size += (count - old);
return old;
}
@@ -599,9 +600,9 @@ public class HashBag<E>
implements Iterator<E>
{
private int index = HashBag.this.table.length; // start at the end of the table
- private Entry<E> nextEntry = null;
+ private Entry nextEntry = null;
private int nextEntryCount = 0;
- private Entry<E> lastReturnedEntry = null;
+ private Entry lastReturnedEntry = null;
/**
* The modCount value that the iterator believes that the backing
@@ -615,9 +616,9 @@ public class HashBag<E>
}
public boolean hasNext() {
- Entry<E> e = this.nextEntry;
+ Entry e = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = HashBag.this.table;
+ Entry[] tab = HashBag.this.table;
// Use locals for faster loop iteration
while ((e == null) && (i > 0)) {
e = tab[--i]; // move backwards through the table
@@ -631,9 +632,9 @@ public class HashBag<E>
if (HashBag.this.modCount != this.expectedModCount) {
throw new ConcurrentModificationException();
}
- Entry<E> et = this.nextEntry;
+ Entry et = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = HashBag.this.table;
+ Entry[] tab = HashBag.this.table;
// Use locals for faster loop iteration
while ((et == null) && (i > 0)) {
et = tab[--i]; // move backwards through the table
@@ -643,7 +644,7 @@ public class HashBag<E>
if (et == null) {
throw new NoSuchElementException();
}
- Entry<E> e = this.lastReturnedEntry = this.nextEntry;
+ Entry e = this.lastReturnedEntry = this.nextEntry;
this.nextEntryCount++;
if (this.nextEntryCount == e.count) {
this.nextEntry = e.next;
@@ -660,7 +661,7 @@ public class HashBag<E>
throw new ConcurrentModificationException();
}
int slot = HashBag.this.index(this.lastReturnedEntry.hash, HashBag.this.table.length);
- for (Entry<E> e = HashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = HashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
if (e == this.lastReturnedEntry) {
HashBag.this.modCount++;
this.expectedModCount++;
@@ -688,11 +689,11 @@ public class HashBag<E>
private class EntryIterator
- implements Iterator<Entry<E>>
+ implements Iterator<Entry>
{
private int index = HashBag.this.table.length; // start at the end of the table
- private Entry<E> nextEntry = null;
- private Entry<E> lastReturnedEntry = null;
+ private Entry nextEntry = null;
+ private Entry lastReturnedEntry = null;
/**
* The modCount value that the iterator believes that the backing
@@ -706,9 +707,9 @@ public class HashBag<E>
}
public boolean hasNext() {
- Entry<E> e = this.nextEntry;
+ Entry e = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = HashBag.this.table;
+ Entry[] tab = HashBag.this.table;
// Use locals for faster loop iteration
while ((e == null) && (i > 0)) {
e = tab[--i]; // move backwards through the table
@@ -718,13 +719,13 @@ public class HashBag<E>
return e != null;
}
- public Entry<E> next() {
+ public Entry next() {
if (HashBag.this.modCount != this.expectedModCount) {
throw new ConcurrentModificationException();
}
- Entry<E> et = this.nextEntry;
+ Entry et = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = HashBag.this.table;
+ Entry[] tab = HashBag.this.table;
// Use locals for faster loop iteration
while ((et == null) && (i > 0)) {
et = tab[--i]; // move backwards through the table
@@ -734,7 +735,7 @@ public class HashBag<E>
if (et == null) {
throw new NoSuchElementException();
}
- Entry<E> e = this.lastReturnedEntry = this.nextEntry;
+ Entry e = this.lastReturnedEntry = this.nextEntry;
this.nextEntry = e.next;
return e;
}
@@ -747,7 +748,7 @@ public class HashBag<E>
throw new ConcurrentModificationException();
}
int slot = HashBag.this.index(this.lastReturnedEntry.hash, HashBag.this.table.length);
- for (Entry<E> e = HashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = HashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
if (e == this.lastReturnedEntry) {
HashBag.this.modCount++;
this.expectedModCount++;
@@ -848,7 +849,7 @@ public class HashBag<E>
// write out elements and counts (alternating)
if (this.uniqueCount > 0) {
- for (Entry<E> entry : this.table) {
+ for (Entry entry : this.table) {
while (entry != null) {
s.writeObject(entry.object);
s.writeInt(entry.count);
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/IdentityHashBag.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/IdentityHashBag.java
index ef7b4135ee..203bb140ca 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/IdentityHashBag.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/IdentityHashBag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -92,7 +92,7 @@ public class IdentityHashBag<E>
implements Bag<E>, Cloneable, Serializable
{
/** The hash table. Resized as necessary. Length MUST Always be a power of two. */
- transient Entry<E>[] table;
+ transient Entry[] table;
/** The total number of entries in the bag. */
transient int size = 0;
@@ -277,7 +277,7 @@ public class IdentityHashBag<E>
private void add_(E o, int cnt) {
int hash = this.hash(o);
int index = this.index(hash);
- for (Entry<E> e = this.table[index]; e != null; e = e.next) {
+ for (Entry e = this.table[index]; e != null; e = e.next) {
if (e.object == o) {
e.count += cnt;
this.size += cnt;
@@ -286,7 +286,7 @@ public class IdentityHashBag<E>
}
// create the new entry and put it in the table
- Entry<E> e = this.buildEntry(hash, o, cnt, this.table[index]);
+ Entry e = this.buildEntry(hash, o, cnt, this.table[index]);
this.table[index] = e;
this.size += cnt;
this.uniqueCount++;
@@ -313,8 +313,8 @@ public class IdentityHashBag<E>
* the object's identity hash code and examining the entries in the corresponding hash
* table bucket.
*/
- private Entry<E> getEntry(Object o) {
- for (Entry<E> e = this.table[this.index(o)]; e != null; e = e.next) {
+ private Entry getEntry(Object o) {
+ for (Entry e = this.table[this.index(o)]; e != null; e = e.next) {
if (e.object == o) {
return e;
}
@@ -328,7 +328,7 @@ public class IdentityHashBag<E>
}
public int count(Object o) {
- Entry<E> e = this.getEntry(o);
+ Entry e = this.getEntry(o);
return (e == null) ? 0 : e.count;
}
@@ -339,7 +339,7 @@ public class IdentityHashBag<E>
* capacity and load factor.
*/
private void rehash() {
- Entry<E>[] oldTable = this.table;
+ Entry[] oldTable = this.table;
int oldCapacity = oldTable.length;
if (oldCapacity == MAXIMUM_CAPACITY) {
@@ -348,11 +348,11 @@ public class IdentityHashBag<E>
}
int newCapacity = 2 * oldCapacity;
- Entry<E>[] newTable = this.buildTable(newCapacity);
+ Entry[] newTable = this.buildTable(newCapacity);
for (int i = oldCapacity; i-- > 0; ) {
- for (Entry<E> old = oldTable[i]; old != null; ) {
- Entry<E> e = old;
+ for (Entry old = oldTable[i]; old != null; ) {
+ Entry e = old;
old = old.next;
int index = this.index(e.hash, newCapacity);
@@ -367,8 +367,8 @@ public class IdentityHashBag<E>
// minimize scope of suppressed warnings
@SuppressWarnings("unchecked")
- private Entry<E>[] buildTable(int capacity) {
- return new Entry[capacity];
+ private Entry[] buildTable(int capacity) {
+ return new IdentityHashBag.Entry[capacity];
}
/**
@@ -395,7 +395,7 @@ public class IdentityHashBag<E>
int index = this.index(hash);
// if the object is already in the bag, simply bump its count
- for (Entry<E> e = this.table[index]; e != null; e = e.next) {
+ for (Entry e = this.table[index]; e != null; e = e.next) {
if (e.object == o) {
e.count += cnt;
this.size += cnt;
@@ -410,7 +410,7 @@ public class IdentityHashBag<E>
}
// create the new entry and put it in the table
- Entry<E> e = this.buildEntry(hash, o, cnt, this.table[index]);
+ Entry e = this.buildEntry(hash, o, cnt, this.table[index]);
this.table[index] = e;
this.size += cnt;
this.uniqueCount++;
@@ -418,9 +418,9 @@ public class IdentityHashBag<E>
}
// minimize scope of suppressed warnings
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private Entry<E> buildEntry(int hash, Object o, int cnt, Entry next) {
- return new Entry<E>(hash, (E) o, cnt, (Entry<E>) next);
+ @SuppressWarnings("unchecked")
+ private Entry buildEntry(int hash, Object o, int cnt, Entry next) {
+ return new Entry(hash, (E) o, cnt, next);
}
/**
@@ -444,7 +444,7 @@ public class IdentityHashBag<E>
}
int index = this.index(o);
- for (Entry<E> e = this.table[index], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = this.table[index], prev = null; e != null; prev = e, e = e.next) {
if (e.object == o) {
this.modCount++;
cnt = (cnt < e.count) ? cnt : e.count;
@@ -489,7 +489,7 @@ public class IdentityHashBag<E>
*/
@Override
public void clear() {
- Entry<E>[] tab = this.table;
+ Entry[] tab = this.table;
this.modCount++;
for (int i = tab.length; i-- > 0; ) {
tab[i] = null;
@@ -524,15 +524,15 @@ public class IdentityHashBag<E>
/**
* Hash table collision list entry.
*/
- private static class Entry<E>
+ private class Entry
implements Bag.Entry<E>
{
final int hash; // cache the hash for re-hashes
final E object;
int count;
- Entry<E> next;
+ Entry next;
- Entry(int hash, E object, int count, Entry<E> next) {
+ Entry(int hash, E object, int count, Entry next) {
this.hash = hash;
this.object = object;
this.count = count;
@@ -554,6 +554,7 @@ public class IdentityHashBag<E>
}
int old = this.count;
this.count = count;
+ IdentityHashBag.this.size += (count - old);
return old;
}
@@ -634,9 +635,9 @@ public class IdentityHashBag<E>
implements Iterator<E>
{
private int index = IdentityHashBag.this.table.length; // start at the end of the table
- private Entry<E> nextEntry = null;
+ private Entry nextEntry = null;
private int nextEntryCount = 0;
- private Entry<E> lastReturnedEntry = null;
+ private Entry lastReturnedEntry = null;
/**
* The modCount value that the iterator believes that the backing
@@ -650,9 +651,9 @@ public class IdentityHashBag<E>
}
public boolean hasNext() {
- Entry<E> e = this.nextEntry;
+ Entry e = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = IdentityHashBag.this.table;
+ Entry[] tab = IdentityHashBag.this.table;
// Use locals for faster loop iteration
while ((e == null) && (i > 0)) {
e = tab[--i]; // move backwards through the table
@@ -666,9 +667,9 @@ public class IdentityHashBag<E>
if (IdentityHashBag.this.modCount != this.expectedModCount) {
throw new ConcurrentModificationException();
}
- Entry<E> et = this.nextEntry;
+ Entry et = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = IdentityHashBag.this.table;
+ Entry[] tab = IdentityHashBag.this.table;
// Use locals for faster loop iteration
while ((et == null) && (i > 0)) {
et = tab[--i]; // move backwards through the table
@@ -678,7 +679,7 @@ public class IdentityHashBag<E>
if (et == null) {
throw new NoSuchElementException();
}
- Entry<E> e = this.lastReturnedEntry = this.nextEntry;
+ Entry e = this.lastReturnedEntry = this.nextEntry;
this.nextEntryCount++;
if (this.nextEntryCount == e.count) {
this.nextEntry = e.next;
@@ -695,7 +696,7 @@ public class IdentityHashBag<E>
throw new ConcurrentModificationException();
}
int slot = IdentityHashBag.this.index(this.lastReturnedEntry.hash, IdentityHashBag.this.table.length);
- for (Entry<E> e = IdentityHashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = IdentityHashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
if (e == this.lastReturnedEntry) {
IdentityHashBag.this.modCount++;
this.expectedModCount++;
@@ -723,11 +724,11 @@ public class IdentityHashBag<E>
private class EntryIterator
- implements Iterator<Entry<E>>
+ implements Iterator<Entry>
{
private int index = IdentityHashBag.this.table.length; // start at the end of the table
- private Entry<E> nextEntry = null;
- private Entry<E> lastReturnedEntry = null;
+ private Entry nextEntry = null;
+ private Entry lastReturnedEntry = null;
/**
* The modCount value that the iterator believes that the backing
@@ -741,9 +742,9 @@ public class IdentityHashBag<E>
}
public boolean hasNext() {
- Entry<E> e = this.nextEntry;
+ Entry e = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = IdentityHashBag.this.table;
+ Entry[] tab = IdentityHashBag.this.table;
// Use locals for faster loop iteration
while ((e == null) && (i > 0)) {
e = tab[--i]; // move backwards through the table
@@ -753,13 +754,13 @@ public class IdentityHashBag<E>
return e != null;
}
- public Entry<E> next() {
+ public Entry next() {
if (IdentityHashBag.this.modCount != this.expectedModCount) {
throw new ConcurrentModificationException();
}
- Entry<E> et = this.nextEntry;
+ Entry et = this.nextEntry;
int i = this.index;
- Entry<E>[] tab = IdentityHashBag.this.table;
+ Entry[] tab = IdentityHashBag.this.table;
// Use locals for faster loop iteration
while ((et == null) && (i > 0)) {
et = tab[--i]; // move backwards through the table
@@ -769,7 +770,7 @@ public class IdentityHashBag<E>
if (et == null) {
throw new NoSuchElementException();
}
- Entry<E> e = this.lastReturnedEntry = this.nextEntry;
+ Entry e = this.lastReturnedEntry = this.nextEntry;
this.nextEntry = e.next;
return e;
}
@@ -782,7 +783,7 @@ public class IdentityHashBag<E>
throw new ConcurrentModificationException();
}
int slot = IdentityHashBag.this.index(this.lastReturnedEntry.hash, IdentityHashBag.this.table.length);
- for (Entry<E> e = IdentityHashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
+ for (Entry e = IdentityHashBag.this.table[slot], prev = null; e != null; prev = e, e = e.next) {
if (e == this.lastReturnedEntry) {
IdentityHashBag.this.modCount++;
this.expectedModCount++;
@@ -887,7 +888,7 @@ public class IdentityHashBag<E>
// write out elements and counts (alternating)
if (this.uniqueCount > 0) {
- for (Entry<E> entry : this.table) {
+ for (Entry entry : this.table) {
while (entry != null) {
s.writeObject(entry.object);
s.writeInt(entry.count);
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java
index 5192bf1480..1864caebd3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,8 +20,6 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Random;
import java.util.RandomAccess;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.internal.Range;
import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
@@ -61,7 +59,14 @@ public final class ListTools {
* Return whether the list changed as a result.
*/
public static <E> boolean addAll(List<? super E> list, int index, Iterator<? extends E> iterator) {
- return iterator.hasNext() && list.addAll(index, list(iterator));
+ return iterator.hasNext() && addAll_(list, index, iterator);
+ }
+
+ /**
+ * assume the iterator is not empty
+ */
+ private static <E> boolean addAll_(List<? super E> list, int index, Iterator<? extends E> iterator) {
+ return (index == list.size()) ? CollectionTools.addAll_(list, iterator) : list.addAll(index, arrayList(iterator));
}
/**
@@ -71,7 +76,7 @@ public final class ListTools {
* The specified iterator size is a performance hint.
*/
public static <E> boolean addAll(List<? super E> list, int index, Iterator<? extends E> iterator, int iteratorSize) {
- return iterator.hasNext() && list.addAll(index, list(iterator, iteratorSize));
+ return iterator.hasNext() && list.addAll(index, arrayList(iterator, iteratorSize));
}
/**
@@ -83,48 +88,6 @@ public final class ListTools {
return (array.length != 0) && list.addAll(index, Arrays.asList(array));
}
- /**
- * Add all the elements in the specified queue
- * to the specified list at the specified index,
- * draining the queue in the process.
- * Return whether the list changed as a result.
- */
- public static <E> boolean addAll(List<? super E> list, int index, Queue<? extends E> queue) {
- return ( ! queue.isEmpty()) && list.addAll(index, list(queue));
- }
-
- /**
- * Add all the elements in the specified queue
- * to the specified list at the specified index,
- * draining the queue in the process.
- * Return whether the list changed as a result.
- * The specified queue size is a performance hint.
- */
- public static <E> boolean addAll(List<? super E> list, int index, Queue<? extends E> queue, int queueSize) {
- return ( ! queue.isEmpty()) && list.addAll(index, list(queue, queueSize));
- }
-
- /**
- * Add all the elements in the specified stack
- * to the specified list at the specified index,
- * draining the stack in the process.
- * Return whether the list changed as a result.
- */
- public static <E> boolean addAll(List<? super E> list, int index, Stack<? extends E> stack) {
- return ( ! stack.isEmpty()) && list.addAll(index, list(stack));
- }
-
- /**
- * Add all the elements in the specified stack
- * to the specified list at the specified index,
- * draining the stack in the process.
- * Return whether the list changed as a result.
- * The specified stack size is a performance hint.
- */
- public static <E> boolean addAll(List<? super E> list, int index, Stack<? extends E> stack, int stackSize) {
- return ( ! stack.isEmpty()) && list.addAll(index, list(stack, stackSize));
- }
-
// ********** diff **********
@@ -585,7 +548,7 @@ public final class ListTools {
* Return a new list with transformations of the
* elements in the specified list.
*/
- public static <I, O> ArrayList<O> transform(List<I> list, Transformer<? super I, ? extends O> transformer) {
+ public static <I, O> ArrayList<O> transform(Collection<I> list, Transformer<? super I, ? extends O> transformer) {
ArrayList<O> result = new ArrayList<O>(list.size());
for (I each : list) {
result.add(transformer.transform(each));
@@ -683,36 +646,36 @@ public final class ListTools {
// ********** factory methods **********
/**
- * Return a list corresponding to the specified iterable.
+ * Return an array list corresponding to the specified iterable.
*/
- public static <E> ArrayList<E> list(Iterable<? extends E> iterable) {
- return list(iterable.iterator());
+ public static <E> ArrayList<E> arrayList(Iterable<? extends E> iterable) {
+ return arrayList(iterable.iterator());
}
/**
- * Return a list corresponding to the specified iterable.
+ * Return an array list corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E> ArrayList<E> list(Iterable<? extends E> iterable, int iterableSize) {
- return list(iterable.iterator(), iterableSize);
+ public static <E> ArrayList<E> arrayList(Iterable<? extends E> iterable, int iterableSize) {
+ return arrayList(iterable.iterator(), iterableSize);
}
/**
- * Return a list corresponding to the specified iterator.
+ * Return an array list corresponding to the specified iterator.
*/
- public static <E> ArrayList<E> list(Iterator<? extends E> iterator) {
- return list(iterator, new ArrayList<E>());
+ public static <E> ArrayList<E> arrayList(Iterator<? extends E> iterator) {
+ return arrayList(iterator, new ArrayList<E>());
}
/**
- * Return a list corresponding to the specified iterator.
+ * Return an array list corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E> ArrayList<E> list(Iterator<? extends E> iterator, int iteratorSize) {
- return list(iterator, new ArrayList<E>(iteratorSize));
+ public static <E> ArrayList<E> arrayList(Iterator<? extends E> iterator, int iteratorSize) {
+ return arrayList(iterator, new ArrayList<E>(iteratorSize));
}
- private static <E> ArrayList<E> list(Iterator<? extends E> iterator, ArrayList<E> list) {
+ private static <E> ArrayList<E> arrayList(Iterator<? extends E> iterator, ArrayList<E> list) {
while (iterator.hasNext()) {
list.add(iterator.next());
}
@@ -720,11 +683,11 @@ public final class ListTools {
}
/**
- * Return a list corresponding to the specified array.
+ * Return an array list corresponding to the specified array.
* Unlike {@link Arrays#asList(Object[])}, the list
* is modifiable and is not backed by the array.
*/
- public static <E> ArrayList<E> list(E... array) {
+ public static <E> ArrayList<E> arrayList(E... array) {
ArrayList<E> list = new ArrayList<E>(array.length);
for (E e : array) {
list.add(e);
@@ -732,54 +695,6 @@ public final class ListTools {
return list;
}
- /**
- * Return a list corresponding to the specified queue,
- * draining the queue in the process.
- */
- public static <E> ArrayList<E> list(Queue<? extends E> queue) {
- return list(queue, new ArrayList<E>());
- }
-
- /**
- * Return a list corresponding to the specified queue,
- * draining the queue in the process.
- * The specified queue size is a performance hint.
- */
- public static <E> ArrayList<E> list(Queue<? extends E> queue, int queueSize) {
- return list(queue, new ArrayList<E>(queueSize));
- }
-
- private static <E> ArrayList<E> list(Queue<? extends E> queue, ArrayList<E> list) {
- while ( ! queue.isEmpty()) {
- list.add(queue.dequeue());
- }
- return list;
- }
-
- /**
- * Return a list corresponding to the specified stack,
- * draining the stack in the process.
- */
- public static <E> ArrayList<E> list(Stack<? extends E> stack) {
- return list(stack, new ArrayList<E>());
- }
-
- /**
- * Return a list corresponding to the specified stack,
- * draining the stack in the process.
- * The specified stack size is a performance hint.
- */
- public static <E> ArrayList<E> list(Stack<? extends E> stack, int stackSize) {
- return list(stack, new ArrayList<E>(stackSize));
- }
-
- private static <E> ArrayList<E> list(Stack<? extends E> stack, ArrayList<E> list) {
- while ( ! stack.isEmpty()) {
- list.add(stack.pop());
- }
- return list;
- }
-
// ********** transformers **********
@@ -820,7 +735,7 @@ public final class ListTools {
* <em>read-only</em> {@link ListIterator}.
*/
@SuppressWarnings("unchecked")
- public static <E> Transformer<List<? extends E>, ListIterator<? extends E>> readOnlyListIteratorTransformer() {
+ public static <E> Transformer<List<? extends E>, ListIterator<E>> readOnlyListIteratorTransformer() {
return READ_ONLY_LIST_ITERATOR_TRANSFORMER;
}
@@ -836,10 +751,10 @@ public final class ListTools {
* <em>read-only</em> {@link ListIterator}.
*/
public static class ReadOnlyListIteratorTransformer<E>
- implements Transformer<List<? extends E>, ListIterator<? extends E>>
+ implements Transformer<List<? extends E>, ListIterator<E>>
{
- public ListIterator<? extends E> transform(List<? extends E> list) {
- return IteratorTools.readOnly(list.listIterator());
+ public ListIterator<E> transform(List<? extends E> list) {
+ return IteratorTools.<E>readOnly(list.listIterator());
}
@Override
public String toString() {
@@ -884,7 +799,7 @@ public final class ListTools {
* <em>read-only</em> {@link ListIterable}.
*/
@SuppressWarnings("unchecked")
- public static <E> Transformer<List<? extends E>, ListIterable<? extends E>> readOnlyListIterableTransformer() {
+ public static <E> Transformer<List<? extends E>, ListIterable<E>> readOnlyListIterableTransformer() {
return READ_ONLY_LIST_ITERABLE_TRANSFORMER;
}
@@ -900,10 +815,10 @@ public final class ListTools {
* <em>read-only</em> {@link ListIterable}.
*/
public static class ReadOnlyListIterableTransformer<E>
- implements Transformer<List<? extends E>, ListIterable<? extends E>>
+ implements Transformer<List<? extends E>, ListIterable<E>>
{
- public ListIterable<? extends E> transform(List<? extends E> list) {
- return IterableTools.listIterable(list);
+ public ListIterable<E> transform(List<? extends E> list) {
+ return IterableTools.<E>readOnly(IterableTools.listIterable(list));
}
@Override
public String toString() {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java
index 812b8f03f9..109b38bf02 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/MapTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Oracle. All rights reserved.
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,8 +14,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.factory.Factory;
import org.eclipse.jpt.common.utility.internal.ClassTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
@@ -117,7 +115,7 @@ public final class MapTools {
* @see Map#get(Object)
* @see Map#containsKey(Object)
*/
- public static <K, V> V get(Map<K, V> map, K key, Class<? extends V> clazz, Class<?> parameterType, Object argument) {
+ public static <K, V, C extends V> V get(Map<K, V> map, K key, Class<C> clazz, Class<?> parameterType, Object argument) {
return get(map, key, clazz, new Class[] {parameterType}, new Object[] {argument});
}
@@ -125,8 +123,8 @@ public final class MapTools {
* <em>Assume</em> the map does not contain any <code>null</code> values.
* @see #get(Map, Object, Class, Class, Object)
*/
- public static <K, V> V get_(Map<K, V> map, K key, Class<? extends V> clazz, Class<?> parameterType, Object argument) {
- return get(map, key, clazz, new Class[] {parameterType}, new Object[] {argument});
+ public static <K, V, C extends V> V get_(Map<K, V> map, K key, Class<C> clazz, Class<?> parameterType, Object argument) {
+ return get_(map, key, clazz, new Class[] {parameterType}, new Object[] {argument});
}
/**
@@ -208,30 +206,6 @@ public final class MapTools {
}
/**
- * With the specified map, map the values dequeued from the specified queue
- * to the keys generated by passing the values to the specified key
- * transformer.
- * @see Map#putAll(Map)
- */
- public static <K, V, E extends V> void addAll(Map<K, V> map, Queue<E> values, Transformer<? super E, ? extends K> keyTransformer) {
- while ( ! values.isEmpty()) {
- add(map, values.dequeue(), keyTransformer);
- }
- }
-
- /**
- * With the specified map, map the values popped from the specified stack
- * to the keys generated by passing the values to the specified key
- * transformer.
- * @see Map#putAll(Map)
- */
- public static <K, V, E extends V> void addAll(Map<K, V> map, Stack<E> values, Transformer<? super E, ? extends K> keyTransformer) {
- while ( ! values.isEmpty()) {
- add(map, values.pop(), keyTransformer);
- }
- }
-
- /**
* With the specified map, map the specified values to the keys generated by
* passing the values to the specified key transformer.
* @see Map#putAll(Map)
@@ -265,32 +239,6 @@ public final class MapTools {
}
/**
- * With the specified map, map the values generated by passing the elements
- * dequeued from the specified queue to the specified value transformer to
- * the key generated by passing the elements to the specified key
- * transformer.
- * @see Map#putAll(Map)
- */
- public static <K, V, E> void addAll(Map<K, V> map, Queue<E> elements, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
- while ( ! elements.isEmpty()) {
- add(map, elements.dequeue(), keyTransformer, valueTransformer);
- }
- }
-
- /**
- * With the specified map, map the values generated by passing the elements
- * popped from the specified stack to the specified value transformer to
- * the key generated by passing the elements to the specified key
- * transformer.
- * @see Map#putAll(Map)
- */
- public static <K, V, E> void addAll(Map<K, V> map, Stack<E> elements, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
- while ( ! elements.isEmpty()) {
- add(map, elements.pop(), keyTransformer, valueTransformer);
- }
- }
-
- /**
* With the specified map, map the values generated by passing the specified
* elements to the specified value transformer to the key generated by
* passing the elements to the specified key transformer.
@@ -378,36 +326,6 @@ public final class MapTools {
return true;
}
- /**
- * Return whether the specified map contains all of the
- * keys in the specified queue, dequeueing elements from the queue
- * until one is not found in the map.
- * @see Map#containsKey(Object)
- */
- public static boolean containsAllKeys(Map<?, ?> map, Queue<?> keys) {
- while ( ! keys.isEmpty()) {
- if ( ! map.containsKey(keys.dequeue())) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Return whether the specified map contains all of the
- * keys in the specified stack, popping elements from the stack
- * until one is not found in the map.
- * @see Map#containsKey(Object)
- */
- public static boolean containsAllKeys(Map<?, ?> map, Stack<?> keys) {
- while ( ! keys.isEmpty()) {
- if ( ! map.containsKey(keys.pop())) {
- return false;
- }
- }
- return true;
- }
-
// ********** contains all values **********
@@ -449,36 +367,6 @@ public final class MapTools {
return true;
}
- /**
- * Return whether the specified map contains all of the
- * values in the specified queue, dequeueing elements from the queue
- * until one is not found in the map.
- * @see Map#containsValue(Object)
- */
- public static boolean containsAllValues(Map<?, ?> map, Queue<?> values) {
- while ( ! values.isEmpty()) {
- if ( ! map.containsValue(values.dequeue())) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Return whether the specified map contains all of the
- * values in the specified stack, popping elements from the stack
- * until one is not found in the map.
- * @see Map#containsValue(Object)
- */
- public static boolean containsAllValues(Map<?, ?> map, Stack<?> values) {
- while ( ! values.isEmpty()) {
- if ( ! map.containsValue(values.pop())) {
- return false;
- }
- }
- return true;
- }
-
// ********** remove all **********
@@ -513,28 +401,6 @@ public final class MapTools {
}
}
- /**
- * Remove from the specified map all of the
- * keys dequeued from the specified queue.
- * @see Map#remove(Object)
- */
- public static void removeAll(Map<?, ?> map, Queue<?> keys) {
- while ( ! keys.isEmpty()) {
- map.remove(keys.dequeue());
- }
- }
-
- /**
- * Remove from the specified map all of the
- * keys popped from the specified stack.
- * @see Map#remove(Object)
- */
- public static void removeAll(Map<?, ?> map, Stack<?> keys) {
- while ( ! keys.isEmpty()) {
- map.remove(keys.pop());
- }
- }
-
// ********** retain all **********
@@ -573,7 +439,7 @@ public final class MapTools {
*/
public static void retainAll(Map<?, ?> map, Iterator<?> keys) {
if (keys.hasNext()) {
- retainAll_(map, CollectionTools.set(keys));
+ retainAll_(map, CollectionTools.hashSet(keys));
} else {
map.clear();
}
@@ -586,7 +452,7 @@ public final class MapTools {
*/
public static void retainAll(Map<?, ?> map, Iterator<?> keys, int keysSize) {
if (keys.hasNext()) {
- retainAll_(map, CollectionTools.set(keys, keysSize));
+ retainAll_(map, CollectionTools.hashSet(keys, keysSize));
} else {
map.clear();
}
@@ -598,37 +464,13 @@ public final class MapTools {
*/
public static void retainAll(Map<?, ?> map, Object... keys) {
if (keys.length > 0) {
- retainAll_(map, CollectionTools.set(keys));
+ retainAll_(map, CollectionTools.hashSet(keys));
} else {
map.clear();
}
}
/**
- * Retain in the specified map only the
- * keys dequeued from the specified queue.
- */
- public static void retainAll(Map<?, ?> map, Queue<?> keys) {
- if (keys.isEmpty()) {
- map.clear();
- } else {
- retainAll_(map, CollectionTools.set(keys));
- }
- }
-
- /**
- * Retain in the specified map only the
- * keys popped from the specified stack.
- */
- public static void retainAll(Map<?, ?> map, Stack<?> keys) {
- if (keys.isEmpty()) {
- map.clear();
- } else {
- retainAll_(map, CollectionTools.set(keys));
- }
- }
-
- /**
* no empty check
*/
private static void retainAll_(Map<?, ?> map, Collection<?> keys) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/NullList.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/NullList.java
index 85926244b8..a44cea694f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/NullList.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/NullList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -100,7 +100,10 @@ public final class NullList<E>
}
public ListIterator<E> listIterator(int index) {
- return EmptyListIterator.instance();
+ if (index == 0) {
+ return EmptyListIterator.instance();
+ }
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: 0"); //$NON-NLS-1$ //$NON-NLS-2$
}
public boolean remove(Object o) {
@@ -128,7 +131,10 @@ public final class NullList<E>
}
public List<E> subList(int fromIndex, int toIndex) {
- return this;
+ if ((fromIndex == 0) && (toIndex == 0)) {
+ return this;
+ }
+ throw new IndexOutOfBoundsException("Index: " + fromIndex + ", Size: 0"); //$NON-NLS-1$ //$NON-NLS-2$
}
public Object[] toArray() {
@@ -141,7 +147,7 @@ public final class NullList<E>
@Override
public String toString() {
- return this.getClass().getSimpleName();
+ return "[]"; //$NON-NLS-1$
}
private static final long serialVersionUID = 1L;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/PriorityQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/PriorityQueue.java
deleted file mode 100644
index e928ab2434..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/PriorityQueue.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013, 2015 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
-
-import java.io.Serializable;
-import java.util.SortedSet;
-import org.eclipse.jpt.common.utility.collection.Queue;
-
-/**
- * Adapt a {@link SortedSet} to create a priority implementation of the
- * {@link Queue} interface. Elements will dequeue in the order determined by
- * wrapped sorted set (i.e. {@link #dequeue} will return the element returned
- * by {@link SortedSet#first}.
- * @param <E> the type of elements maintained by the queue
- * @see QueueTools
- */
-public class PriorityQueue<E>
- implements Queue<E>, Serializable
-{
- private final SortedSet<E> elements;
-
- private static final long serialVersionUID = 1L;
-
-
- public PriorityQueue(SortedSet<E> elements) {
- super();
- if (elements == null) {
- throw new NullPointerException();
- }
- this.elements = elements;
- }
-
- public void enqueue(E element) {
- this.elements.add(element);
- }
-
- public E dequeue() {
- E result = this.elements.first();
- this.elements.remove(result);
- return result;
- }
-
- public E peek() {
- return this.elements.first();
- }
-
- public boolean isEmpty() {
- return this.elements.isEmpty();
- }
-
- @Override
- public String toString() {
- return this.elements.toString();
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/QueueTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/QueueTools.java
deleted file mode 100644
index 9de1eab2e3..0000000000
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/QueueTools.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013, 2015 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
-
-/**
- * {@link Queue} utility methods.
- */
-public final class QueueTools {
-
- // ********** enqueue all **********
-
- /**
- * Enqueue all the elements returned by the specified iterable
- * on the specified queue.
- * Return the queue.
- */
- public static <Q extends Queue<? super E>, E> Q enqueueAll(Q queue, Iterable<? extends E> iterable) {
- return enqueueAll(queue, iterable.iterator());
- }
-
- /**
- * Enqueue all the elements returned by the specified iterator
- * on the specified queue.
- * Return the queue.
- */
- public static <Q extends Queue<? super E>, E> Q enqueueAll(Q queue, Iterator<? extends E> iterator) {
- while (iterator.hasNext()) {
- queue.enqueue(iterator.next());
- }
- return queue;
- }
-
- /**
- * Enqueue all the elements in the specified array
- * on the specified queue.
- * Return the queue.
- */
- public static <Q extends Queue<? super E>, E> Q enqueueAll(Q queue, E... array) {
- for (E element : array) {
- queue.enqueue(element);
- }
- return queue;
- }
-
- /**
- * Pop all the elements from the specified stack and enqueue them
- * on the specified queue.
- * Return the queue.
- */
- public static <Q extends Queue<? super E>, E> Q enqueueAll(Q queue, Stack<? extends E> stack) {
- while ( ! stack.isEmpty()) {
- queue.enqueue(stack.pop());
- }
- return queue;
- }
-
- /**
- * Dequeue all the elements from the second specified queue and enqueue them
- * on the first specified queue.
- * Return the first queue.
- * @see #drainTo(Queue, Queue)
- */
- public static <Q extends Queue<? super E>, E> Q enqueueAll(Q queue1, Queue<? extends E> queue2) {
- while ( ! queue2.isEmpty()) {
- queue1.enqueue(queue2.dequeue());
- }
- return queue1;
- }
-
-
- // ********** drain **********
-
- /**
- * Drain all the elements from the specified queue and return them in a
- * list.
- */
- public static <E> ArrayList<E> drain(Queue<? extends E> queue) {
- return drainTo(queue, new ArrayList<E>());
- }
-
- /**
- * Drain all the elements from the specified queue and add them to the
- * specified collection.
- * Return the collection.
- */
- public static <C extends Collection<? super E>, E> C drainTo(Queue<? extends E> queue, C collection) {
- while ( ! queue.isEmpty()) {
- collection.add(queue.dequeue());
- }
- return collection;
- }
-
- /**
- * Drain all the elements from the specified queue and push them on the
- * specified stack.
- * Return the stack.
- */
- public static <S extends Stack<? super E>, E> S drainTo(Queue<? extends E> queue, S stack) {
- while ( ! queue.isEmpty()) {
- stack.push(queue.dequeue());
- }
- return stack;
- }
-
- /**
- * Drain all the elements from the first specified queue and enqueue them
- * on the second specified queue.
- * Return the second queue.
- * @see #enqueueAll(Queue, Queue)
- */
- public static <Q extends Queue<? super E>, E> Q drainTo(Queue<? extends E> queue1, Q queue2) {
- while ( ! queue1.isEmpty()) {
- queue2.enqueue(queue1.dequeue());
- }
- return queue2;
- }
-
-
- // ********** factory methods **********
-
- /**
- * Return an empty array-based FIFO queue.
- */
- public static <E> ArrayQueue<E> queue() {
- return arrayQueue();
- }
-
- /**
- * Return an empty array-based FIFO queue with specified initial capacity.
- */
- public static <E> ArrayQueue<E> queue(int initialCapacity) {
- return arrayQueue(initialCapacity);
- }
-
- /**
- * Return a FIFO queue corresponding to the specified iterable.
- */
- public static <E> ArrayQueue<E> queue(Iterable<? extends E> iterable) {
- return arrayQueue(iterable);
- }
-
- /**
- * Return a FIFO queue corresponding to the specified iterable.
- * The specified iterable size is a performance hint.
- */
- public static <E> ArrayQueue<E> queue(Iterable<? extends E> iterable, int iterableSize) {
- return arrayQueue(iterable, iterableSize);
- }
-
- /**
- * Return a FIFO queue corresponding to the specified iterator.
- */
- public static <E> ArrayQueue<E> queue(Iterator<? extends E> iterator) {
- return arrayQueue(iterator);
- }
-
- /**
- * Return a FIFO queue corresponding to the specified iterator.
- * The specified iterator size is a performance hint.
- */
- public static <E> ArrayQueue<E> queue(Iterator<? extends E> iterator, int iteratorSize) {
- return arrayQueue(iterator, iteratorSize);
- }
-
- /**
- * Return a FIFO queue corresponding to the specified array.
- */
- public static <E> ArrayQueue<E> queue(E... array) {
- return arrayQueue(array);
- }
-
- /**
- * Return an empty array-based FIFO queue.
- */
- public static <E> ArrayQueue<E> arrayQueue() {
- return arrayQueue(10);
- }
-
- /**
- * Return an empty array-based FIFO queue with specified initial capacity.
- */
- public static <E> ArrayQueue<E> arrayQueue(int initialCapacity) {
- return new ArrayQueue<E>(initialCapacity);
- }
-
- /**
- * Return an array-based FIFO queue corresponding to the specified iterable.
- */
- public static <E> ArrayQueue<E> arrayQueue(Iterable<? extends E> iterable) {
- return arrayQueue(iterable.iterator());
- }
-
- /**
- * Return an array-based FIFO queue corresponding to the specified iterable.
- * The specified iterable size is a performance hint.
- */
- public static <E> ArrayQueue<E> arrayQueue(Iterable<? extends E> iterable, int iterableSize) {
- return arrayQueue(iterable.iterator(), iterableSize);
- }
-
- /**
- * Return an array-based FIFO queue corresponding to the specified iterator.
- */
- public static <E> ArrayQueue<E> arrayQueue(Iterator<? extends E> iterator) {
- return enqueueAll(QueueTools.<E>arrayQueue(), iterator);
- }
-
- /**
- * Return an array-based FIFO queue corresponding to the specified iterator.
- * The specified iterator size is a performance hint.
- */
- public static <E> ArrayQueue<E> arrayQueue(Iterator<? extends E> iterator, int iteratorSize) {
- return enqueueAll(QueueTools.<E>arrayQueue(iteratorSize), iterator);
- }
-
- /**
- * Return an array-based FIFO queue corresponding to the specified array.
- */
- public static <E> ArrayQueue<E> arrayQueue(E... array) {
- return enqueueAll(QueueTools.<E>arrayQueue(array.length), array);
- }
-
- /**
- * Return an empty link-based FIFO queue with no node cache.
- */
- public static <E> LinkedQueue<E> linkedQueue() {
- return linkedQueue(0);
- }
-
- /**
- * Return an empty link-based FIFO queue
- * with the specified node cache size.
- * Specify a cache size of -1 for an unlimited cache.
- */
- public static <E> LinkedQueue<E> linkedQueue(int cacheSize) {
- return new LinkedQueue<E>(cacheSize);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified iterable.
- */
- public static <E> LinkedQueue<E> linkedQueue(Iterable<? extends E> iterable) {
- return linkedQueue(iterable, 0);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified iterable
- * with the specified node cache size.
- * Specify a cache size of -1 for an unlimited cache.
- */
- public static <E> LinkedQueue<E> linkedQueue(Iterable<? extends E> iterable, int cacheSize) {
- return linkedQueue(iterable.iterator(), cacheSize);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified iterator.
- */
- public static <E> LinkedQueue<E> linkedQueue(Iterator<? extends E> iterator) {
- return linkedQueue(iterator, 0);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified iterator
- * with the specified node cache size.
- * Specify a cache size of -1 for an unlimited cache.
- */
- public static <E> LinkedQueue<E> linkedQueue(Iterator<? extends E> iterator, int cacheSize) {
- return enqueueAll(QueueTools.<E>linkedQueue(cacheSize), iterator);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified array.
- */
- public static <E> LinkedQueue<E> linkedQueue(E... array) {
- return linkedQueue(array, 0);
- }
-
- /**
- * Return a link-based FIFO queue corresponding to the specified array
- * with the specified node cache size.
- * Specify a cache size of -1 for an unlimited cache.
- */
- public static <E> LinkedQueue<E> linkedQueue(E[] array, int cacheSize) {
- return enqueueAll(QueueTools.<E>linkedQueue(cacheSize), array);
- }
-
- /**
- * Return a fixed-size queue with the specified capacity.
- */
- public static <E> FixedSizeArrayQueue<E> fixedSizeQueue(int capacity) {
- return new FixedSizeArrayQueue<E>(capacity);
- }
-
- /**
- * Return a fized-size queue containing the elements of the specified
- * collection. The queue will dequeue its elements in the same
- * order they are returned by the collection's iterator (i.e. the
- * first element returned by the collection's iterator will be the
- * first element returned by {@link Queue#dequeue()}).
- * The queue's capacity will be match the collection's size.
- */
- public static <E> FixedSizeArrayQueue<E> fixedSizeQueue(Collection<? extends E> collection) {
- return enqueueAll(QueueTools.<E>fixedSizeQueue(collection.size()), collection);
- }
-
- /**
- * Return a LIFO queue.
- */
- public static <E> StackQueue<E> stackQueue() {
- return queue(new ArrayStack<E>());
- }
-
- /**
- * Adapt the specified stack to the {@link Queue} interface,
- * implementing a LIFO queue.
- */
- public static <E> StackQueue<E> queue(Stack<E> stack) {
- return new StackQueue<E>(stack);
- }
-
- /**
- * Return a priority queue that returns its elements in
- * {@linkplain Comparable natural order}.
- */
- public static <E> PriorityQueue<E> priorityQueue() {
- return queue((Comparator<? super E>) null);
- }
-
- /**
- * Return a priority queue whose elements are returned in
- * the order determined by the specified comparator.
- * If the specified comparator is <code>null</code>, the elements will be
- * returned in {@linkplain Comparable natural order}.
- */
- public static <E> PriorityQueue<E> queue(Comparator<? super E> comparator) {
- return queue(new TreeSet<E>(comparator));
- }
-
- /**
- * Adapt the specified sorted set to the {@link Queue} interface,
- * implementing a priority queue.
- */
- public static <E> PriorityQueue<E> queue(SortedSet<E> elements) {
- return new PriorityQueue<E>(elements);
- }
-
- /**
- * Adapt the specified list to the {@link Queue} interface.
- */
- public static <E> ListQueue<E> wrap(List<E> list) {
- return new ListQueue<E>(list);
- }
-
- /**
- * Return a queue that synchronizes the specified queue
- * with specified mutex.
- */
- public static <E> SynchronizedQueue<E> synchronizedQueue(Queue<E> queue, Object mutex) {
- return new SynchronizedQueue<E>(queue, mutex);
- }
-
- /**
- * Return a queue that synchronizes the specified queue.
- */
- public static <E> SynchronizedQueue<E> synchronizedQueue(Queue<E> queue) {
- return new SynchronizedQueue<E>(queue);
- }
-
- /**
- * Return an unmodifiable empty queue.
- */
- public static <E> Queue<E> emptyQueue() {
- return EmptyQueue.<E>instance();
- }
-
-
- // ********** constructor **********
-
- /**
- * Suppress default constructor, ensuring non-instantiability.
- */
- private QueueTools() {
- super();
- throw new UnsupportedOperationException();
- }
-}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedBag.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedBag.java
index 42d882900e..d85b62ed0b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedBag.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedBag.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -59,20 +59,6 @@ public class SynchronizedBag<E>
this.mutex = this;
}
- /**
- * Construct a synchronized bag that locks on the specified mutex.
- */
- public SynchronizedBag(Object mutex) {
- this(new HashBag<E>(), mutex);
- }
-
- /**
- * Construct a synchronized bag that locks on itself.
- */
- public SynchronizedBag() {
- this(new HashBag<E>());
- }
-
// ********** Bag implementation **********
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandContext.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandContext.java
index 09c0ff9547..cc4bf69ee3 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractAsynchronousCommandContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -16,8 +16,9 @@ import org.eclipse.jpt.common.utility.exception.ExceptionHandler;
import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
import org.eclipse.jpt.common.utility.internal.SimpleThreadFactory;
-import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
import org.eclipse.jpt.common.utility.internal.exception.RuntimeExceptionHandler;
+import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
+import org.eclipse.jpt.common.utility.internal.queue.SynchronizedQueue;
/**
* This command context will dispatch commands to be executed in a separate
@@ -44,7 +45,7 @@ public abstract class AbstractAsynchronousCommandContext<E extends StatefulComma
* to execute the new command once the currently executing command has
* finished executing.
*/
- private final SynchronizedQueue<Command> commands = new SynchronizedQueue<Command>();
+ private final SynchronizedQueue<Command> commands = QueueTools.synchronizedQueue();
/**
* Most of the thread-related behavior is delegated to this coordinator.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandContext.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandContext.java
index 0373d7ff94..71d7c77a03 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractQueueingCommandContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal.command;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.StatefulCommandContext;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.collection.LinkedQueue;
+import org.eclipse.jpt.common.utility.internal.queue.LinkedQueue;
import org.eclipse.jpt.common.utility.internal.reference.SynchronizedBoolean;
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandContext.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandContext.java
index 25df4431fd..b2a71b9c92 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandContext.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AbstractSingleUseQueueingCommandContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2012, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,7 +12,7 @@ package org.eclipse.jpt.common.utility.internal.command;
import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.command.StatefulCommandContext;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.collection.LinkedQueue;
+import org.eclipse.jpt.common.utility.internal.queue.LinkedQueue;
/**
* This is a command context that queues up any commands that are
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractArrayDeque.java
index 5b7b87ddcf..e894d76821 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractArrayDeque.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Oracle. All rights reserved.
+ * Copyright (c) 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -7,31 +7,29 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.deque;
import java.io.Serializable;
import java.util.Arrays;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
+import org.eclipse.jpt.common.utility.deque.Deque;
/**
- * Resizable-array FIFO implementation of the {@link Queue} interface.
- * @param <E> the type of elements maintained by the queue
- * @see FixedSizeArrayQueue
- * @see QueueTools
+ * Abstract array implementation of the {@link Deque} interface.
+ * @param <E> the type of elements maintained by the deque
*/
-public class ArrayQueue<E>
- implements Queue<E>, Cloneable, Serializable
+public abstract class AbstractArrayDeque<E>
+ implements Deque<E>, Cloneable, Serializable
{
- private transient E[] elements;
+ protected transient E[] elements;
- /** Index of next element to be "dequeued". */
- private transient int head = 0;
+ /** Index of head element */
+ protected transient int head = 0;
- /** Index of next element to be "enqueued". */
- private transient int tail = 0;
+ /** Index of the <em>next</em> tail element. */
+ protected transient int tail = 0;
- private int size = 0;
+ protected int size = 0;
private static final long serialVersionUID = 1L;
@@ -39,17 +37,10 @@ public class ArrayQueue<E>
// ********** constructors **********
/**
- * Construct an empty queue.
- */
- public ArrayQueue() {
- this(10);
- }
-
- /**
- * Construct an empty queue with the specified initial capacity.
+ * Construct an empty deque with the specified initial capacity.
*/
@SuppressWarnings("unchecked")
- public ArrayQueue(int initialCapacity) {
+ protected AbstractArrayDeque(int initialCapacity) {
super();
if (initialCapacity < 0) {
throw new IllegalArgumentException("Illegal capacity: " + initialCapacity); //$NON-NLS-1$
@@ -58,10 +49,9 @@ public class ArrayQueue<E>
}
- // ********** Queue implementation **********
+ // ********** Deque implementation **********
- public void enqueue(E element) {
- this.ensureCapacity(this.size + 1);
+ public void enqueueTail(E element) {
this.elements[this.tail] = element;
if (++this.tail == this.elements.length) {
this.tail = 0;
@@ -69,53 +59,15 @@ public class ArrayQueue<E>
this.size++;
}
- /**
- * Increase the queue's capacity, if necessary, to ensure it has at least
- * the specified minimum capacity.
- */
- public void ensureCapacity(int minCapacity) {
- int oldCapacity = this.elements.length;
- if (oldCapacity < minCapacity) {
- int newCapacity = ((oldCapacity * 3) >> 1) + 1;
- if (newCapacity < minCapacity) {
- newCapacity = minCapacity;
- }
- this.elements = this.copyElements(newCapacity);
- this.head = 0;
- this.tail = this.size;
- }
- }
-
- /**
- * Decrease the queue's capacity, if necessary, to match its current size.
- */
- public void trimToSize() {
- if (this.elements.length > this.size) {
- this.elements = this.copyElements(this.size);
- this.head = 0;
- this.tail = this.size;
+ public void enqueueHead(E element) {
+ if (this.head == 0) {
+ this.head = this.elements.length;
}
+ this.elements[--this.head] = element;
+ this.size++;
}
- private E[] copyElements(int newCapacity) {
- @SuppressWarnings("unchecked")
- E[] newElements = (E[]) new Object[newCapacity];
- if (this.size != 0) {
- Object oldElements[] = this.elements;
- if ((this.head == 0) || (this.head < this.tail) || (this.tail == 0)) {
- // elements are contiguous
- System.arraycopy(oldElements, this.head, newElements, 0, this.size);
- } else {
- // elements wrap past end of array
- int fragmentSize = oldElements.length - this.head;
- System.arraycopy(oldElements, this.head, newElements, 0, fragmentSize);
- System.arraycopy(oldElements, 0, newElements, fragmentSize, (this.size - fragmentSize));
- }
- }
- return newElements;
- }
-
- public E dequeue() {
+ public E dequeueHead() {
if (this.size == 0) {
throw new NoSuchElementException();
}
@@ -128,13 +80,34 @@ public class ArrayQueue<E>
return element;
}
- public E peek() {
+ public E dequeueTail() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ if (this.tail == 0) {
+ this.tail = this.elements.length;
+ }
+ E element = this.elements[--this.tail];
+ this.elements[this.tail] = null; // allow GC to work
+ this.size--;
+ return element;
+ }
+
+ public E peekHead() {
if (this.size == 0) {
throw new NoSuchElementException();
}
return this.elements[this.head];
}
+ public E peekTail() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ int index = (this.tail == 0) ? this.elements.length : this.tail;
+ return this.elements[--index];
+ }
+
public boolean isEmpty() {
return this.size == 0;
}
@@ -143,10 +116,10 @@ public class ArrayQueue<E>
// ********** standard methods **********
@Override
- public ArrayQueue<E> clone() {
+ public AbstractArrayDeque<E> clone() {
try {
@SuppressWarnings("unchecked")
- ArrayQueue<E> clone = (ArrayQueue<E>) super.clone();
+ AbstractArrayDeque<E> clone = (AbstractArrayDeque<E>) super.clone();
@SuppressWarnings("cast")
E[] array = (E[]) this.elements.clone();
clone.elements = array;
@@ -161,6 +134,28 @@ public class ArrayQueue<E>
return Arrays.toString(this.copyElements(this.size));
}
+ protected E[] copyElements(int newCapacity) {
+ @SuppressWarnings("unchecked")
+ E[] newElements = (E[]) new Object[newCapacity];
+ if (this.size != 0) {
+ Object oldElements[] = this.elements;
+ int t = this.tail;
+ if (t == 0) {
+ t = oldElements.length;
+ }
+ if (this.head < t) {
+ // elements are contiguous
+ System.arraycopy(oldElements, this.head, newElements, 0, this.size);
+ } else {
+ // elements wrap past end of array
+ int fragmentSize = oldElements.length - this.head;
+ System.arraycopy(oldElements, this.head, newElements, 0, fragmentSize);
+ System.arraycopy(oldElements, 0, newElements, fragmentSize, (this.size - fragmentSize));
+ }
+ }
+ return newElements;
+ }
+
// ********** Serializable "implementation" **********
@@ -174,11 +169,15 @@ public class ArrayQueue<E>
return;
}
// save the elements in contiguous order
- if (this.head < this.tail) { // elements are contiguous
- for (int i = this.head; i < this.tail; i++) {
+ int t = this.tail;
+ if (t == 0) {
+ t = elementsLength;
+ }
+ if (this.head < t) { // elements are contiguous
+ for (int i = this.head; i < t; i++) {
stream.writeObject(array[i]);
}
- } else { // (this.head >= this.tail) - elements wrap past end of array
+ } else { // (this.head >= t) - elements wrap past end of array
for (int i = this.head; i < elementsLength; i++) {
stream.writeObject(array[i]);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractPriorityDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractPriorityDeque.java
new file mode 100644
index 0000000000..e2b01d7776
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/AbstractPriorityDeque.java
@@ -0,0 +1,396 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.deque.InputRestrictedDeque;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+
+/**
+ * Abstract priority implementation of the {@link InputRestrictedDeque} interface.
+ * Elements will dequeue from the deque's head in the order determined by a comparator
+ * (i.e. {@link #dequeueHead} will return the element sorted first
+ * while {@link #dequeueTail} will return the element sorted last).
+ * @param <E> the type of elements maintained by the deque
+ */
+public abstract class AbstractPriorityDeque<E>
+ implements InputRestrictedDeque<E>, Cloneable, Serializable
+{
+ protected final Comparator<? super E> comparator;
+
+ /**
+ * Standard min-max heap implementation.
+ * To simplify our math, we leave the first slot [0] empty.
+ */
+ protected transient E[] elements;
+
+ protected int size = 0;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty priority deque with the specified comparator
+ * and initial capacity.
+ */
+ @SuppressWarnings("unchecked")
+ protected AbstractPriorityDeque(Comparator<? super E> comparator, int initialCapacity) {
+ super();
+ if (comparator == null) {
+ throw new NullPointerException();
+ }
+ this.comparator = comparator;
+ if (initialCapacity < 0) {
+ throw new IllegalArgumentException("Illegal capacity: " + initialCapacity); //$NON-NLS-1$
+ }
+
+ this.elements = (E[]) new Object[initialCapacity + 1];
+ }
+
+
+ // ********** Deque implementation **********
+
+ /**
+ * The element is not enqueued strictly to the deque's tail;
+ * it is placed in its proper position, as determined by the
+ * deque's priority comparator.
+ */
+ public void enqueueTail(E element) {
+ this.enqueue(element);
+ }
+
+ public void enqueue(E element) {
+ this.size++;
+ int current = this.size;
+ this.elements[current] = element;
+ int parent = current >> 1;
+ if (parent == 0) {
+ return;
+ }
+
+ int level = 31 - Integer.numberOfLeadingZeros(current); // 'current' is never zero
+ if ((level & 1) == 0) { // even levels are min levels (top level is zero)
+ if (this.comparator.compare(this.elements[current], this.elements[parent]) > 0) {
+ // move to max level before bubbling up
+ ArrayTools.swap(this.elements, current, parent);
+ current = parent;
+ int gp = current >> 2;
+ while ((gp != 0) && this.comparator.compare(this.elements[current], this.elements[gp]) > 0) {
+ ArrayTools.swap(this.elements, current, gp);
+ current = gp;
+ gp = current >> 2;
+ }
+ } else {
+ // bubble up min levels
+ int gp = current >> 2;
+ while ((gp != 0) && this.comparator.compare(this.elements[current], this.elements[gp]) < 0) {
+ ArrayTools.swap(this.elements, current, gp);
+ current = gp;
+ gp = current >> 2;
+ }
+ }
+ } else { // max level
+ if (this.comparator.compare(this.elements[current], this.elements[parent]) < 0) {
+ // move to min level before bubbling up
+ ArrayTools.swap(this.elements, current, parent);
+ current = parent;
+ int gp = current >> 2;
+ while ((gp != 0) && this.comparator.compare(this.elements[current], this.elements[gp]) < 0) {
+ ArrayTools.swap(this.elements, current, gp);
+ current = gp;
+ gp = current >> 2;
+ }
+ } else {
+ // bubble up max levels
+ int gp = current >> 2;
+ while ((gp != 0) && this.comparator.compare(this.elements[current], this.elements[gp]) > 0) {
+ ArrayTools.swap(this.elements, current, gp);
+ current = gp;
+ gp = current >> 2;
+ }
+ }
+ }
+ }
+
+// reduce the redundant code, but add more conditional logic
+// public void enqueue(E element) {
+// this.size++;
+// int current = this.size;
+// this.elements[current] = element;
+// int parent = current >> 1;
+// if (parent == 0) {
+// return;
+// }
+//
+// int level = 31 - Integer.numberOfLeadingZeros(current); // 'current' is never zero
+// boolean minLevel = (level & 1) == 0;
+// int first = minLevel ? current : parent;
+// int second = minLevel ? parent : current;
+// if (this.comparator.compare(this.elements[first], this.elements[second]) > 0) {
+// ArrayTools.swap(this.elements, current, parent);
+// minLevel = ! minLevel;
+// current = parent;
+// }
+// int gp = current >> 2;
+// while (gp != 0) {
+// first = minLevel ? current : gp;
+// second = minLevel ? gp : current;
+// if (this.comparator.compare(this.elements[first], this.elements[second]) > 0) {
+// break;
+// }
+// ArrayTools.swap(this.elements, current, gp);
+// current = gp;
+// gp = current >> 2;
+// }
+// }
+
+ /**
+ * Dequeue first/min element.
+ */
+ public E dequeueHead() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ E element = this.elements[1];
+ if (this.size != 1) {
+ // replace root with last node and move it to its new position
+ ArrayTools.swap(this.elements, 1, this.size);
+ this.trickleDownMin(1, this.size - 1);
+ }
+ this.elements[this.size] = null; // allow GC to work
+ this.size--;
+ return element;
+ }
+
+ private void trickleDownMin(int index, int newSize) {
+ int minChildIndex = index << 1; // left child
+ if (minChildIndex > newSize) {
+ return; // no children
+ }
+
+ E element = this.elements[index];
+ E minChild = this.elements[minChildIndex];
+ int rightChildIndex = minChildIndex + 1;
+ if (rightChildIndex > newSize) {
+ // no right child; and, therefore, no possible grandchildren
+ if (this.comparator.compare(minChild, element) < 0) {
+ ArrayTools.swap(this.elements, minChildIndex, index);
+ }
+ return;
+ }
+
+ E rightChild = this.elements[rightChildIndex];
+ if (this.comparator.compare(rightChild, minChild) < 0) {
+ // right child exists and is less than left
+ minChildIndex = rightChildIndex;
+ minChild = rightChild;
+ }
+
+ // now find min grandchild
+ int minGCIndex = -1;
+ E minGC = null;
+ int i = index << 2; // leftmost grandchild
+ if (i <= newSize) {
+ minGCIndex = i;
+ minGC = this.elements[i];
+ int last = Math.min(i + 3, newSize);
+ while (++i <= last) {
+ E temp = this.elements[i];
+ if (this.comparator.compare(temp, minGC) < 0) {
+ minGCIndex = i;
+ minGC = temp;
+ }
+ }
+ }
+
+ if ((minGC != null) && (this.comparator.compare(minGC, minChild) < 0)) {
+ // min descendant is a grandchild
+ if (this.comparator.compare(minGC, element) < 0) {
+ ArrayTools.swap(this.elements, minGCIndex, index);
+ int parentIndex = minGCIndex >> 1; // 'element' is now at 'minGCIndex'
+ if (this.comparator.compare(element, this.elements[parentIndex]) > 0) {
+ // move element to max level
+ ArrayTools.swap(this.elements, minGCIndex, parentIndex);
+ }
+ this.trickleDownMin(minGCIndex, newSize); // recurse - still on a min level
+ }
+ } else {
+ // min is a direct child and, therefore, has no children itself (since it would have to be greater than its children)
+ if (this.comparator.compare(minChild, element) < 0) {
+ ArrayTools.swap(this.elements, minChildIndex, index);
+ }
+ }
+ }
+
+ /**
+ * Dequeue last/max element.
+ */
+ public E dequeueTail() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ int index = (this.size == 1) ? 1 : (this.size == 2) ? 2 : (this.comparator.compare(this.elements[2], this.elements[3]) > 0) ? 2 : 3;
+ E element = this.elements[index];
+ if (this.size != 1) {
+ // replace removed element with last node and move it to its new position
+ ArrayTools.swap(this.elements, index, this.size);
+ this.trickleDownMax(index, this.size - 1);
+ }
+ this.elements[this.size] = null; // allow GC to work
+ this.size--;
+ return element;
+ }
+
+ private void trickleDownMax(int index, int newSize) {
+ int maxChildIndex = index << 1; // left child
+ if (maxChildIndex > newSize) {
+ return; // no children
+ }
+
+ E element = this.elements[index];
+ E maxChild = this.elements[maxChildIndex];
+ int rightChildIndex = maxChildIndex + 1;
+ if (rightChildIndex > newSize) {
+ // no right child; and, therefore, no possible grandchildren
+ if (this.comparator.compare(maxChild, element) > 0) {
+ ArrayTools.swap(this.elements, maxChildIndex, index);
+ }
+ return;
+ }
+
+ E rightChild = this.elements[rightChildIndex];
+ if (this.comparator.compare(rightChild, maxChild) > 0) {
+ // right child exists and is greater than left
+ maxChildIndex = rightChildIndex;
+ maxChild = rightChild;
+ }
+
+ // now find max grandchild
+ int maxGCIndex = -1;
+ E maxGC = null;
+ int i = index << 2; // leftmost grandchild
+ if (i <= newSize) {
+ maxGCIndex = i;
+ maxGC = this.elements[i];
+ int last = Math.min(i + 3, newSize);
+ while (++i <= last) {
+ E temp = this.elements[i];
+ if (this.comparator.compare(temp, maxGC) > 0) {
+ maxGCIndex = i;
+ maxGC = temp;
+ }
+ }
+ }
+
+ if ((maxGC != null) && (this.comparator.compare(maxGC, maxChild) > 0)) {
+ // max descendant is a grandchild
+ if (this.comparator.compare(maxGC, element) > 0) {
+ ArrayTools.swap(this.elements, maxGCIndex, index);
+ int parentIndex = maxGCIndex >> 1; // 'element' is now at 'maxGCIndex'
+ if (this.comparator.compare(element, this.elements[parentIndex]) < 0) {
+ // move element to min level
+ ArrayTools.swap(this.elements, maxGCIndex, parentIndex);
+ }
+ this.trickleDownMax(maxGCIndex, newSize); // recurse - still on a max level
+ }
+ } else {
+ // max is a direct child and, therefore, has no children itself (since it would have to be less than its children)
+ if (this.comparator.compare(maxChild, element) > 0) {
+ ArrayTools.swap(this.elements, maxChildIndex, index);
+ }
+ }
+ }
+
+ /**
+ * Return first/min element.
+ */
+ public E peekHead() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.elements[1];
+ }
+
+ /**
+ * Return last/max element.
+ */
+ public E peekTail() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ if (this.size == 1) {
+ return this.elements[1];
+ }
+ E left = this.elements[2];
+ if (this.size == 2) {
+ return left;
+ }
+ E right = this.elements[3];
+ return (this.comparator.compare(left, right) > 0) ? left : right;
+ }
+
+ public boolean isEmpty() {
+ return this.size == 0;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public AbstractPriorityDeque<E> clone() {
+ try {
+ @SuppressWarnings("unchecked")
+ AbstractPriorityDeque<E> clone = (AbstractPriorityDeque<E>) super.clone();
+ @SuppressWarnings("cast")
+ E[] array = (E[]) this.elements.clone();
+ clone.elements = array;
+ return clone;
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(ArrayTools.subArray(this.elements, 1, this.size + 1));
+ }
+
+
+ // ********** Serializable "implementation" **********
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
+ // write comparator and size (and any hidden stuff)
+ stream.defaultWriteObject();
+ stream.writeInt(this.elements.length);
+ if (this.size == 0) {
+ return;
+ }
+ for (int i = 1; i <= this.size; i++) { // skip 0
+ stream.writeObject(this.elements[i]);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
+ // read comparator and size (and any hidden stuff)
+ stream.defaultReadObject();
+ int elementsLength = stream.readInt();
+ Object[] array = new Object[elementsLength];
+ for (int i = 1; i <= this.size; i++) { // skip 0
+ array[i] = stream.readObject();
+ }
+ this.elements = (E[]) array;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ArrayDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ArrayDeque.java
new file mode 100644
index 0000000000..4e29e598ca
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ArrayDeque.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import org.eclipse.jpt.common.utility.deque.Deque;
+
+/**
+ * Resizable-array implementation of the {@link Deque} interface.
+ * @param <E> the type of elements maintained by the deque
+ * @see FixedCapacityArrayDeque
+ * @see DequeTools
+ */
+public class ArrayDeque<E>
+ extends AbstractArrayDeque<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty deque with the specified initial capacity.
+ */
+ public ArrayDeque(int initialCapacity) {
+ super(initialCapacity);
+ }
+
+
+ // ********** Deque implementation **********
+
+ @Override
+ public void enqueueTail(E element) {
+ this.ensureCapacity(this.size + 1);
+ super.enqueueTail(element);
+ }
+
+ @Override
+ public void enqueueHead(E element) {
+ this.ensureCapacity(this.size + 1);
+ super.enqueueHead(element);
+ }
+
+ /**
+ * Increase the deque's capacity, if necessary, to ensure it has at least
+ * the specified minimum capacity.
+ */
+ public void ensureCapacity(int minCapacity) {
+ int oldCapacity = this.elements.length;
+ if (oldCapacity < minCapacity) {
+ int newCapacity = ((oldCapacity * 3) >> 1) + 1;
+ if (newCapacity < minCapacity) {
+ newCapacity = minCapacity;
+ }
+ this.elements = this.copyElements(newCapacity);
+ this.head = 0;
+ this.tail = this.size;
+ }
+ }
+
+ /**
+ * Decrease the deque's capacity, if necessary, to match its current size.
+ */
+ public void trimToSize() {
+ if (this.elements.length > this.size) {
+ this.elements = this.copyElements(this.size);
+ this.head = 0;
+ this.tail = this.size;
+ }
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public ArrayDeque<E> clone() {
+ return (ArrayDeque<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/DequeTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/DequeTools.java
new file mode 100644
index 0000000000..aedc7296db
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/DequeTools.java
@@ -0,0 +1,799 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.internal.comparator.ComparatorTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * {@link Deque} utility methods.
+ */
+public final class DequeTools {
+
+ // ********** enqueue all **********
+
+ /**
+ * Enqueue all the elements returned by the specified iterable
+ * on the specified deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueTailAll(Deque<? super E> deque, Iterable<? extends E> iterable) {
+ return enqueueTailAll(deque, iterable.iterator());
+ }
+
+ /**
+ * Enqueue all the elements returned by the specified iterable
+ * on the specified deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueHeadAll(Deque<? super E> deque, Iterable<? extends E> iterable) {
+ return enqueueHeadAll(deque, iterable.iterator());
+ }
+
+ /**
+ * Enqueue all the elements returned by the specified iterator
+ * on the specified deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueTailAll(Deque<? super E> deque, Iterator<? extends E> iterator) {
+ return iterator.hasNext() && enqueueTailAll_(deque, iterator);
+ }
+
+ /**
+ * assume the iterator is not empty
+ */
+ private static <E> boolean enqueueTailAll_(Deque<? super E> deque, Iterator<? extends E> iterator) {
+ do {
+ deque.enqueueTail(iterator.next());
+ } while (iterator.hasNext());
+ return true;
+ }
+
+ /**
+ * Enqueue all the elements returned by the specified iterator
+ * on the specified deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueHeadAll(Deque<? super E> deque, Iterator<? extends E> iterator) {
+ return iterator.hasNext() && enqueueHeadAll_(deque, iterator);
+ }
+
+ /**
+ * assume the iterator is not empty
+ */
+ private static <E> boolean enqueueHeadAll_(Deque<? super E> deque, Iterator<? extends E> iterator) {
+ do {
+ deque.enqueueHead(iterator.next());
+ } while (iterator.hasNext());
+ return true;
+ }
+
+ /**
+ * Enqueue all the elements in the specified array
+ * on the specified deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueTailAll(Deque<? super E> deque, E... array) {
+ int len = array.length;
+ return (len != 0) && enqueueTailAll_(deque, array, len);
+ }
+
+ /**
+ * assume the array is not empty
+ */
+ private static <E> boolean enqueueTailAll_(Deque<? super E> deque, E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ deque.enqueueTail(array[i++]);
+ } while (i < arrayLength);
+ return true;
+ }
+
+ /**
+ * Enqueue all the elements in the specified array
+ * on the specified deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean enqueueHeadAll(Deque<? super E> deque, E... array) {
+ int len = array.length;
+ return (len != 0) && enqueueHeadAll_(deque, array, len);
+ }
+
+ /**
+ * assume the array is not empty
+ */
+ private static <E> boolean enqueueHeadAll_(Deque<? super E> deque, E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ deque.enqueueHead(array[i++]);
+ } while (i < arrayLength);
+ return true;
+ }
+
+
+ // ********** drain **********
+
+ /**
+ * Drain all the elements from the specified deque's head and return them in a
+ * list.
+ */
+ public static <E> ArrayList<E> drainHead(Deque<? extends E> deque) {
+ ArrayList<E> result = new ArrayList<E>();
+ drainHeadTo(deque, result);
+ return result;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail and return them in a
+ * list.
+ */
+ public static <E> ArrayList<E> drainTail(Deque<? extends E> deque) {
+ ArrayList<E> result = new ArrayList<E>();
+ drainTailTo(deque, result);
+ return result;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head and add them to the
+ * specified collection.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainHeadTo(Deque<? extends E> deque, Collection<? super E> collection) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, collection);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainHeadTo_(Deque<? extends E> deque, Collection<? super E> collection) {
+ do {
+ collection.add(deque.dequeueHead());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail and add them to the
+ * specified collection.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainTailTo(Deque<? extends E> deque, Collection<? super E> collection) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, collection);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainTailTo_(Deque<? extends E> deque, Collection<? super E> collection) {
+ do {
+ collection.add(deque.dequeueTail());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head
+ * to the specified list at the specified index.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainHeadTo(Deque<? extends E> deque, List<? super E> list, int index) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, list, index);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainHeadTo_(Deque<? extends E> deque, List<? super E> list, int index) {
+ return (index == list.size()) ? drainHeadTo_(deque, list) : list.addAll(index, drainHead(deque));
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail
+ * to the specified list at the specified index.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainTailTo(Deque<? extends E> deque, List<? super E> list, int index) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, list, index);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainTailTo_(Deque<? extends E> deque, List<? super E> list, int index) {
+ return (index == list.size()) ? drainTailTo_(deque, list) : list.addAll(index, drainTail(deque));
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head and push them on the
+ * specified stack.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainHeadTo(Deque<? extends E> deque, Stack<? super E> stack) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, stack);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainHeadTo_(Deque<? extends E> deque, Stack<? super E> stack) {
+ do {
+ stack.push(deque.dequeueHead());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail and push them on the
+ * specified stack.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainTailTo(Deque<? extends E> deque, Stack<? super E> stack) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, stack);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainTailTo_(Deque<? extends E> deque, Stack<? super E> stack) {
+ do {
+ stack.push(deque.dequeueTail());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head and enqueue them
+ * on the specified queue.
+ * Return whether the deque changed as a result.
+ */
+ public static <E> boolean drainHeadTo(Deque<? extends E> deque, Queue<? super E> queue) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, queue);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainHeadTo_(Deque<? extends E> deque, Queue<? super E> queue) {
+ do {
+ queue.enqueue(deque.dequeueHead());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail and enqueue them
+ * on the specified queue.
+ * Return whether the first deque changed as a result.
+ */
+ public static <E> boolean drainTailTo(Deque<? extends E> deque, Queue<? super E> queue) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, queue);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <E> boolean drainTailTo_(Deque<? extends E> deque, Queue<? super E> queue) {
+ do {
+ queue.enqueue(deque.dequeueTail());
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the first specified deque's head and enqueue them
+ * on the second specified deque's tail.
+ * Return whether the first deque changed as a result.
+ */
+ public static <E> boolean drainHeadTo(Deque<? extends E> deque1, Deque<? super E> deque2) {
+ return ( ! deque1.isEmpty()) && drainHeadTo_(deque1, deque2);
+ }
+
+ /**
+ * assume deque 1 is not empty
+ */
+ private static <E> boolean drainHeadTo_(Deque<? extends E> deque1, Deque<? super E> deque2) {
+ do {
+ deque2.enqueueTail(deque1.dequeueHead());
+ } while ( ! deque1.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the first specified deque's tail and enqueue them
+ * on the second specified deque's head.
+ * Return whether the first deque changed as a result.
+ */
+ public static <E> boolean drainTailTo(Deque<? extends E> deque1, Deque<? super E> deque2) {
+ return ( ! deque1.isEmpty()) && drainTailTo_(deque1, deque2);
+ }
+
+ /**
+ * assume deque 1 is not empty
+ */
+ private static <E> boolean drainTailTo_(Deque<? extends E> deque1, Deque<? super E> deque2) {
+ do {
+ deque2.enqueueHead(deque1.dequeueTail());
+ } while ( ! deque1.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head, passing each element to the
+ * specified key transformer. Map the generated key to its element.
+ */
+ public static <K, V, E extends V> boolean drainHeadTo(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, map, keyTransformer);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <K, V, E extends V> boolean drainHeadTo_(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ do {
+ MapTools.add(map, deque.dequeueHead(), keyTransformer);
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail, passing each element to the
+ * specified key transformer. Map the generated key to its element.
+ */
+ public static <K, V, E extends V> boolean drainTailTo(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, map, keyTransformer);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <K, V, E extends V> boolean drainTailTo_(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ do {
+ MapTools.add(map, deque.dequeueTail(), keyTransformer);
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's head, passing each element to the
+ * specified key and value transformers. Add the generated key/value pairs
+ * to the specified map.
+ */
+ public static <K, V, E> boolean drainHeadTo(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ return ( ! deque.isEmpty()) && drainHeadTo_(deque, map, keyTransformer, valueTransformer);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <K, V, E> boolean drainHeadTo_(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ do {
+ MapTools.add(map, deque.dequeueHead(), keyTransformer, valueTransformer);
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified deque's tail, passing each element to the
+ * specified key and value transformers. Add the generated key/value pairs
+ * to the specified map.
+ */
+ public static <K, V, E> boolean drainTailTo(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ return ( ! deque.isEmpty()) && drainTailTo_(deque, map, keyTransformer, valueTransformer);
+ }
+
+ /**
+ * assume the deque is not empty
+ */
+ private static <K, V, E> boolean drainTailTo_(Deque<E> deque, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ do {
+ MapTools.add(map, deque.dequeueTail(), keyTransformer, valueTransformer);
+ } while ( ! deque.isEmpty());
+ return true;
+ }
+
+
+ // ********** array deque factory methods **********
+
+ /**
+ * Return an empty array-based deque.
+ */
+ public static <E> ArrayDeque<E> arrayDeque() {
+ return arrayDeque(10);
+ }
+
+ /**
+ * Return an empty array-based deque with specified initial capacity.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(int initialCapacity) {
+ return new ArrayDeque<E>(initialCapacity);
+ }
+
+ /**
+ * Return an array-based deque corresponding to the specified iterable.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(Iterable<? extends E> iterable) {
+ return arrayDeque(iterable.iterator());
+ }
+
+ /**
+ * Return an array-based deque corresponding to the reverse of the specified iterable.
+ */
+ public static <E> ArrayDeque<E> reverseArrayDeque(Iterable<? extends E> iterable) {
+ return reverseArrayDeque(iterable.iterator());
+ }
+
+ /**
+ * Return an array-based deque corresponding to the specified iterable.
+ * The specified iterable size is a performance hint.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(Iterable<? extends E> iterable, int iterableSize) {
+ return arrayDeque(iterable.iterator(), iterableSize);
+ }
+
+ /**
+ * Return an array-based deque corresponding to the reverse of the specified iterable.
+ * The specified iterable size is a performance hint.
+ */
+ public static <E> ArrayDeque<E> reverseArrayDeque(Iterable<? extends E> iterable, int iterableSize) {
+ return reverseArrayDeque(iterable.iterator(), iterableSize);
+ }
+
+ /**
+ * Return an array-based deque corresponding to the specified iterator.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(Iterator<? extends E> iterator) {
+ ArrayDeque<E> deque = arrayDeque();
+ enqueueTailAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return an array-based deque corresponding to the reverse of the specified iterator.
+ */
+ public static <E> ArrayDeque<E> reverseArrayDeque(Iterator<? extends E> iterator) {
+ ArrayDeque<E> deque = arrayDeque();
+ enqueueHeadAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return an array-based deque corresponding to the specified iterator.
+ * The specified iterator size is a performance hint.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(Iterator<? extends E> iterator, int iteratorSize) {
+ ArrayDeque<E> deque = arrayDeque(iteratorSize);
+ enqueueTailAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return an array-based deque corresponding to the reverse of the specified iterator.
+ * The specified iterator size is a performance hint.
+ */
+ public static <E> ArrayDeque<E> reverseArrayDeque(Iterator<? extends E> iterator, int iteratorSize) {
+ ArrayDeque<E> deque = arrayDeque(iteratorSize);
+ enqueueHeadAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return an array-based deque corresponding to the specified array.
+ */
+ public static <E> ArrayDeque<E> arrayDeque(E... array) {
+ ArrayDeque<E> deque = arrayDeque(array.length);
+ enqueueTailAll(deque, array);
+ return deque;
+ }
+
+ /**
+ * Return an array-based deque corresponding to the reverse of the specified array.
+ */
+ public static <E> ArrayDeque<E> reverseArrayDeque(E... array) {
+ ArrayDeque<E> deque = arrayDeque(array.length);
+ enqueueHeadAll(deque, array);
+ return deque;
+ }
+
+
+ // ********** linked deque factory methods **********
+
+ /**
+ * Return an empty link-based deque with no node cache.
+ */
+ public static <E> LinkedDeque<E> linkedDeque() {
+ return linkedDeque(0);
+ }
+
+ /**
+ * Return an empty link-based deque
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(int cacheSize) {
+ return new LinkedDeque<E>(cacheSize);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified iterable.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(Iterable<? extends E> iterable) {
+ return linkedDeque(iterable, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified iterable.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(Iterable<? extends E> iterable) {
+ return reverseLinkedDeque(iterable, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified iterable
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(Iterable<? extends E> iterable, int cacheSize) {
+ return linkedDeque(iterable.iterator(), cacheSize);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified iterable
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(Iterable<? extends E> iterable, int cacheSize) {
+ return reverseLinkedDeque(iterable.iterator(), cacheSize);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified iterator.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(Iterator<? extends E> iterator) {
+ return linkedDeque(iterator, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified iterator.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(Iterator<? extends E> iterator) {
+ return reverseLinkedDeque(iterator, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified iterator
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(Iterator<? extends E> iterator, int cacheSize) {
+ LinkedDeque<E> deque = linkedDeque(cacheSize);
+ enqueueTailAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified iterator
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(Iterator<? extends E> iterator, int cacheSize) {
+ LinkedDeque<E> deque = linkedDeque(cacheSize);
+ enqueueHeadAll(deque, iterator);
+ return deque;
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified array.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(E... array) {
+ return linkedDeque(array, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified array.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(E... array) {
+ return reverseLinkedDeque(array, 0);
+ }
+
+ /**
+ * Return a link-based deque corresponding to the specified array
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> linkedDeque(E[] array, int cacheSize) {
+ LinkedDeque<E> deque = linkedDeque(cacheSize);
+ enqueueTailAll(deque, array);
+ return deque;
+ }
+
+ /**
+ * Return a link-based deque corresponding to the reverse of the specified array
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedDeque<E> reverseLinkedDeque(E[] array, int cacheSize) {
+ LinkedDeque<E> deque = linkedDeque(cacheSize);
+ enqueueHeadAll(deque, array);
+ return deque;
+ }
+
+
+ // ********** fixed size array deque factory methods **********
+
+ /**
+ * Return a fixed-capacity array deque with the specified capacity.
+ */
+ public static <E> FixedCapacityArrayDeque<E> fixedCapacityArrayDeque(int capacity) {
+ return new FixedCapacityArrayDeque<E>(capacity);
+ }
+
+ /**
+ * Return a fized-capacity array deque containing the elements of the specified
+ * collection. The deque will dequeue its head elements in the same
+ * order they are returned by the collection's iterator (i.e. the
+ * first element returned by the collection's iterator will be the
+ * first element returned by {@link Deque#dequeueHead()}).
+ * The deque's capacity will be match the collection's size.
+ */
+ public static <E> FixedCapacityArrayDeque<E> fixedCapacityArrayDeque(Collection<? extends E> collection) {
+ FixedCapacityArrayDeque<E> deque = fixedCapacityArrayDeque(collection.size());
+ enqueueTailAll(deque, collection);
+ return deque;
+ }
+
+ /**
+ * Return a fized-capacity array deque containing the elements of the specified
+ * collection. The deque will dequeue its tail elements in the same
+ * order they are returned by the collection's iterator (i.e. the
+ * first element returned by the collection's iterator will be the
+ * first element returned by {@link Deque#dequeueTail()}).
+ * The deque's capacity will be match the collection's size.
+ */
+ public static <E> FixedCapacityArrayDeque<E> reverseFixedCapacityArrayDeque(Collection<? extends E> collection) {
+ FixedCapacityArrayDeque<E> deque = fixedCapacityArrayDeque(collection.size());
+ enqueueHeadAll(deque, collection);
+ return deque;
+ }
+
+
+ // ********** priority deque factory methods **********
+
+ /**
+ * Return a priority deque that returns its elements in
+ * {@linkplain Comparable natural order}.
+ */
+ public static <E extends Comparable<E>> PriorityDeque<E> priorityDeque() {
+ return priorityDeque(10);
+ }
+
+ /**
+ * Return a priority deque that returns its elements in
+ * {@linkplain Comparable natural order} and has the specified initial capacity.
+ */
+ public static <E extends Comparable<E>> PriorityDeque<E> priorityDeque(int initialCapacity) {
+ return priorityDeque(ComparatorTools.<E>naturalComparator(), initialCapacity);
+ }
+
+ /**
+ * Return a priority deque whose elements are returned in
+ * the order determined by the specified comparator.
+ */
+ public static <E> PriorityDeque<E> priorityDeque(Comparator<? super E> comparator) {
+ return priorityDeque(comparator, 10);
+ }
+
+ /**
+ * Return a priority deque whose elements are returned in
+ * the order determined by the specified comparator
+ * and has the specified initial capacity.
+ */
+ public static <E> PriorityDeque<E> priorityDeque(Comparator<? super E> comparator, int initialCapacity) {
+ return new PriorityDeque<E>(comparator, initialCapacity);
+ }
+
+
+ // ********** fixed size priority deque factory methods **********
+
+ /**
+ * Return a fixed-capacity priority deque that returns its elements in
+ * {@linkplain Comparable natural order} and has the specified capacity.
+ */
+ public static <E extends Comparable<E>> FixedCapacityPriorityDeque<E> fixedCapacityPriorityDeque(int capacity) {
+ return fixedCapacityPriorityDeque(ComparatorTools.<E>naturalComparator(), capacity);
+ }
+
+ /**
+ * Return a fixed-capacity priority deque whose elements are returned in
+ * the order determined by the specified comparator
+ * and has the specified capacity.
+ */
+ public static <E> FixedCapacityPriorityDeque<E> fixedCapacityPriorityDeque(Comparator<? super E> comparator, int capacity) {
+ return new FixedCapacityPriorityDeque<E>(comparator, capacity);
+ }
+
+
+ // ********** synchronized deque factory methods **********
+
+ /**
+ * Return a synchronized deque.
+ */
+ public static <E> SynchronizedDeque<E> synchronizedDeque() {
+ ArrayDeque<E> deque = arrayDeque();
+ return synchronizedDeque(deque);
+ }
+
+ /**
+ * Return a deque that synchronizes the specified deque.
+ */
+ public static <E> SynchronizedDeque<E> synchronizedDeque(Object mutex) {
+ ArrayDeque<E> deque = arrayDeque();
+ return synchronizedDeque(deque, mutex);
+ }
+
+ /**
+ * Return a deque that synchronizes the specified deque.
+ */
+ public static <E> SynchronizedDeque<E> synchronizedDeque(Deque<E> deque) {
+ return new SynchronizedDeque<E>(deque);
+ }
+
+ /**
+ * Return a deque that synchronizes the specified deque
+ * with specified mutex.
+ */
+ public static <E> SynchronizedDeque<E> synchronizedDeque(Deque<E> deque, Object mutex) {
+ return new SynchronizedDeque<E>(deque, mutex);
+ }
+
+
+ // ********** misc deque factory methods **********
+
+ /**
+ * Adapt the specified list to the {@link Deque} interface.
+ */
+ public static <E> ListDeque<E> adapt(List<E> list) {
+ return new ListDeque<E>(list);
+ }
+
+ /**
+ * Return a deque that reverses the specified deque.
+ */
+ public static <E> Deque<E> reverse(Deque<E> deque) {
+ return new ReverseDeque<E>(deque);
+ }
+
+ /**
+ * Return an unmodifiable empty deque.
+ */
+ public static <E> Deque<E> emptyDeque() {
+ return EmptyDeque.instance();
+ }
+
+
+ // ********** constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private DequeTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/EmptyDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/EmptyDeque.java
new file mode 100644
index 0000000000..7408bfa5d9
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/EmptyDeque.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.deque.Deque;
+
+/**
+ * Empty implementation of the {@link Deque} interface.
+ * @param <E> the type of elements maintained by the deque
+ * @see DequeTools
+ */
+public final class EmptyDeque<E>
+ implements Deque<E>, Serializable
+{
+ @SuppressWarnings("rawtypes")
+ public static final Deque INSTANCE = new EmptyDeque();
+ @SuppressWarnings("unchecked")
+ public static <E> Deque<E> instance() {
+ return INSTANCE;
+ }
+
+ // ensure single instance
+ private EmptyDeque() {
+ super();
+ }
+
+ public void enqueueTail(E o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void enqueueHead(E o) {
+ throw new UnsupportedOperationException();
+ }
+
+ public E dequeueHead() {
+ throw new NoSuchElementException();
+ }
+
+ public E dequeueTail() {
+ throw new NoSuchElementException();
+ }
+
+ public E peekHead() {
+ throw new NoSuchElementException();
+ }
+
+ public E peekTail() {
+ throw new NoSuchElementException();
+ }
+
+ public boolean isEmpty() {
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "[]"; //$NON-NLS-1$
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityArrayDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityArrayDeque.java
new file mode 100644
index 0000000000..e225c55dc1
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityArrayDeque.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import org.eclipse.jpt.common.utility.deque.Deque;
+
+/**
+ * Fixed-capacity array implementation of the {@link Deque} interface.
+ * This implementation will throw an exception if its capacity is exceeded.
+ * @param <E> the type of elements maintained by the queue
+ * @see ArrayDeque
+ * @see DequeTools
+ */
+public class FixedCapacityArrayDeque<E>
+ extends AbstractArrayDeque<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty deque with the specified capacity.
+ */
+ public FixedCapacityArrayDeque(int capacity) {
+ super(capacity);
+ }
+
+
+ // ********** Deque implementation **********
+
+ /**
+ * @exception IllegalStateException if the deque is full
+ */
+ @Override
+ public void enqueueTail(E element) {
+ if (this.isFull()) {
+ throw new IllegalStateException("Deque is full."); //$NON-NLS-1$
+ }
+ super.enqueueTail(element);
+ }
+
+ /**
+ * @exception IllegalStateException if the deque is full
+ */
+ @Override
+ public void enqueueHead(E element) {
+ if (this.isFull()) {
+ throw new IllegalStateException("Deque is full."); //$NON-NLS-1$
+ }
+ super.enqueueHead(element);
+ }
+
+ /**
+ * Return whether the deque is full,
+ * as its capacity is fixed.
+ */
+ public boolean isFull() {
+ return this.size == this.elements.length;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public FixedCapacityArrayDeque<E> clone() {
+ return (FixedCapacityArrayDeque<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityPriorityDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityPriorityDeque.java
new file mode 100644
index 0000000000..0934b18f28
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/FixedCapacityPriorityDeque.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.util.Comparator;
+import org.eclipse.jpt.common.utility.deque.InputRestrictedDeque;
+
+/**
+ * Fixed capacity priority implementation of the {@link InputRestrictedDeque} interface.
+ * Elements will dequeue from the deque's head in the order determined by a comparator
+ * (i.e. {@link #dequeueHead} will return the element sorted first
+ * while {@link #dequeueTail} will return the element sorted last).
+ * @param <E> the type of elements maintained by the deque
+ * @see PriorityDeque
+ * @see DequeTools
+ */
+public class FixedCapacityPriorityDeque<E>
+ extends AbstractPriorityDeque<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty, fixed-capacity priority deque with the specified comparator
+ * and capacity.
+ */
+ public FixedCapacityPriorityDeque(Comparator<? super E> comparator, int capacity) {
+ super(comparator, capacity);
+ }
+
+
+ // ********** Deque implementation **********
+
+ /**
+ * @exception IllegalStateException if the deque is full
+ */
+ @Override
+ public void enqueue(E element) {
+ if (this.isFull()) {
+ throw new IllegalStateException("Deque is full."); //$NON-NLS-1$
+ }
+ super.enqueue(element);
+ }
+
+ /**
+ * Return whether the deque is full,
+ * as its capacity is fixed.
+ */
+ public boolean isFull() {
+ return this.size == this.elements.length - 1;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public FixedCapacityPriorityDeque<E> clone() {
+ return (FixedCapacityPriorityDeque<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/LinkedDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/LinkedDeque.java
new file mode 100644
index 0000000000..937d38e079
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/LinkedDeque.java
@@ -0,0 +1,321 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+
+/**
+ * Linked implementation of the {@link Deque} interface.
+ * @param <E> the type of elements maintained by the deque
+ * @see DequeTools
+ */
+public class LinkedDeque<E>
+ implements Deque<E>, Cloneable, Serializable
+{
+ private final NodeFactory<E> nodeFactory;
+ private transient Node<E> head; // next element to dequeue head
+ private transient Node<E> tail; // next element to dequeue tail
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty deque with no node cache.
+ */
+ public LinkedDeque() {
+ this(0);
+ }
+
+ /**
+ * Construct an empty deque with a node cache with the specified size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public LinkedDeque(int cacheSize) {
+ this(LinkedDeque.<E>buildNodeFactory(cacheSize));
+ this.head = null;
+ }
+
+ private static <E> NodeFactory<E> buildNodeFactory(int cacheSize) {
+ if (cacheSize < -1) {
+ throw new IllegalArgumentException("Cache size must be greater than or equal to -1: " + cacheSize); //$NON-NLS-1$
+ }
+ return (cacheSize == 0) ? SimpleNodeFactory.<E>instance() : new CachingNodeFactory<E>(cacheSize);
+ }
+
+ private LinkedDeque(NodeFactory<E> nodeFactory) {
+ super();
+ this.nodeFactory = nodeFactory;
+ this.head = null;
+ this.tail = null;
+ }
+
+
+ // ********** Deque implementation **********
+
+ public void enqueueTail(E element) {
+ Node<E> newNode = this.nodeFactory.buildNode(element, null, this.tail);
+ if (this.tail == null) {
+ this.head = newNode; // first node
+ } else {
+ this.tail.next = newNode;
+ }
+ this.tail = newNode;
+ }
+
+ public void enqueueHead(E element) {
+ Node<E> newNode = this.nodeFactory.buildNode(element, this.head, null);
+ if (this.head == null) {
+ this.tail = newNode; // first node
+ } else {
+ this.head.prev = newNode;
+ }
+ this.head = newNode;
+ }
+
+ public E dequeueHead() {
+ if (this.head == null) {
+ throw new NoSuchElementException();
+ }
+ Node<E> node = this.head;
+ this.head = node.next;
+ if (this.head == null) {
+ this.tail = null; // last node
+ } else {
+ this.head.prev = null;
+ }
+ E element = node.element;
+ this.nodeFactory.release(node);
+ return element;
+ }
+
+ public E dequeueTail() {
+ if (this.tail == null) {
+ throw new NoSuchElementException();
+ }
+ Node<E> node = this.tail;
+ this.tail = node.prev;
+ if (this.tail == null) {
+ this.head = null; // last node
+ } else {
+ this.tail.next = null;
+ }
+ E element = node.element;
+ this.nodeFactory.release(node);
+ return element;
+ }
+
+ public E peekHead() {
+ if (this.head == null) {
+ throw new NoSuchElementException();
+ }
+ return this.head.element;
+ }
+
+ public E peekTail() {
+ if (this.tail == null) {
+ throw new NoSuchElementException();
+ }
+ return this.tail.element;
+ }
+
+ public boolean isEmpty() {
+ return this.head == null;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public LinkedDeque<E> clone() {
+ LinkedDeque<E> clone = new LinkedDeque<E>(this.nodeFactory.copy());
+ E[] elements = this.buildElements();
+ for (E element : elements) {
+ clone.enqueueTail(element);
+ }
+ return clone;
+ }
+
+ @SuppressWarnings("unchecked")
+ private E[] buildElements() {
+ int size = this.size();
+ if (size == 0) {
+ return (E[]) ObjectTools.EMPTY_OBJECT_ARRAY;
+ }
+ E[] elements = (E[]) new Object[size];
+ int i = 0;
+ for (Node<E> node = this.head; node != null; node = node.next) {
+ elements[i++] = node.element;
+ }
+ return elements;
+ }
+
+ private int size() {
+ int size = 0;
+ for (Node<E> node = this.head; node != null; node = node.next) {
+ size++;
+ }
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.buildElements());
+ }
+
+
+ // ********** Serializable "implementation" **********
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
+ // write nodeFactory (and any hidden stuff)
+ stream.defaultWriteObject();
+ Object[] elements = this.buildElements();
+ stream.writeInt(elements.length);
+ for (Object element : elements) {
+ stream.writeObject(element);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
+ // read nodeFactory (and any hidden stuff)
+ stream.defaultReadObject();
+ int len = stream.readInt();
+ for (int i = len; i-- > 0; ) {
+ this.enqueueTail((E) stream.readObject());
+ }
+ }
+
+
+ // ********** Node classes **********
+
+ private static final class Node<E> {
+ E element;
+ Node<E> next;
+ Node<E> prev;
+
+ Node(E element, Node<E> next, Node<E> prev) {
+ super();
+ this.element = element;
+ this.next = next;
+ this.prev = prev;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.element);
+ }
+ }
+
+ private abstract static class NodeFactory<E> {
+ NodeFactory() {
+ super();
+ }
+
+ Node<E> buildNode(E element, Node<E> next, Node<E> prev) {
+ return new Node<E>(element, next, prev);
+ }
+
+ abstract void release(Node<E> node);
+
+ abstract NodeFactory<E> copy();
+ }
+
+ private static class SimpleNodeFactory<E>
+ extends NodeFactory<E>
+ implements Serializable
+ {
+ @SuppressWarnings("rawtypes")
+ public static final NodeFactory INSTANCE = new SimpleNodeFactory();
+ @SuppressWarnings("unchecked")
+ public static <E> NodeFactory<E> instance() {
+ return INSTANCE;
+ }
+
+ private SimpleNodeFactory() {
+ super();
+ }
+
+ @Override
+ void release(Node<E> node) {
+ // NOP
+ }
+
+ @Override
+ NodeFactory<E> copy() {
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+
+ private static final long serialVersionUID = 1L;
+ private Object readResolve() {
+ // replace this object with the singleton
+ return INSTANCE;
+ }
+ }
+
+ private static final class CachingNodeFactory<E>
+ extends NodeFactory<E>
+ implements Serializable
+ {
+ private final int maxCacheSize;
+ private transient int cacheSize = 0;
+ private transient Node<E> cacheHead;
+ private static final long serialVersionUID = 1L;
+
+ CachingNodeFactory(int maxCacheSize) {
+ super();
+ this.maxCacheSize = maxCacheSize;
+ }
+
+ @Override
+ Node<E> buildNode(E element, Node<E> next, Node<E> prev) {
+ if (this.cacheHead == null) {
+ return super.buildNode(element, next, prev);
+ }
+ Node<E> node = this.cacheHead;
+ this.cacheHead = node.next;
+ this.cacheSize--;
+ node.element = element;
+ node.next = next;
+ return node;
+ }
+
+ @Override
+ void release(Node<E> node) {
+ if ((this.maxCacheSize == -1) || (this.cacheSize < this.maxCacheSize)) {
+ node.element = null; // allow GC to work
+ node.next = this.cacheHead;
+ node.prev = null;
+ this.cacheHead = node;
+ this.cacheSize++;
+ }
+ }
+
+ @Override
+ NodeFactory<E> copy() {
+ return new CachingNodeFactory<E>(this.maxCacheSize);
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.cacheSize);
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ListDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ListDeque.java
new file mode 100644
index 0000000000..bd86cdf73b
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ListDeque.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.deque.Deque;
+
+/**
+ * Adapt a {@link List} to the {@link Deque} interface.
+ * Head elements are dequeueHeadd from the front of the list (i.e. index 0);
+ * while tail elements are dequeueHeadd from the end of the list.
+ * @param <E> the type of elements maintained by the deque
+ * @see DequeTools
+ */
+public class ListDeque<E>
+ implements Deque<E>, Serializable
+{
+ private List<E> list;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a deque, adapting the specified list.
+ * The deque's head will dequeueHead its elements in the same
+ * order they are returned by the list's iterator (i.e. the
+ * first element returned by the list's iterator will be the
+ * first element returned by {@link #dequeueHead()}).
+ */
+ public ListDeque(List<E> list) {
+ super();
+ this.list = list;
+ }
+
+
+ // ********** Deque implementation **********
+
+ public void enqueueTail(E element) {
+ this.list.add(element);
+ }
+
+ public void enqueueHead(E element) {
+ this.list.add(0, element);
+ }
+
+ public E dequeueHead() {
+ if (this.list.size() == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.list.remove(0);
+ }
+
+ public E dequeueTail() {
+ int size = this.list.size();
+ if (size == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.list.remove(size - 1);
+ }
+
+ public E peekHead() {
+ if (this.list.size() == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.list.get(0);
+ }
+
+ public E peekTail() {
+ int size = this.list.size();
+ if (size == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.list.get(size - 1);
+ }
+
+ public boolean isEmpty() {
+ return this.list.isEmpty();
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public String toString() {
+ return this.list.toString();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/PriorityDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/PriorityDeque.java
new file mode 100644
index 0000000000..270b04af78
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/PriorityDeque.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.util.Comparator;
+import org.eclipse.jpt.common.utility.deque.InputRestrictedDeque;
+
+/**
+ * Resizable priority implementation of the {@link InputRestrictedDeque} interface.
+ * Elements will dequeue from the deque's head in the order determined by a comparator
+ * (i.e. {@link #dequeueHead} will return the element sorted first
+ * while {@link #dequeueTail} will return the element sorted last).
+ * @param <E> the type of elements maintained by the deque
+ * @see FixedCapacityPriorityDeque
+ * @see DequeTools
+ */
+public class PriorityDeque<E>
+ extends AbstractPriorityDeque<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty priority deque with the specified comparator
+ * and initial capacity.
+ */
+ public PriorityDeque(Comparator<? super E> comparator, int initialCapacity) {
+ super(comparator, initialCapacity);
+ }
+
+
+ // ********** Deque implementation **********
+
+ @Override
+ public void enqueue(E element) {
+ this.ensureCapacity(this.size + 1);
+ super.enqueue(element);
+ }
+
+ /**
+ * Increase the deque's capacity, if necessary, to ensure it has at least
+ * the specified minimum capacity.
+ */
+ public void ensureCapacity(int minCapacity) {
+ int oldCapacity = this.elements.length - 1;
+ if (oldCapacity < minCapacity) {
+ int newCapacity = ((oldCapacity * 3) >> 1) + 1;
+ if (newCapacity < minCapacity) {
+ newCapacity = minCapacity;
+ }
+ this.elements = this.copyElements(newCapacity);
+ }
+ }
+
+ /**
+ * Decrease the deque's capacity, if necessary, to match its current size.
+ */
+ public void trimToSize() {
+ if (this.elements.length > this.size + 1) {
+ this.elements = this.copyElements(this.size);
+ }
+ }
+
+ private E[] copyElements(int newCapacity) {
+ @SuppressWarnings("unchecked")
+ E[] newElements = (E[]) new Object[newCapacity + 1];
+ System.arraycopy(this.elements, 1, newElements, 1, this.size); // skip 0
+ return newElements;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public PriorityDeque<E> clone() {
+ return (PriorityDeque<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ReverseDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ReverseDeque.java
new file mode 100644
index 0000000000..e834b86bdd
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/ReverseDeque.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+
+/**
+ * This deque will reverse the order of the configured deque.
+ * @param <E> the type of elements maintained by the deque
+ * @see DequeTools
+ */
+public class ReverseDeque<E>
+ implements Deque<E>, Serializable
+{
+ private Deque<E> deque;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a deque that reverses the specified deque.
+ */
+ public ReverseDeque(Deque<E> deque) {
+ super();
+ if (deque == null) {
+ throw new NullPointerException();
+ }
+ this.deque = deque;
+ }
+
+
+ // ********** Deque implementation **********
+
+ public void enqueueTail(E element) {
+ this.deque.enqueueHead(element);
+ }
+
+ public void enqueueHead(E element) {
+ this.deque.enqueueTail(element);
+ }
+
+ public E dequeueHead() {
+ return this.deque.dequeueTail();
+ }
+
+ public E dequeueTail() {
+ return this.deque.dequeueHead();
+ }
+
+ public E peekHead() {
+ return this.deque.peekTail();
+ }
+
+ public E peekTail() {
+ return this.deque.peekHead();
+ }
+
+ public boolean isEmpty() {
+ return this.deque.isEmpty();
+ }
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.deque);
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/SynchronizedDeque.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/SynchronizedDeque.java
new file mode 100644
index 0000000000..d89d60a07a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/deque/SynchronizedDeque.java
@@ -0,0 +1,984 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.deque;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * Thread-safe implementation of the {@link Deque} interface.
+ * This also provides protocol for suspending a thread until the
+ * deque is empty or not empty, with optional time-outs.
+ * @param <E> the type of elements maintained by the deque
+ * @see DequeTools
+ */
+public class SynchronizedDeque<E>
+ implements Deque<E>, Serializable
+{
+ /** Backing deque. */
+ private final Deque<E> deque;
+
+ /** Object to synchronize on. */
+ private final Object mutex;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a synchronized deque that wraps the
+ * specified deque and locks on the specified mutex.
+ */
+ public SynchronizedDeque(Deque<E> deque, Object mutex) {
+ super();
+ if ((deque == null) || (mutex == null)) {
+ throw new NullPointerException();
+ }
+ this.deque = deque;
+ this.mutex = mutex;
+ }
+
+ /**
+ * Construct a synchronized deque that wraps the
+ * specified deque and locks on itself.
+ */
+ public SynchronizedDeque(Deque<E> deque) {
+ super();
+ if (deque == null) {
+ throw new NullPointerException();
+ }
+ this.deque = deque;
+ this.mutex = this;
+ }
+
+
+ // ********** Deque implementation **********
+
+ public void enqueueTail(E element) {
+ synchronized (this.mutex) {
+ this.enqueueTail_(element);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private void enqueueTail_(E element) {
+ this.deque.enqueueTail(element);
+ this.mutex.notifyAll();
+ }
+
+ public void enqueueHead(E element) {
+ synchronized (this.mutex) {
+ this.enqueueHead_(element);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private void enqueueHead_(E element) {
+ this.deque.enqueueHead(element);
+ this.mutex.notifyAll();
+ }
+
+ public E dequeueHead() {
+ synchronized (this.mutex) {
+ return this.dequeueHead_();
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private E dequeueHead_() {
+ E element = this.deque.dequeueHead();
+ this.mutex.notifyAll();
+ return element;
+ }
+
+ public E dequeueTail() {
+ synchronized (this.mutex) {
+ return this.dequeueTail_();
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private E dequeueTail_() {
+ E element = this.deque.dequeueTail();
+ this.mutex.notifyAll();
+ return element;
+ }
+
+ public E peekHead() {
+ synchronized (this.mutex) {
+ return this.deque.peekHead();
+ }
+ }
+
+ public E peekTail() {
+ synchronized (this.mutex) {
+ return this.deque.peekTail();
+ }
+ }
+
+ public boolean isEmpty() {
+ synchronized (this.mutex) {
+ return this.deque.isEmpty();
+ }
+ }
+
+
+ // ********** indefinite waits **********
+
+ /**
+ * Suspend the current thread until the deque's empty status changes
+ * to the specified value.
+ */
+ public void waitUntilEmptyIs(boolean empty) throws InterruptedException {
+ synchronized (this.mutex) {
+ this.waitUntilEmptyIs_(empty);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private void waitUntilEmptyIs_(boolean empty) throws InterruptedException {
+ while (this.deque.isEmpty() != empty) {
+ this.mutex.wait();
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty.
+ */
+ public void waitUntilEmpty() throws InterruptedException {
+ this.waitUntilEmptyIs(true);
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it.
+ */
+ public void waitUntilNotEmpty() throws InterruptedException {
+ this.waitUntilEmptyIs(false);
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty,
+ * then "enqueue" the specified item to the tail of the deque
+ * and continue executing.
+ */
+ public void waitToEnqueueTail(E element) throws InterruptedException {
+ synchronized (this.mutex) {
+ this.waitUntilEmptyIs_(true);
+ this.enqueueTail_(element);
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty,
+ * then "enqueue" the specified item to the head of the deque
+ * and continue executing.
+ */
+ public void waitToEnqueueHead(E element) throws InterruptedException {
+ synchronized (this.mutex) {
+ this.waitUntilEmptyIs_(true);
+ this.enqueueHead_(element);
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it,
+ * then "dequeue" an item from the head of the deque and return it.
+ */
+ public Object waitToDequeueHead() throws InterruptedException {
+ synchronized (this.mutex) {
+ this.waitUntilEmptyIs_(false);
+ return this.dequeueHead_();
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it,
+ * then "dequeue" an item from the tail of the deque and return it.
+ */
+ public Object waitToDequeueTail() throws InterruptedException {
+ synchronized (this.mutex) {
+ this.waitUntilEmptyIs_(false);
+ return this.dequeueTail_();
+ }
+ }
+
+
+ // ********** timed waits **********
+
+ /**
+ * Suspend the current thread until the deque's empty status changes
+ * to the specified value or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if the specified
+ * empty status was achieved; return <code>false</code> if a time-out occurred.
+ * If the deque's empty status is already the specified value,
+ * return <code>true</code> immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public boolean waitUntilEmptyIs(boolean empty, long timeout) throws InterruptedException {
+ synchronized (this.mutex) {
+ return this.waitUntilEmptyIs_(empty, timeout);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean waitUntilEmptyIs_(boolean empty, long timeout) throws InterruptedException {
+ if (timeout == 0L) {
+ this.waitUntilEmptyIs_(empty); // wait indefinitely until notified
+ return true; // if it ever comes back, the condition was met
+ }
+
+ long stop = System.currentTimeMillis() + timeout;
+ long remaining = timeout;
+ while ((this.deque.isEmpty() != empty) && (remaining > 0L)) {
+ this.mutex.wait(remaining);
+ remaining = stop - System.currentTimeMillis();
+ }
+ return (this.deque.isEmpty() == empty);
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the deque is empty; return <code>false</code> if a time-out occurred.
+ * If the deque is already empty, return <code>true</code> immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public boolean waitUntilEmpty(long timeout) throws InterruptedException {
+ return this.waitUntilEmptyIs(true, timeout);
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it.
+ * or the specified time-out occurs.
+ * The time-out is specified in milliseconds. Return <code>true</code> if
+ * the deque is not empty; return <code>false</code> if a time-out occurred.
+ * If the deque already has something on it, return <code>true</code> immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public boolean waitUntilNotEmpty(long timeout) throws InterruptedException {
+ return this.waitUntilEmptyIs(false, timeout);
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty,
+ * then "enqueue" the specified item to the tail of the deque
+ * and continue executing. If the deque is not emptied out
+ * before the time-out, simply continue executing without
+ * "enqueueing" the item.
+ * The time-out is specified in milliseconds. Return <code>true</code> if the
+ * item was enqueued; return <code>false</code> if a time-out occurred.
+ * If the deque is already empty, "enqueue" the specified item and
+ * return <code>true</code> immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public boolean waitToEnqueueTail(E element, long timeout) throws InterruptedException {
+ synchronized (this.mutex) {
+ boolean success = this.waitUntilEmptyIs_(true, timeout);
+ if (success) {
+ this.enqueueTail_(element);
+ }
+ return success;
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque is empty,
+ * then "enqueue" the specified item to the head of the deque
+ * and continue executing. If the deque is not emptied out
+ * before the time-out, simply continue executing without
+ * "enqueueing" the item.
+ * The time-out is specified in milliseconds. Return <code>true</code> if the
+ * item was enqueued; return <code>false</code> if a time-out occurred.
+ * If the deque is already empty, "enqueue" the specified item and
+ * return <code>true</code> immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public boolean waitToEnqueueHead(E element, long timeout) throws InterruptedException {
+ synchronized (this.mutex) {
+ boolean success = this.waitUntilEmptyIs_(true, timeout);
+ if (success) {
+ this.enqueueHead_(element);
+ }
+ return success;
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it,
+ * then "dequeue" an item from the head of the deque and return it.
+ * If the deque is empty and nothing is "enqueued" on to it before the
+ * time-out, throw a no such element exception.
+ * The time-out is specified in milliseconds.
+ * If the deque is not empty, "dequeue" an item and
+ * return it immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public Object waitToDequeueHead(long timeout) throws InterruptedException {
+ synchronized (this.mutex) {
+ boolean success = this.waitUntilEmptyIs_(false, timeout);
+ if (success) {
+ return this.dequeueHead_();
+ }
+ throw new NoSuchElementException();
+ }
+ }
+
+ /**
+ * Suspend the current thread until the deque has something on it,
+ * then "dequeue" an item from the tail of the deque and return it.
+ * If the deque is empty and nothing is "enqueued" on to it before the
+ * time-out, throw a no such element exception.
+ * The time-out is specified in milliseconds.
+ * If the deque is not empty, "dequeue" an item and
+ * return it immediately.
+ * If the time-out is zero, wait indefinitely.
+ */
+ public Object waitToDequeueTail(long timeout) throws InterruptedException {
+ synchronized (this.mutex) {
+ boolean success = this.waitUntilEmptyIs_(false, timeout);
+ if (success) {
+ return this.dequeueTail_();
+ }
+ throw new NoSuchElementException();
+ }
+ }
+
+
+ // ********** synchronized behavior **********
+
+ /**
+ * If the current thread is not interrupted, execute the specified command
+ * with the mutex locked. This is useful for initializing the deque in another
+ * thread.
+ */
+ public void execute(Command command) throws InterruptedException {
+ if (Thread.currentThread().isInterrupted()) {
+ throw new InterruptedException();
+ }
+ synchronized (this.mutex) {
+ command.execute();
+ }
+ }
+
+
+ // ********** additional public protocol **********
+
+ /**
+ * "Enqueue" all the elements returned by the specified iterable to the deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueTailAll(Iterable<? extends E> iterable) {
+ return this.enqueueTailAll(iterable.iterator());
+ }
+
+ /**
+ * "Enqueue" all the elements returned by the specified iterable to the deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueHeadAll(Iterable<? extends E> iterable) {
+ return this.enqueueHeadAll(iterable.iterator());
+ }
+
+ /**
+ * "Enqueue" all the elements returned by the specified iterator to the deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueTailAll(Iterator<? extends E> iterator) {
+ if ( ! iterator.hasNext()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueTailAll_(iterator);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the iterator is not empty.
+ */
+ private boolean enqueueTailAll_(Iterator<? extends E> iterator) {
+ do {
+ this.deque.enqueueTail(iterator.next());
+ } while (iterator.hasNext());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Enqueue" all the elements returned by the specified iterator to the deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueHeadAll(Iterator<? extends E> iterator) {
+ if ( ! iterator.hasNext()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueHeadAll_(iterator);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the iterator is not empty.
+ */
+ private boolean enqueueHeadAll_(Iterator<? extends E> iterator) {
+ do {
+ this.deque.enqueueHead(iterator.next());
+ } while (iterator.hasNext());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Enqueue" all the elements in the specified array to the deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueTailAll(E... array) {
+ int len = array.length;
+ if (len == 0) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueTailAll_(array, len);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the array is not empty.
+ */
+ private boolean enqueueTailAll_(E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ this.deque.enqueueTail(array[i++]);
+ } while (i < arrayLength);
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Enqueue" all the elements in the specified array to the deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueHeadAll(E... array) {
+ int len = array.length;
+ if (len == 0) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueHeadAll_(array, len);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the array is not empty.
+ */
+ private boolean enqueueHeadAll_(E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ this.deque.enqueueHead(array[i++]);
+ } while (i < arrayLength);
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * Pop all the elements from the specified stack and "enqueue" them to the deque's tail.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueTailAll(Stack<? extends E> stack) {
+ if (stack.isEmpty()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueTailAll_(stack);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the stack is not empty.
+ */
+ private boolean enqueueTailAll_(Stack<? extends E> stack) {
+ do {
+ this.deque.enqueueTail(stack.pop());
+ } while ( ! stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * Pop all the elements from the specified stack and "enqueue" them to the deque's head.
+ * Return whether the deque changed as a result.
+ */
+ public boolean enqueueHeadAll(Stack<? extends E> stack) {
+ if (stack.isEmpty()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueHeadAll_(stack);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the stack is not empty.
+ */
+ private boolean enqueueHeadAll_(Stack<? extends E> stack) {
+ do {
+ this.deque.enqueueHead(stack.pop());
+ } while ( ! stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Dequeue" all the elements from the specified deque's head and
+ * "enqueue" them to the deque's tail.
+ * Return whether the deque changed as a result.
+ * @see #drainHeadTo(Deque)
+ */
+ public boolean enqueueTailAll(Deque<? extends E> q) {
+ if (q.isEmpty()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueTailAll_(q);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the deque is not empty.
+ */
+ private boolean enqueueTailAll_(Deque<? extends E> q) {
+ do {
+ this.deque.enqueueTail(q.dequeueHead());
+ } while ( ! q.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Dequeue" all the elements from the specified deque's tail and
+ * "enqueue" them to the deque's head.
+ * Return whether the deque changed as a result.
+ * @see #drainTailTo(Deque)
+ */
+ public boolean enqueueHeadAll(Deque<? extends E> q) {
+ if (q.isEmpty()) {
+ return false;
+ }
+ synchronized (this.mutex) {
+ return this.enqueueHeadAll_(q);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the deque is not empty.
+ */
+ private boolean enqueueHeadAll_(Deque<? extends E> q) {
+ do {
+ this.deque.enqueueHead(q.dequeueTail());
+ } while ( ! q.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head and return them in a list.
+ */
+ public ArrayList<E> drainHead() {
+ ArrayList<E> result = new ArrayList<E>();
+ this.drainHeadTo(result);
+ return result;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail and return them in a list.
+ */
+ public ArrayList<E> drainTail() {
+ ArrayList<E> result = new ArrayList<E>();
+ this.drainTailTo(result);
+ return result;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head into specified collection.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainHeadTo(Collection<? super E> collection) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(collection);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainHeadTo_(Collection<? super E> collection) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ return this.drainHeadTo__(collection);
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the deque is not empty.
+ */
+ private boolean drainHeadTo__(Collection<? super E> collection) {
+ do {
+ collection.add(this.deque.dequeueHead());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail into specified collection.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainTailTo(Collection<? super E> collection) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(collection);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainTailTo_(Collection<? super E> collection) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ return this.drainTailTo__(collection);
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the deque is not empty.
+ */
+ private boolean drainTailTo__(Collection<? super E> collection) {
+ do {
+ collection.add(this.deque.dequeueTail());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head into specified list
+ * at the specified index.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainHeadTo(List<? super E> list, int index) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(list, index);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainHeadTo_(List<? super E> list, int index) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ if (index == list.size()) {
+ return this.drainHeadTo__(list);
+ }
+ ArrayList<E> temp = new ArrayList<E>();
+ this.drainHeadTo__(temp);
+ list.addAll(index, temp);
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail into specified list
+ * at the specified index.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainTailTo(List<? super E> list, int index) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(list, index);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainTailTo_(List<? super E> list, int index) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ if (index == list.size()) {
+ return this.drainTailTo__(list);
+ }
+ ArrayList<E> temp = new ArrayList<E>();
+ this.drainTailTo__(temp);
+ list.addAll(index, temp);
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head into specified stack.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainHeadTo(Stack<? super E> stack) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(stack);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainHeadTo_(Stack<? super E> stack) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ stack.push(this.deque.dequeueHead());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail into specified stack.
+ * Return whether the deque changed as a result.
+ */
+ public boolean drainTailTo(Stack<? super E> stack) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(stack);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainTailTo_(Stack<? super E> stack) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ stack.push(this.deque.dequeueTail());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head into specified deque's tail.
+ * Return whether the deque changed as a result.
+ * @see #enqueueTailAll(Deque)
+ */
+ public boolean drainHeadTo(Deque<? super E> q) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(q);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainHeadTo_(Deque<? super E> q) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ q.enqueueTail(this.deque.dequeueHead());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail into specified deque's head.
+ * Return whether the deque changed as a result.
+ * @see #enqueueTailAll(Deque)
+ */
+ public boolean drainTailTo(Deque<? super E> q) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(q);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainTailTo_(Deque<? super E> q) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ q.enqueueHead(this.deque.dequeueTail());
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each item.
+ * Return whether the deque changed as a result.
+ */
+ public <K> boolean drainHeadTo(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(map, keyTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K> boolean drainHeadTo_(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ MapTools.add(map, this.deque.dequeueHead(), keyTransformer);
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each item.
+ * Return whether the deque changed as a result.
+ */
+ public <K> boolean drainTailTo(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(map, keyTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K> boolean drainTailTo_(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ MapTools.add(map, this.deque.dequeueTail(), keyTransformer);
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's head
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each dequeued item and the specified value transformer
+ * to generator the value for each dequeued item.
+ * Return whether the deque changed as a result.
+ */
+ public <K, V> boolean drainHeadTo(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ synchronized (this.mutex) {
+ return this.drainHeadTo_(map, keyTransformer, valueTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K, V> boolean drainHeadTo_(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ MapTools.add(map, this.deque.dequeueHead(), keyTransformer, valueTransformer);
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the deque's tail
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each dequeued item and the specified value transformer
+ * to generator the value for each dequeued item.
+ * Return whether the deque changed as a result.
+ */
+ public <K, V> boolean drainTailTo(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ synchronized (this.mutex) {
+ return this.drainTailTo_(map, keyTransformer, valueTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K, V> boolean drainTailTo_(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ if (this.deque.isEmpty()) {
+ return false;
+ }
+ do {
+ MapTools.add(map, this.deque.dequeueTail(), keyTransformer, valueTransformer);
+ } while ( ! this.deque.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * Return the object the deque locks on while performing
+ * its operations.
+ */
+ public Object getMutex() {
+ return this.mutex;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public String toString() {
+ synchronized (this.mutex) {
+ return this.deque.toString();
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
+ synchronized (this.mutex) {
+ s.defaultWriteObject();
+ }
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/enumeration/EnumerationTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/enumeration/EnumerationTools.java
index 9ce3de3ae4..6b2ca1ca5d 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/enumeration/EnumerationTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/enumeration/EnumerationTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -53,7 +53,7 @@ public final class EnumerationTools {
* elements in the specified collection.
*/
public static boolean containsAll(Enumeration<?> enumeration, Collection<?> collection) {
- return CollectionTools.set(iterator(enumeration)).containsAll(collection);
+ return CollectionTools.hashSet(iterator(enumeration)).containsAll(collection);
}
/**
@@ -62,7 +62,7 @@ public final class EnumerationTools {
* The specified enumeration size is a performance hint.
*/
public static boolean containsAll(Enumeration<?> enumeration, int enumerationSize, Collection<?> collection) {
- return CollectionTools.set(iterator(enumeration), enumerationSize).containsAll(collection);
+ return CollectionTools.hashSet(iterator(enumeration), enumerationSize).containsAll(collection);
}
/**
@@ -70,7 +70,7 @@ public final class EnumerationTools {
* elements in the specified iterable.
*/
public static boolean containsAll(Enumeration<?> enumeration, Iterable<?> iterable) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration)), iterable);
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration)), iterable);
}
/**
@@ -79,7 +79,7 @@ public final class EnumerationTools {
* The specified enumeration size is a performance hint.
*/
public static boolean containsAll(Enumeration<?> enumeration, int enumerationSize, Iterable<?> iterable) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration), enumerationSize), iterable);
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration), enumerationSize), iterable);
}
/**
@@ -87,7 +87,7 @@ public final class EnumerationTools {
* elements in the specified enumeration 2.
*/
public static boolean containsAll(Enumeration<?> enumeration1, Enumeration<?> enumeration2) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration1)), iterator(enumeration2));
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration1)), iterator(enumeration2));
}
/**
@@ -96,7 +96,7 @@ public final class EnumerationTools {
* The specified iterator 1 size is a performance hint.
*/
public static boolean containsAll(Enumeration<?> enumeration1, int enumeration1Size, Enumeration<?> enumeration2) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration1), enumeration1Size), iterator(enumeration2));
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration1), enumeration1Size), iterator(enumeration2));
}
/**
@@ -104,7 +104,7 @@ public final class EnumerationTools {
* elements in the specified array.
*/
public static boolean containsAll(Enumeration<?> enumeration, Object... array) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration)), array);
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration)), array);
}
/**
@@ -113,7 +113,7 @@ public final class EnumerationTools {
* The specified enumeration size is a performance hint.
*/
public static boolean containsAll(Enumeration<?> enumeration, int enumerationSize, Object... array) {
- return CollectionTools.containsAll(CollectionTools.set(iterator(enumeration), enumerationSize), array);
+ return CollectionTools.containsAll(CollectionTools.hashSet(iterator(enumeration), enumerationSize), array);
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ChainIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ChainIterable.java
index 83bbe90373..babbca5401 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ChainIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ChainIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -56,6 +56,6 @@ public class ChainIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeIterable.java
index 8170130fe8..cf84a8c404 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -66,6 +66,6 @@ public class CompositeIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeListIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeListIterable.java
index cf85171468..45c7c5c265 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeListIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/CompositeListIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -68,6 +68,6 @@ public class CompositeListIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/FilteringIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/FilteringIterable.java
index 2fceff8515..0d6274a9bf 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/FilteringIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/FilteringIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -50,6 +50,6 @@ public class FilteringIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/GraphIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/GraphIterable.java
index aa994633b8..372860398e 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/GraphIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/GraphIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -72,6 +72,6 @@ public class GraphIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java
index 0b84ffbed0..8b45db23fc 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/IterableTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,8 +18,6 @@ import java.util.List;
import java.util.ListIterator;
import org.eclipse.jpt.common.utility.closure.Closure;
import org.eclipse.jpt.common.utility.closure.InterruptibleClosure;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.exception.ExceptionHandler;
import org.eclipse.jpt.common.utility.internal.closure.DisabledClosure;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
@@ -30,6 +28,8 @@ import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
@@ -56,18 +56,18 @@ public final class IterableTools {
}
/**
- * Return a collection corresponding to the specified iterable.
+ * Return a hash bag corresponding to the specified iterable.
*/
- public static <E> HashBag<E> collection(Iterable<? extends E> iterable) {
- return IteratorTools.collection(iterable.iterator());
+ public static <E> HashBag<E> hashBag(Iterable<? extends E> iterable) {
+ return IteratorTools.hashBag(iterable.iterator());
}
/**
- * Return a collection corresponding to the specified iterable.
+ * Return a hash bag corresponding to the specified iterable.
* The specified iterable size is a performance hint.
*/
- public static <E> HashBag<E> collection(Iterable<? extends E> iterable, int iterableSize) {
- return IteratorTools.collection(iterable.iterator(), iterableSize);
+ public static <E> HashBag<E> hashBag(Iterable<? extends E> iterable, int iterableSize) {
+ return IteratorTools.hashBag(iterable.iterator(), iterableSize);
}
/**
@@ -388,7 +388,7 @@ public final class IterableTools {
public static <E> Iterable<E> sort(Iterable<? extends E> iterable, Comparator<? super E> comparator) {
Iterator<? extends E> iterator = iterable.iterator();
if (iterator.hasNext()) {
- return ListTools.sort(ListTools.list(iterator), comparator);
+ return ListTools.sort(ListTools.arrayList(iterator), comparator);
}
return emptyIterable();
}
@@ -400,7 +400,7 @@ public final class IterableTools {
public static <E> Iterable<E> sort(Iterable<? extends E> iterable, Comparator<? super E> comparator, int iterableSize) {
Iterator<? extends E> iterator = iterable.iterator();
if (iterator.hasNext()) {
- return ListTools.sort(ListTools.list(iterator, iterableSize), comparator);
+ return ListTools.sort(ListTools.arrayList(iterator, iterableSize), comparator);
}
return emptyIterable();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/QueueIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/QueueIterable.java
index 7831132475..42e2c1fc1b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/QueueIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/QueueIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,8 @@
package org.eclipse.jpt.common.utility.internal.iterable;
import java.util.Iterator;
-import org.eclipse.jpt.common.utility.collection.Queue;
import org.eclipse.jpt.common.utility.internal.iterator.QueueIterator;
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* A <code>QueueIterable</code> provides an {@link Iterable}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ReadOnlyCompositeListIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ReadOnlyCompositeListIterable.java
index eddb200200..9459e1f873 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ReadOnlyCompositeListIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/ReadOnlyCompositeListIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -68,6 +68,6 @@ public class ReadOnlyCompositeListIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/StackIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/StackIterable.java
index 32e7d61765..8281166013 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/StackIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/StackIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,8 +10,8 @@
package org.eclipse.jpt.common.utility.internal.iterable;
import java.util.Iterator;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.internal.iterator.StackIterator;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* A <code>StackIterable</code> provides an {@link Iterable}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationIterable.java
index ce2962332e..91ac5d96d2 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -52,6 +52,6 @@ public class TransformationIterable<E1, E2>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationListIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationListIterable.java
index a704681a49..e1b3a73f0e 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationListIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TransformationListIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -53,6 +53,6 @@ public class TransformationListIterable<E1, E2>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TreeIterable.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TreeIterable.java
index a9c62a7dd2..d4d6e75c0e 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TreeIterable.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterable/TreeIterable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -58,6 +58,6 @@ public class TreeIterable<E>
@Override
public String toString() {
- return ListTools.list(this).toString();
+ return ListTools.arrayList(this).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/CloneListIterator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/CloneListIterator.java
index ce02223b35..80c63372dd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/CloneListIterator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/CloneListIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -68,7 +68,7 @@ public class CloneListIterator<E>
}
// build a copy of the list and keep it in sync with original (if the mutator allows changes)
// that way the nested list iterator will maintain some of our state
- this.listIterator = ListTools.list(array).listIterator();
+ this.listIterator = ListTools.arrayList(array).listIterator();
this.adapter = adapter;
this.cursor = 0;
this.state = State.UNKNOWN;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java
index 2dc251b80d..1bdd506833 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/IteratorTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,8 +18,6 @@ import java.util.List;
import java.util.ListIterator;
import org.eclipse.jpt.common.utility.closure.Closure;
import org.eclipse.jpt.common.utility.closure.InterruptibleClosure;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.exception.ExceptionHandler;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
@@ -32,6 +30,8 @@ import org.eclipse.jpt.common.utility.internal.iterable.IterableTools;
import org.eclipse.jpt.common.utility.internal.iterator.CloneListIterator.Adapter;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.predicate.Predicate;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
@@ -46,7 +46,7 @@ public final class IteratorTools {
* Return a bag corresponding to the specified iterator.
*/
public static <E> HashBag<E> bag(Iterator<? extends E> iterator) {
- return CollectionTools.bag(iterator);
+ return CollectionTools.hashBag(iterator);
}
/**
@@ -54,22 +54,22 @@ public final class IteratorTools {
* The specified iterator size is a performance hint.
*/
public static <E> HashBag<E> bag(Iterator<? extends E> iterator, int iteratorSize) {
- return CollectionTools.bag(iterator, iteratorSize);
+ return CollectionTools.hashBag(iterator, iteratorSize);
}
/**
- * Return a collection corresponding to the specified iterator.
+ * Return a hash bag corresponding to the specified iterator.
*/
- public static <E> HashBag<E> collection(Iterator<? extends E> iterator) {
- return CollectionTools.collection(iterator);
+ public static <E> HashBag<E> hashBag(Iterator<? extends E> iterator) {
+ return CollectionTools.hashBag(iterator);
}
/**
- * Return a collection corresponding to the specified iterator.
+ * Return a hash bag corresponding to the specified iterator.
* The specified iterator size is a performance hint.
*/
- public static <E> HashBag<E> collection(Iterator<? extends E> iterator, int iteratorSize) {
- return CollectionTools.collection(iterator, iteratorSize);
+ public static <E> HashBag<E> hashBag(Iterator<? extends E> iterator, int iteratorSize) {
+ return CollectionTools.hashBag(iterator, iteratorSize);
}
/**
@@ -155,7 +155,7 @@ public final class IteratorTools {
* elements in the specified collection.
*/
public static boolean containsAll(Iterator<?> iterator, Collection<?> collection) {
- return collection.isEmpty() || CollectionTools.set(iterator).containsAll(collection);
+ return collection.isEmpty() || CollectionTools.hashSet(iterator).containsAll(collection);
}
/**
@@ -164,7 +164,7 @@ public final class IteratorTools {
* The specified iterator size is a performance hint.
*/
public static boolean containsAll(Iterator<?> iterator, int iteratorSize, Collection<?> collection) {
- return collection.isEmpty() || CollectionTools.set(iterator, iteratorSize).containsAll(collection);
+ return collection.isEmpty() || CollectionTools.hashSet(iterator, iteratorSize).containsAll(collection);
}
/**
@@ -189,7 +189,7 @@ public final class IteratorTools {
* elements in the specified iterator 2.
*/
public static boolean containsAll(Iterator<?> iterator1, Iterator<?> iterator2) {
- return isEmpty(iterator2) || CollectionTools.containsAll(CollectionTools.set(iterator1), iterator2);
+ return isEmpty(iterator2) || CollectionTools.containsAll(CollectionTools.hashSet(iterator1), iterator2);
}
/**
@@ -198,7 +198,7 @@ public final class IteratorTools {
* The specified iterator 1 size is a performance hint.
*/
public static boolean containsAll(Iterator<?> iterator1, int iterator1Size, Iterator<?> iterator2) {
- return isEmpty(iterator2) || CollectionTools.containsAll(CollectionTools.set(iterator1, iterator1Size), iterator2);
+ return isEmpty(iterator2) || CollectionTools.containsAll(CollectionTools.hashSet(iterator1, iterator1Size), iterator2);
}
/**
@@ -206,7 +206,7 @@ public final class IteratorTools {
* elements in the specified array.
*/
public static boolean containsAll(Iterator<?> iterator, Object... array) {
- return (array.length == 0) || CollectionTools.containsAll(CollectionTools.set(iterator), array);
+ return (array.length == 0) || CollectionTools.containsAll(CollectionTools.hashSet(iterator), array);
}
/**
@@ -215,7 +215,7 @@ public final class IteratorTools {
* The specified iterator size is a performance hint.
*/
public static boolean containsAll(Iterator<?> iterator, int iteratorSize, Object... array) {
- return (array.length == 0) || CollectionTools.containsAll(CollectionTools.set(iterator, iteratorSize), array);
+ return (array.length == 0) || CollectionTools.containsAll(CollectionTools.hashSet(iterator, iteratorSize), array);
}
/**
@@ -472,7 +472,7 @@ public final class IteratorTools {
* Return a list corresponding to the specified iterator.
*/
public static <E> ArrayList<E> list(Iterator<? extends E> iterator) {
- return ListTools.list(iterator);
+ return ListTools.arrayList(iterator);
}
/**
@@ -480,7 +480,7 @@ public final class IteratorTools {
* The specified iterator size is a performance hint.
*/
public static <E> ArrayList<E> list(Iterator<? extends E> iterator, int iteratorSize) {
- return ListTools.list(iterator, iteratorSize);
+ return ListTools.arrayList(iterator, iteratorSize);
}
/**
@@ -533,7 +533,7 @@ public final class IteratorTools {
if (isEmpty(iterator)) {
return emptyListIterator();
}
- return ListTools.sort(ListTools.list(iterator), comparator).listIterator();
+ return ListTools.sort(ListTools.arrayList(iterator), comparator).listIterator();
}
/**
@@ -544,7 +544,7 @@ public final class IteratorTools {
if (isEmpty(iterator)) {
return emptyListIterator();
}
- return ListTools.sort(ListTools.list(iterator, iteratorSize), comparator).listIterator();
+ return ListTools.sort(ListTools.arrayList(iterator, iteratorSize), comparator).listIterator();
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/QueueIterator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/QueueIterator.java
index 2f6a5ad834..12c59349fa 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/QueueIterator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/QueueIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,9 +10,8 @@
package org.eclipse.jpt.common.utility.internal.iterator;
import java.util.Iterator;
-
-import org.eclipse.jpt.common.utility.collection.Queue;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* A <code>QueueIterator</code> provides an {@link Iterator}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/ReverseIterator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/ReverseIterator.java
index 256b69525f..4ee3b96243 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/ReverseIterator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/ReverseIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -35,14 +35,14 @@ public class ReverseIterator<E>
* Construct a reverse iterator for the specified iterator.
*/
public ReverseIterator(Iterator<? extends E> iterator) {
- this(ListTools.reverse(ListTools.list(iterator)));
+ this(ListTools.reverse(ListTools.arrayList(iterator)));
}
/**
* Construct a reverse iterator for the specified iterator.
*/
public ReverseIterator(Iterator<? extends E> iterator, int size) {
- this(ListTools.reverse(ListTools.list(iterator, size)));
+ this(ListTools.reverse(ListTools.arrayList(iterator, size)));
}
private ReverseIterator(ArrayList<E> reverseList) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/StackIterator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/StackIterator.java
index e1108cf1bd..cc9dad4343 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/StackIterator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterator/StackIterator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -10,9 +10,8 @@
package org.eclipse.jpt.common.utility.internal.iterator;
import java.util.Iterator;
-
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* A <code>StackIterator</code> provides an {@link Iterator}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
index 269b4e9a2e..7b796ef4f2 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -1233,7 +1233,7 @@ public class ChangeSupport {
* no empty checks
*/
protected boolean removeItemsFromCollection_(Iterator<?> items, Collection<?> collection, String collectionName) {
- HashBag<?> removedItems = CollectionTools.collection(items);
+ HashBag<?> removedItems = CollectionTools.hashBag(items);
removedItems.retainAll(collection);
boolean changed = collection.removeAll(removedItems);
@@ -1305,8 +1305,8 @@ public class ChangeSupport {
* no empty checks
*/
protected boolean retainItemsInCollection_(Iterator<?> items, Collection<?> collection, String collectionName) {
- HashBag<?> retainedItems = CollectionTools.collection(items);
- HashBag<?> removedItems = CollectionTools.collection(collection);
+ HashBag<?> retainedItems = CollectionTools.hashBag(items);
+ HashBag<?> removedItems = CollectionTools.hashBag(collection);
removedItems.removeAll(retainedItems);
boolean changed = collection.retainAll(retainedItems);
@@ -1378,7 +1378,7 @@ public class ChangeSupport {
return this.addItemsToCollection_(newCollection, collection, collectionName);
}
- return this.synchronizeCollection_(CollectionTools.collection(newCollection), collection, collectionName);
+ return this.synchronizeCollection_(CollectionTools.hashBag(newCollection), collection, collectionName);
}
/**
@@ -2191,7 +2191,7 @@ public class ChangeSupport {
return false;
}
- ArrayList<E> addedItems = ListTools.list(items);
+ ArrayList<E> addedItems = ListTools.arrayList(items);
if (list.addAll(index, addedItems)) {
this.fireItemsAdded(listName, index, addedItems);
return true;
@@ -2264,7 +2264,7 @@ public class ChangeSupport {
* no empty check
*/
protected <E> boolean addItemsToList_(Iterator<? extends E> items, List<E> list, String listName) {
- ArrayList<E> addedItems = ListTools.list(items);
+ ArrayList<E> addedItems = ListTools.arrayList(items);
int index = list.size();
if (list.addAll(addedItems)) {
this.fireItemsAdded(listName, index, addedItems);
@@ -2467,8 +2467,8 @@ public class ChangeSupport {
* no empty checks
*/
protected boolean retainItemsInList_(Iterator<?> items, List<?> list, String listName) {
- HashBag<?> retainedItems = CollectionTools.collection(items);
- HashBag<?> removedItems = CollectionTools.collection(list);
+ HashBag<?> retainedItems = CollectionTools.hashBag(items);
+ HashBag<?> removedItems = CollectionTools.hashBag(list);
removedItems.removeAll(retainedItems);
return this.removeItemsFromList(removedItems, list, listName);
}
@@ -2642,7 +2642,7 @@ public class ChangeSupport {
if (list.isEmpty()) {
return this.addItemsToList_(newList, list, listName);
}
- return this.synchronizeList_(ListTools.list(newList), list, listName);
+ return this.synchronizeList_(ListTools.arrayList(newList), list, listName);
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTPropertyChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTPropertyChangeListenerWrapper.java
index 0f5ecad022..db3dd3da42 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTPropertyChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTPropertyChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,7 +11,8 @@ package org.eclipse.jpt.common.utility.internal.model.listener.awt;
import java.awt.EventQueue;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
-import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
+import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
+import org.eclipse.jpt.common.utility.internal.queue.SynchronizedQueue;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
@@ -32,7 +33,7 @@ public final class AWTPropertyChangeListenerWrapper
implements PropertyChangeListener
{
private final PropertyChangeListener listener;
- private final SynchronizedQueue<PropertyChangeEvent> events = new SynchronizedQueue<PropertyChangeEvent>();
+ private final SynchronizedQueue<PropertyChangeEvent> events = QueueTools.synchronizedQueue();
public AWTPropertyChangeListenerWrapper(PropertyChangeListener listener) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTStateChangeListenerWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTStateChangeListenerWrapper.java
index 600014f51d..3d78f7bbcd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTStateChangeListenerWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/listener/awt/AWTStateChangeListenerWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -11,7 +11,8 @@ package org.eclipse.jpt.common.utility.internal.model.listener.awt;
import java.awt.EventQueue;
import org.eclipse.jpt.common.utility.internal.RunnableAdapter;
-import org.eclipse.jpt.common.utility.internal.collection.SynchronizedQueue;
+import org.eclipse.jpt.common.utility.internal.queue.QueueTools;
+import org.eclipse.jpt.common.utility.internal.queue.SynchronizedQueue;
import org.eclipse.jpt.common.utility.model.event.StateChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;
@@ -30,7 +31,7 @@ public final class AWTStateChangeListenerWrapper
implements StateChangeListener
{
private final StateChangeListener listener;
- private final SynchronizedQueue<StateChangeEvent> events = new SynchronizedQueue<StateChangeEvent>();
+ private final SynchronizedQueue<StateChangeEvent> events = QueueTools.synchronizedQueue();
public AWTStateChangeListenerWrapper(StateChangeListener listener) {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractTreeNodeValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractTreeNodeValueModel.java
index 6300294bfc..b4315334c0 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractTreeNodeValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AbstractTreeNodeValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -114,7 +114,7 @@ public abstract class AbstractTreeNodeValueModel<V>
@SuppressWarnings("unchecked")
public TreeNodeValueModel<V>[] path() {
- List<TreeNodeValueModel<V>> path = ListTools.reverse(ListTools.list(this.backPath()));
+ List<TreeNodeValueModel<V>> path = ListTools.reverse(ListTools.arrayList(this.backPath()));
return path.toArray(new TreeNodeValueModel[path.size()]);
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
index 4736f8fe2e..74bb555e15 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectCollectionValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -147,7 +147,7 @@ public abstract class AspectCollectionValueModelAdapter<S, E>
}
protected Collection<E> buildValueCollection() {
- return CollectionTools.collection(this.iterator());
+ return CollectionTools.hashBag(this.iterator());
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
index 6b7ea124a4..227ba6bddd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/AspectListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -189,7 +189,7 @@ public abstract class AspectListValueModelAdapter<S, E>
}
protected List<E> buildValueList() {
- return ListTools.list(this.iterator());
+ return ListTools.arrayList(this.iterator());
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
index b720c883cc..54a5a00187 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -344,7 +344,7 @@ public class CompositeCollectionValueModel<E1, E2>
protected void collectionChanged(CollectionChangeEvent event) {
this.removeAllComponentSources();
this.addAllComponentSources();
- this.fireCollectionChanged(VALUES, CollectionTools.collection(this.iterator()));
+ this.fireCollectionChanged(VALUES, CollectionTools.hashBag(this.iterator()));
}
@@ -396,7 +396,7 @@ public class CompositeCollectionValueModel<E1, E2>
ArrayList<E2> componentCollection = this.collections.get(componentCVM);
this.removeComponentItems(componentCollection);
this.addComponentItems(componentCVM, componentCollection);
- this.fireCollectionChanged(VALUES, CollectionTools.collection(this.iterator()));
+ this.fireCollectionChanged(VALUES, CollectionTools.hashBag(this.iterator()));
}
// minimize scope of suppressed warnings
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
index ac9e7d2900..ff4406a642 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/CompositeListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -479,14 +479,14 @@ public class CompositeListValueModel<E1, E2>
protected Iterable<? extends E1> buildSubListHolder(int fromIndex) {
int listModelSize = this.listModel.size();
- return ListTools.list(this.listModel, listModelSize).subList(fromIndex, listModelSize);
+ return ListTools.arrayList(this.listModel, listModelSize).subList(fromIndex, listModelSize);
}
protected Iterable<? extends E1> buildSubListHolder(int fromIndex, int toIndex) {
int listModelSize = this.listModel.size();
return ((fromIndex == 0) && (toIndex == listModelSize)) ?
this.listModel :
- ListTools.list(this.listModel, listModelSize).subList(fromIndex, toIndex);
+ ListTools.arrayList(this.listModel, listModelSize).subList(fromIndex, toIndex);
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ExtendedListValueModelWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ExtendedListValueModelWrapper.java
index 9d1fe07aa4..4545b8bd64 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ExtendedListValueModelWrapper.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ExtendedListValueModelWrapper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -206,7 +206,7 @@ public class ExtendedListValueModelWrapper<E>
}
private List<E> buildList() {
- return ListTools.list(this.listIterator_());
+ return ListTools.arrayList(this.listIterator_());
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemAspectListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemAspectListValueModelAdapter.java
index 0d922e3c73..a567b95257 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemAspectListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ItemAspectListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -268,7 +268,7 @@ public abstract class ItemAspectListValueModelAdapter<E>
* whether the item aspect change is significant.
*/
protected void itemAspectChanged(@SuppressWarnings("unused") EventObject event) {
- this.fireListChanged(LIST_VALUES, ListTools.list(this.listModel, this.listModel.size()));
+ this.fireListChanged(LIST_VALUES, ListTools.arrayList(this.listModel, this.listModel.size()));
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
index 71b92caca7..a95b278f6b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/ListCurator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -180,7 +180,7 @@ public abstract class ListCurator<S extends Model, E>
// ********** behavior **********
void submitInventoryReport() {
- List<E> newRecord = ListTools.list(this.iteratorForRecord());
+ List<E> newRecord = ListTools.arrayList(this.iteratorForRecord());
int recordIndex = 0;
// add items from the new record
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
index d10e73672f..3842893b13 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -137,9 +137,9 @@ public class SimpleCollectionValueModel<E>
return true;
}
if ((o instanceof Collection<?>) && (o instanceof CollectionValueModel<?>)) {
- Collection<E> c1 = CollectionTools.collection(this.collection);
+ Collection<E> c1 = CollectionTools.hashBag(this.collection);
@SuppressWarnings("unchecked")
- Collection<E> c2 = CollectionTools.collection(((Collection<E>) o).iterator());
+ Collection<E> c2 = CollectionTools.hashBag(((Collection<E>) o).iterator());
return c1.equals(c2);
}
return false;
@@ -147,7 +147,7 @@ public class SimpleCollectionValueModel<E>
@Override
public int hashCode() {
- return CollectionTools.collection(this.collection).hashCode();
+ return CollectionTools.hashBag(this.collection).hashCode();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
index f2056b9493..da81f0c2de 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SimpleListValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -152,9 +152,9 @@ public class SimpleListValueModel<E>
return true;
}
if ((o instanceof List<?>) && (o instanceof ListValueModel<?>)) {
- List<E> l1 = ListTools.list(this.list);
+ List<E> l1 = ListTools.arrayList(this.list);
@SuppressWarnings("unchecked")
- List<E> l2 = ListTools.list(((List<E>) o).iterator());
+ List<E> l2 = ListTools.arrayList(((List<E>) o).iterator());
return l1.equals(l2);
}
return false;
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
index 39bcd0cb9d..455ef6ae00 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/SortedListValueModelAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -105,7 +105,7 @@ public class SortedListValueModelAdapter<E>
@Override
protected Iterable<? extends E> buildSyncList() {
- return CollectionTools.sortedSet(this.collectionHolder, this.comparator, this.collectionHolder.size());
+ return CollectionTools.treeSet(this.collectionHolder, this.comparator, this.collectionHolder.size());
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
index 58f65bff5b..23dfebd425 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/prefs/PreferencesCollectionValueModel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -133,7 +133,7 @@ public class PreferencesCollectionValueModel<P>
@Override
protected void fireAspectChanged(Object oldValue, Object newValue) {
@SuppressWarnings("unchecked") Iterator<PreferencePropertyValueModel<P>> iterator = (Iterator<PreferencePropertyValueModel<P>>) newValue;
- this.fireCollectionChanged(VALUES, CollectionTools.collection(iterator));
+ this.fireCollectionChanged(VALUES, CollectionTools.hashBag(iterator));
}
@Override
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/AbstractArrayQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/AbstractArrayQueue.java
new file mode 100644
index 0000000000..0f9d7569d8
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/AbstractArrayQueue.java
@@ -0,0 +1,172 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Abstract array implementation of the {@link Queue} interface.
+ * @param <E> the type of elements maintained by the queue
+ */
+public abstract class AbstractArrayQueue<E>
+ implements Queue<E>, Cloneable, Serializable
+{
+ protected transient E[] elements;
+
+ /** Index of next element to be "dequeued". */
+ protected transient int head = 0;
+
+ /** Index of next element to be "enqueued". */
+ protected transient int tail = 0;
+
+ protected int size = 0;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty queue with the specified initial capacity.
+ */
+ @SuppressWarnings("unchecked")
+ protected AbstractArrayQueue(int initialCapacity) {
+ super();
+ if (initialCapacity < 0) {
+ throw new IllegalArgumentException("Illegal capacity: " + initialCapacity); //$NON-NLS-1$
+ }
+ this.elements = (E[]) new Object[initialCapacity];
+ }
+
+
+ // ********** Queue implementation **********
+
+ public void enqueue(E element) {
+ this.elements[this.tail] = element;
+ if (++this.tail == this.elements.length) {
+ this.tail = 0;
+ }
+ this.size++;
+ }
+
+ public E dequeue() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ E element = this.elements[this.head];
+ this.elements[this.head] = null; // allow GC to work
+ if (++this.head == this.elements.length) {
+ this.head = 0;
+ }
+ this.size--;
+ return element;
+ }
+
+ public E peek() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.elements[this.head];
+ }
+
+ public boolean isEmpty() {
+ return this.size == 0;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public AbstractArrayQueue<E> clone() {
+ try {
+ @SuppressWarnings("unchecked")
+ AbstractArrayQueue<E> clone = (AbstractArrayQueue<E>) super.clone();
+ @SuppressWarnings("cast")
+ E[] array = (E[]) this.elements.clone();
+ clone.elements = array;
+ return clone;
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.copyElements(this.size));
+ }
+
+ protected E[] copyElements(int newCapacity) {
+ @SuppressWarnings("unchecked")
+ E[] newElements = (E[]) new Object[newCapacity];
+ if (this.size != 0) {
+ int t = this.tail;
+ if (t == 0) {
+ t = this.elements.length;
+ }
+ if (this.head < t) {
+ // elements are contiguous
+ System.arraycopy(this.elements, this.head, newElements, 0, this.size);
+ } else {
+ // elements wrap past end of array
+ int fragmentSize = this.elements.length - this.head;
+ System.arraycopy(this.elements, this.head, newElements, 0, fragmentSize);
+ System.arraycopy(this.elements, 0, newElements, fragmentSize, (this.size - fragmentSize));
+ }
+ }
+ return newElements;
+ }
+
+
+ // ********** Serializable "implementation" **********
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
+ // write size (and any hidden stuff)
+ stream.defaultWriteObject();
+ int elementsLength = this.elements.length;
+ stream.writeInt(elementsLength);
+ if (this.size == 0) {
+ return;
+ }
+ // save the elements in contiguous order
+ int t = this.tail;
+ if (t == 0) {
+ t = elementsLength;
+ }
+ if (this.head < t) { // elements are contiguous
+ for (int i = this.head; i < t; i++) {
+ stream.writeObject(this.elements[i]);
+ }
+ } else { // (this.head >= t) - elements wrap past end of array
+ for (int i = this.head; i < elementsLength; i++) {
+ stream.writeObject(this.elements[i]);
+ }
+ for (int i = 0; i < this.tail; i++) {
+ stream.writeObject(this.elements[i]);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
+ // read size (and any hidden stuff)
+ stream.defaultReadObject();
+ int elementsLength = stream.readInt();
+ Object[] array = new Object[elementsLength];
+ for (int i = 0; i < this.size; i++) {
+ array[i] = stream.readObject();
+ }
+ this.elements = (E[]) array;
+ this.head = 0;
+ this.tail = this.size;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ArrayQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ArrayQueue.java
new file mode 100644
index 0000000000..5d0db4dbeb
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ArrayQueue.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2012, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Resizable-array FIFO implementation of the {@link Queue} interface.
+ * @param <E> the type of elements maintained by the queue
+ * @see FixedCapacityArrayQueue
+ * @see QueueTools
+ */
+public class ArrayQueue<E>
+ extends AbstractArrayQueue<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty queue with the specified initial capacity.
+ */
+ public ArrayQueue(int initialCapacity) {
+ super(initialCapacity);
+ }
+
+
+ // ********** Queue implementation **********
+
+ @Override
+ public void enqueue(E element) {
+ this.ensureCapacity(this.size + 1);
+ super.enqueue(element);
+ }
+
+ /**
+ * Increase the queue's capacity, if necessary, to ensure it has at least
+ * the specified minimum capacity.
+ */
+ public void ensureCapacity(int minCapacity) {
+ if (this.elements.length < minCapacity) {
+ int newCapacity = ((this.elements.length * 3) >> 1) + 1;
+ if (newCapacity < minCapacity) {
+ newCapacity = minCapacity;
+ }
+ this.elements = this.copyElements(newCapacity);
+ this.head = 0;
+ this.tail = this.size;
+ }
+ }
+
+ /**
+ * Decrease the queue's capacity, if necessary, to match its current size.
+ */
+ public void trimToSize() {
+ if (this.elements.length > this.size) {
+ this.elements = this.copyElements(this.size);
+ this.head = 0;
+ this.tail = this.size;
+ }
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public ArrayQueue<E> clone() {
+ return (ArrayQueue<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/DequeQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/DequeQueue.java
new file mode 100644
index 0000000000..041d4e4231
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/DequeQueue.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import java.io.Serializable;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Adapt a {@link Deque} to the {@link Queue} interface.
+ * Elements are dequeued from the head of the deque and
+ * enqueued to the tail of the deque.
+ * @param <E> the type of elements maintained by the queue
+ * @see QueueTools
+ */
+public class DequeQueue<E>
+ implements Queue<E>, Serializable
+{
+ private Deque<E> deque;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a queue, adapting the specified deque.
+ * Elements are dequeued from the head of the deque and
+ * enqueued to the tail of the deque.
+ */
+ public DequeQueue(Deque<E> deque) {
+ super();
+ this.deque = deque;
+ }
+
+
+ // ********** Queue implementation **********
+
+ public void enqueue(E element) {
+ this.deque.enqueueTail(element);
+ }
+
+ public E dequeue() {
+ return this.deque.dequeueHead();
+ }
+
+ public E peek() {
+ return this.deque.peekHead();
+ }
+
+ public boolean isEmpty() {
+ return this.deque.isEmpty();
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public String toString() {
+ return this.deque.toString();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/EmptyQueue.java
index 074e885f3e..2d4c277d55 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/EmptyQueue.java
@@ -7,11 +7,11 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* Empty implementation of the {@link Queue} interface.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/FixedCapacityArrayQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/FixedCapacityArrayQueue.java
new file mode 100644
index 0000000000..124bdc706a
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/FixedCapacityArrayQueue.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Fixed-capacity array FIFO implementation of the {@link Queue} interface.
+ * This implementation will throw an exception if its capacity is exceeded.
+ * @param <E> the type of elements maintained by the queue
+ * @see ArrayQueue
+ * @see QueueTools
+ */
+public class FixedCapacityArrayQueue<E>
+ extends AbstractArrayQueue<E>
+{
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty queue with the specified capacity.
+ */
+ public FixedCapacityArrayQueue(int capacity) {
+ super(capacity);
+ }
+
+
+ // ********** Queue implementation **********
+
+ /**
+ * @exception IllegalStateException if the queue is full
+ */
+ @Override
+ public void enqueue(E element) {
+ if (this.isFull()) {
+ throw new IllegalStateException("Queue is full."); //$NON-NLS-1$
+ }
+ super.enqueue(element);
+ }
+
+ /**
+ * Return whether the queue is full,
+ * as its capacity is fixed.
+ */
+ public boolean isFull() {
+ return this.size == this.elements.length;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public FixedCapacityArrayQueue<E> clone() {
+ return (FixedCapacityArrayQueue<E>) super.clone();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/LinkedQueue.java
index ee07946479..83aeb357f5 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/LinkedQueue.java
@@ -7,13 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
import java.util.Arrays;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* Linked FIFO implementation of the {@link Queue} interface.
@@ -221,6 +221,11 @@ public class LinkedQueue<E>
return this;
}
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
@@ -269,5 +274,10 @@ public class LinkedQueue<E>
NodeFactory<E> copy() {
return new CachingNodeFactory<E>(this.maxCacheSize);
}
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.cacheSize);
+ }
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ListQueue.java
index c119164dd1..14fe489a31 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/ListQueue.java
@@ -7,12 +7,12 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
import java.util.List;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* Adapt a {@link List} to the {@link Queue} interface.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/PriorityQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/PriorityQueue.java
new file mode 100644
index 0000000000..6dec365f41
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/PriorityQueue.java
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+
+/**
+ * Resizable priority implementation of the {@link Queue} interface.
+ * Elements will dequeue in the order determined by a comparator
+ * (i.e. {@link #dequeue} will return the element sorted first).
+ * @param <E> the type of elements maintained by the queue
+ * @see QueueTools
+ */
+public class PriorityQueue<E>
+ implements Queue<E>, Cloneable, Serializable
+{
+ private final Comparator<? super E> comparator;
+
+ /**
+ * Standard heap implementation.
+ * To simplify our math, we leave the first slot [0] empty.
+ */
+ private transient E[] elements;
+
+ private int size = 0;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct an empty priority queue with the specified comparator
+ * and initial capacity.
+ */
+ @SuppressWarnings("unchecked")
+ public PriorityQueue(Comparator<? super E> comparator, int initialCapacity) {
+ super();
+ if (comparator == null) {
+ throw new NullPointerException();
+ }
+ this.comparator = comparator;
+ if (initialCapacity < 0) {
+ throw new IllegalArgumentException("Illegal capacity: " + initialCapacity); //$NON-NLS-1$
+ }
+
+ this.elements = (E[]) new Object[initialCapacity + 1];
+ }
+
+ /**
+ * Construct a priority queue with the specified comparator,
+ * initial array of elements, and size. The array of elements
+ * should hold elements at contiguous indices from
+ * 1 to the the specified size, inclusive. The array should <em>not</em>
+ * hold an element at index 0. The queue will <em>not</em> copy the
+ * elements from the supplied array; i.e. the queue will directly use
+ * and manipulate the supplied array.
+ */
+ public PriorityQueue(Comparator<? super E> comparator, E[] initialElements, int size) {
+ super();
+ if (comparator == null) {
+ throw new NullPointerException();
+ }
+ this.comparator = comparator;
+
+ if (initialElements == null) {
+ throw new NullPointerException();
+ }
+ if (initialElements.length == 0) {
+ throw new IllegalArgumentException("Initial elements array must have a length of at least 1."); //$NON-NLS-1$
+ }
+ this.elements = initialElements;
+
+ if (size < 0) {
+ throw new IllegalArgumentException("Illegal size: " + size); //$NON-NLS-1$
+ }
+ this.size = size;
+
+ if (this.size > 1) {
+ // this is similar to what we do when an element is dequeued
+ int nonLeafMax = this.size >> 1;
+ for (int i = nonLeafMax; i > 0; i--) { // we need move only non-leaf nodes
+ int current = i;
+ do {
+ int child = current << 1; // left child
+ if ((child < this.size) && (this.comparator.compare(this.elements[child + 1], this.elements[child]) < 0)) {
+ // right child exists and is less than left (i.e. dequeues first)
+ child++;
+ }
+ if (this.comparator.compare(this.elements[current], this.elements[child]) < 0) {
+ break;
+ }
+ ArrayTools.swap(this.elements, current, child);
+ current = child;
+ } while (current <= nonLeafMax); // i.e. not a leaf (i.e. has at least one child)
+ }
+ }
+ }
+
+
+ // ********** Queue implementation **********
+
+ public void enqueue(E element) {
+ this.ensureCapacity(this.size + 1);
+ this.size++;
+ int current = this.size;
+ this.elements[current] = element;
+ int parent = current >> 1;
+ while ((parent != 0) && this.comparator.compare(this.elements[current], this.elements[parent]) < 0) {
+ ArrayTools.swap(this.elements, current, parent);
+ current = parent;
+ parent = current >> 1;
+ }
+ }
+
+ /**
+ * Increase the queue's capacity, if necessary, to ensure it has at least
+ * the specified minimum capacity.
+ */
+ public void ensureCapacity(int minCapacity) {
+ int oldCapacity = this.elements.length - 1;
+ if (oldCapacity < minCapacity) {
+ int newCapacity = ((oldCapacity * 3) >> 1) + 1;
+ if (newCapacity < minCapacity) {
+ newCapacity = minCapacity;
+ }
+ this.elements = this.copyElements(newCapacity);
+ }
+ }
+
+ /**
+ * Decrease the queue's capacity, if necessary, to match its current size.
+ */
+ public void trimToSize() {
+ if (this.elements.length > this.size + 1) {
+ this.elements = this.copyElements(this.size);
+ }
+ }
+
+ private E[] copyElements(int newCapacity) {
+ @SuppressWarnings("unchecked")
+ E[] newElements = (E[]) new Object[newCapacity + 1];
+ System.arraycopy(this.elements, 1, newElements, 1, this.size); // skip 0
+ return newElements;
+ }
+
+ public E dequeue() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ E element = this.elements[1];
+ if (this.size != 1) {
+ // replace root with last node and move it to its new position
+ ArrayTools.swap(this.elements, 1, this.size);
+ int newSize = this.size - 1;
+ int nonLeafMax = newSize >> 1;
+ int current = 1;
+ while (current <= nonLeafMax) { // i.e. not a leaf (i.e. has at least one child)
+ int child = current << 1; // left child
+ if ((child < newSize) && (this.comparator.compare(this.elements[child + 1], this.elements[child]) < 0)) {
+ // right child exists and is less than left (i.e. dequeues first)
+ child++;
+ }
+ if (this.comparator.compare(this.elements[current], this.elements[child]) < 0) {
+ break;
+ }
+ ArrayTools.swap(this.elements, current, child);
+ current = child;
+ }
+ }
+ this.elements[this.size] = null; // allow GC to work
+ this.size--;
+ return element;
+ }
+
+ public E peek() {
+ if (this.size == 0) {
+ throw new NoSuchElementException();
+ }
+ return this.elements[1];
+ }
+
+ public boolean isEmpty() {
+ return this.size == 0;
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public PriorityQueue<E> clone() {
+ try {
+ @SuppressWarnings("unchecked")
+ PriorityQueue<E> clone = (PriorityQueue<E>) super.clone();
+ @SuppressWarnings("cast")
+ E[] array = (E[]) this.elements.clone();
+ clone.elements = array;
+ return clone;
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(ArrayTools.subArray(this.elements, 1, this.size + 1));
+ }
+
+
+ // ********** Serializable "implementation" **********
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {
+ // write comparator and size (and any hidden stuff)
+ stream.defaultWriteObject();
+ Object[] array = this.elements;
+ int elementsLength = array.length;
+ stream.writeInt(elementsLength);
+ if (this.size == 0) {
+ return;
+ }
+ for (int i = 1; i <= this.size; i++) { // skip 0
+ stream.writeObject(array[i]);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException, ClassNotFoundException {
+ // read comparator and size (and any hidden stuff)
+ stream.defaultReadObject();
+ int elementsLength = stream.readInt();
+ Object[] array = new Object[elementsLength];
+ for (int i = 1; i <= this.size; i++) { // skip 0
+ array[i] = stream.readObject();
+ }
+ this.elements = (E[]) array;
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/QueueTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/QueueTools.java
new file mode 100644
index 0000000000..88b7bb3707
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/QueueTools.java
@@ -0,0 +1,534 @@
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.queue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.internal.comparator.ComparatorTools;
+import org.eclipse.jpt.common.utility.internal.stack.ArrayStack;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+
+/**
+ * {@link Queue} utility methods.
+ */
+public final class QueueTools {
+
+ // ********** enqueue all **********
+
+ /**
+ * Enqueue all the elements returned by the specified iterable
+ * on the specified queue.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean enqueueAll(Queue<? super E> queue, Iterable<? extends E> iterable) {
+ return enqueueAll(queue, iterable.iterator());
+ }
+
+ /**
+ * Enqueue all the elements returned by the specified iterator
+ * on the specified queue.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean enqueueAll(Queue<? super E> queue, Iterator<? extends E> iterator) {
+ return iterator.hasNext() && enqueueAll_(queue, iterator);
+ }
+
+ /**
+ * assume the iterator is not empty
+ */
+ private static <E> boolean enqueueAll_(Queue<? super E> queue, Iterator<? extends E> iterator) {
+ do {
+ queue.enqueue(iterator.next());
+ } while (iterator.hasNext());
+ return true;
+ }
+
+ /**
+ * Enqueue all the elements in the specified array
+ * on the specified queue.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean enqueueAll(Queue<? super E> queue, E... array) {
+ int len = array.length;
+ return (len != 0) && enqueueAll_(queue, array, len);
+ }
+
+ /**
+ * assume the array is not empty
+ */
+ private static <E> boolean enqueueAll_(Queue<? super E> queue, E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ queue.enqueue(array[i++]);
+ } while (i < arrayLength);
+ return true;
+ }
+
+
+ // ********** drain **********
+
+ /**
+ * Drain all the elements from the specified queue and return them in a
+ * list.
+ */
+ public static <E> ArrayList<E> drain(Queue<? extends E> queue) {
+ ArrayList<E> result = new ArrayList<E>();
+ drainTo(queue, result);
+ return result;
+ }
+
+ /**
+ * Drain all the elements from the specified queue and add them to the
+ * specified collection.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean drainTo(Queue<? extends E> queue, Collection<? super E> collection) {
+ return ( ! queue.isEmpty()) && drainTo_(queue, collection);
+ }
+
+ /**
+ * assume the queue is not empty
+ */
+ private static <E> boolean drainTo_(Queue<? extends E> queue, Collection<? super E> collection) {
+ do {
+ collection.add(queue.dequeue());
+ } while ( ! queue.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified queue
+ * to the specified list at the specified index.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean drainTo(Queue<? extends E> queue, List<? super E> list, int index) {
+ return ( ! queue.isEmpty()) && drainTo_(queue, list, index);
+ }
+
+ /**
+ * assume the queue is not empty
+ */
+ private static <E> boolean drainTo_(Queue<? extends E> queue, List<? super E> list, int index) {
+ return (index == list.size()) ? drainTo_(queue, list) : list.addAll(index, drain(queue));
+ }
+
+ /**
+ * Drain all the elements from the specified queue and push them on the
+ * specified stack.
+ * Return whether the queue changed as a result.
+ */
+ public static <E> boolean drainTo(Queue<? extends E> queue, Stack<? super E> stack) {
+ return ( ! queue.isEmpty()) && drainTo_(queue, stack);
+ }
+
+ /**
+ * assume the queue is not empty
+ */
+ private static <E> boolean drainTo_(Queue<? extends E> queue, Stack<? super E> stack) {
+ do {
+ stack.push(queue.dequeue());
+ } while ( ! queue.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the first specified queue and enqueue them
+ * on the second specified queue.
+ * Return whether the first queue changed as a result.
+ */
+ public static <E> boolean drainTo(Queue<? extends E> queue1, Queue<? super E> queue2) {
+ return ( ! queue1.isEmpty()) && drainTo_(queue1, queue2);
+ }
+
+ /**
+ * assume queue 1 is not empty
+ */
+ private static <E> boolean drainTo_(Queue<? extends E> queue1, Queue<? super E> queue2) {
+ do {
+ queue2.enqueue(queue1.dequeue());
+ } while ( ! queue1.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified queue, passing each element to the
+ * specified key transformer. Map the generated key to its element.
+ * Return whether the queue changed as a result.
+ */
+ public static <K, V, E extends V> boolean drainTo(Queue<E> queue, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ return ( ! queue.isEmpty()) && drainTo_(queue, map, keyTransformer);
+ }
+
+ /**
+ * assume the queue is not empty
+ */
+ private static <K, V, E extends V> boolean drainTo_(Queue<E> queue, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ do {
+ MapTools.add(map, queue.dequeue(), keyTransformer);
+ } while ( ! queue.isEmpty());
+ return true;
+ }
+
+ /**
+ * Drain all the elements from the specified queue, passing each element to the
+ * specified key and value transformers. Add the generated key/value pairs
+ * to the specified map.
+ * Return whether the queue changed as a result.
+ */
+ public static <K, V, E> boolean drainTo(Queue<E> queue, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ return ( ! queue.isEmpty()) && drainTo_(queue, map, keyTransformer, valueTransformer);
+ }
+
+ /**
+ * assume the queue is not empty
+ */
+ private static <K, V, E> boolean drainTo_(Queue<E> queue, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ do {
+ MapTools.add(map, queue.dequeue(), keyTransformer, valueTransformer);
+ } while ( ! queue.isEmpty());
+ return true;
+ }
+
+
+ // ********** array queue factory methods **********
+
+ /**
+ * Return an empty array-based FIFO queue.
+ */
+ public static <E> ArrayQueue<E> arrayQueue() {
+ return arrayQueue(10);
+ }
+
+ /**
+ * Return an empty array-based FIFO queue with specified initial capacity.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(int initialCapacity) {
+ return new ArrayQueue<E>(initialCapacity);
+ }
+
+ /**
+ * Return an array-based FIFO queue corresponding to the specified iterable.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(Iterable<? extends E> iterable) {
+ return arrayQueue(iterable.iterator());
+ }
+
+ /**
+ * Return an array-based FIFO queue corresponding to the specified iterable.
+ * The specified iterable size is a performance hint.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(Iterable<? extends E> iterable, int iterableSize) {
+ return arrayQueue(iterable.iterator(), iterableSize);
+ }
+
+ /**
+ * Return an array-based FIFO queue corresponding to the specified iterator.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(Iterator<? extends E> iterator) {
+ ArrayQueue<E> result = QueueTools.arrayQueue();
+ enqueueAll(result, iterator);
+ return result;
+ }
+
+ /**
+ * Return an array-based FIFO queue corresponding to the specified iterator.
+ * The specified iterator size is a performance hint.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(Iterator<? extends E> iterator, int iteratorSize) {
+ ArrayQueue<E> result = QueueTools.arrayQueue(iteratorSize);
+ enqueueAll(result, iterator);
+ return result;
+ }
+
+ /**
+ * Return an array-based FIFO queue corresponding to the specified array.
+ */
+ public static <E> ArrayQueue<E> arrayQueue(E... array) {
+ ArrayQueue<E> result = QueueTools.arrayQueue(array.length);
+ enqueueAll(result, array);
+ return result;
+ }
+
+
+ // ********** linked queue factory methods **********
+
+ /**
+ * Return an empty link-based FIFO queue with no node cache.
+ */
+ public static <E> LinkedQueue<E> linkedQueue() {
+ return linkedQueue(0);
+ }
+
+ /**
+ * Return an empty link-based FIFO queue
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(int cacheSize) {
+ return new LinkedQueue<E>(cacheSize);
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified iterable.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(Iterable<? extends E> iterable) {
+ return linkedQueue(iterable, 0);
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified iterable
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(Iterable<? extends E> iterable, int cacheSize) {
+ return linkedQueue(iterable.iterator(), cacheSize);
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified iterator.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(Iterator<? extends E> iterator) {
+ return linkedQueue(iterator, 0);
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified iterator
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(Iterator<? extends E> iterator, int cacheSize) {
+ LinkedQueue<E> result = QueueTools.linkedQueue(cacheSize);
+ enqueueAll(result, iterator);
+ return result;
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified array.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(E... array) {
+ return linkedQueue(array, 0);
+ }
+
+ /**
+ * Return a link-based FIFO queue corresponding to the specified array
+ * with the specified node cache size.
+ * Specify a cache size of -1 for an unlimited cache.
+ */
+ public static <E> LinkedQueue<E> linkedQueue(E[] array, int cacheSize) {
+ LinkedQueue<E> result = QueueTools.linkedQueue(cacheSize);
+ enqueueAll(result, array);
+ return result;
+ }
+
+
+ // ********** fixed size queue factory methods **********
+
+ /**
+ * Return a fixed-capacity array queue with the specified capacity.
+ */
+ public static <E> FixedCapacityArrayQueue<E> fixedCapacityArrayQueue(int capacity) {
+ return new FixedCapacityArrayQueue<E>(capacity);
+ }
+
+ /**
+ * Return a fized-capacity array queue containing the elements of the specified
+ * collection. The queue will dequeue its elements in the same
+ * order they are returned by the collection's iterator (i.e. the
+ * first element returned by the collection's iterator will be the
+ * first element returned by {@link Queue#dequeue()}).
+ * The queue's capacity will be match the collection's size.
+ */
+ public static <E> FixedCapacityArrayQueue<E> fixedCapacityArrayQueue(Collection<? extends E> collection) {
+ FixedCapacityArrayQueue<E> result = QueueTools.fixedCapacityArrayQueue(collection.size());
+ enqueueAll(result, collection);
+ return result;
+ }
+
+
+ // ********** stack queue factory methods **********
+
+ /**
+ * Return a LIFO queue.
+ */
+ public static <E> StackQueue<E> stackQueue() {
+ return adapt(new ArrayStack<E>());
+ }
+
+ /**
+ * Adapt the specified stack to the {@link Queue} interface,
+ * implementing a LIFO queue.
+ */
+ public static <E> StackQueue<E> adapt(Stack<E> stack) {
+ return new StackQueue<E>(stack);
+ }
+
+
+ // ********** priority queue factory methods **********
+
+ /**
+ * Return a priority queue that returns its elements in
+ * {@linkplain Comparable natural order}.
+ */
+ public static <E extends Comparable<E>> PriorityQueue<E> priorityQueue() {
+ return priorityQueue(10);
+ }
+
+ /**
+ * Return a priority queue that returns its elements in
+ * {@linkplain Comparable natural order} and has the specified initial capacity.
+ */
+ public static <E extends Comparable<E>> PriorityQueue<E> priorityQueue(int initialCapacity) {
+ return priorityQueue(ComparatorTools.<E>naturalComparator(), initialCapacity);
+ }
+
+ /**
+ * Return a priority queue whose elements are returned in
+ * the order determined by the specified comparator.
+ */
+ public static <E> PriorityQueue<E> priorityQueue(Comparator<? super E> comparator) {
+ return priorityQueue(comparator, 10);
+ }
+
+ /**
+ * Return a priority queue whose elements are returned in
+ * the order determined by the specified comparator
+ * and has the specified initial capacity.
+ */
+ public static <E> PriorityQueue<E> priorityQueue(Comparator<? super E> comparator, int initialCapacity) {
+ return new PriorityQueue<E>(comparator, initialCapacity);
+ }
+
+ /**
+ * Construct a priority queue with the specified initial full array of elements.
+ * The priority queue will return its elements in {@linkplain Comparable natural order}.
+ * The array of elements should hold elements at
+ * every index except 0. The queue will <em>not</em> copy the
+ * elements from the supplied array; i.e. the queue will directly use and manipulate
+ * the supplied array.
+ */
+ public static <E extends Comparable<E>> PriorityQueue<E> priorityQueue(E[] initialElements) {
+ return priorityQueue(initialElements, initialElements.length - 1);
+ }
+
+ /**
+ * Construct a priority queue with the specified initial array of elements and size.
+ * The priority queue will return its elements in {@linkplain Comparable natural order}.
+ * The array of elements should hold elements at contiguous indices from
+ * 1 to the the specified size, inclusive. The array should <em>not</em>
+ * hold an element at index 0. The queue will <em>not</em> copy the
+ * elements from the supplied array; i.e. the queue will directly use and manipulate
+ * the supplied array.
+ */
+ public static <E extends Comparable<E>> PriorityQueue<E> priorityQueue(E[] initialElements, int size) {
+ return priorityQueue(ComparatorTools.<E>naturalComparator(), initialElements, size);
+ }
+
+ /**
+ * Construct a priority queue with the specified comparator and
+ * initial full array of elements.
+ * The array of elements should hold elements at
+ * every index except 0. The queue will <em>not</em> copy the
+ * elements from the supplied array; i.e. the queue will directly use and manipulate
+ * the supplied array.
+ */
+ public static <E> PriorityQueue<E> priorityQueue(Comparator<? super E> comparator, E[] initialElements) {
+ return priorityQueue(comparator, initialElements, initialElements.length - 1);
+ }
+
+ /**
+ * Construct a priority queue with the specified comparator,
+ * initial array of elements, and size. The array of elements
+ * should hold elements at contiguous indices from
+ * 1 to the the specified size, inclusive. The array should <em>not</em>
+ * hold an element at index 0. The queue will <em>not</em> copy the
+ * elements from the supplied array; i.e. the queue will directly use and manipulate
+ * the supplied array.
+ */
+ public static <E> PriorityQueue<E> priorityQueue(Comparator<? super E> comparator, E[] initialElements, int size) {
+ return new PriorityQueue<E>(comparator, initialElements, size);
+ }
+
+
+ // ********** synchronized queue factory methods **********
+
+ /**
+ * Return a synchronized queue.
+ */
+ public static <E> SynchronizedQueue<E> synchronizedQueue() {
+ ArrayQueue<E> queue = arrayQueue();
+ return synchronizedQueue(queue);
+ }
+
+ /**
+ * Return a queue that synchronizes with specified mutex.
+ */
+ public static <E> SynchronizedQueue<E> synchronizedQueue(Object mutex) {
+ ArrayQueue<E> queue = arrayQueue();
+ return synchronizedQueue(queue, mutex);
+ }
+
+ /**
+ * Return a queue that synchronizes the specified queue.
+ */
+ public static <E> SynchronizedQueue<E> synchronizedQueue(Queue<E> queue) {
+ return new SynchronizedQueue<E>(queue);
+ }
+
+ /**
+ * Return a queue that synchronizes the specified queue
+ * with specified mutex.
+ */
+ public static <E> SynchronizedQueue<E> synchronizedQueue(Queue<E> queue, Object mutex) {
+ return new SynchronizedQueue<E>(queue, mutex);
+ }
+
+
+ // ********** misc queue factory methods **********
+
+ /**
+ * Adapt the specified deque to the {@link Queue} interface.
+ */
+ public static <E> DequeQueue<E> adapt(Deque<E> deque) {
+ return new DequeQueue<E>(deque);
+ }
+
+ /**
+ * Adapt the specified list to the {@link Queue} interface.
+ */
+ public static <E> ListQueue<E> adapt(List<E> list) {
+ return new ListQueue<E>(list);
+ }
+
+ /**
+ * Return an unmodifiable empty queue.
+ */
+ public static <E> Queue<E> emptyQueue() {
+ return EmptyQueue.instance();
+ }
+
+
+ // ********** constructor **********
+
+ /**
+ * Suppress default constructor, ensuring non-instantiability.
+ */
+ private QueueTools() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/StackQueue.java
index 4239a829b3..11503386fd 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/StackQueue.java
@@ -7,11 +7,11 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Adapt a {@link Stack} to create a LIFO implementation of the {@link Queue}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedQueue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/SynchronizedQueue.java
index 769deb4ffa..c5c1deea89 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedQueue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/queue/SynchronizedQueue.java
@@ -7,16 +7,20 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
* Thread-safe implementation of the {@link Queue} interface.
@@ -65,20 +69,6 @@ public class SynchronizedQueue<E>
this.mutex = this;
}
- /**
- * Construct an empty synchronized queue that locks on the specified mutex.
- */
- public SynchronizedQueue(Object mutex) {
- this(new LinkedQueue<E>(), mutex);
- }
-
- /**
- * Construct an empty synchronized queue that locks on itself.
- */
- public SynchronizedQueue() {
- this(new LinkedQueue<E>());
- }
-
// ********** Queue implementation **********
@@ -306,122 +296,189 @@ public class SynchronizedQueue<E>
/**
* "Enqueue" all the elements returned by the specified iterable.
+ * Return whether the queue changed as a result.
*/
- public void enqueueAll(Iterable<? extends E> iterable) {
- this.enqueueAll(iterable.iterator());
+ public boolean enqueueAll(Iterable<? extends E> iterable) {
+ return this.enqueueAll(iterable.iterator());
}
/**
* "Enqueue" all the elements returned by the specified iterator.
+ * Return whether the queue changed as a result.
*/
- public void enqueueAll(Iterator<? extends E> iterator) {
+ public boolean enqueueAll(Iterator<? extends E> iterator) {
+ if ( ! iterator.hasNext()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.enqueueAll_(iterator);
+ return this.enqueueAll_(iterator);
}
}
/**
* Pre-condition: synchronized
+ * Assume the iterator is not empty.
*/
- private void enqueueAll_(Iterator<? extends E> iterator) {
- while (iterator.hasNext()) {
- this.enqueue_(iterator.next());
- }
+ private boolean enqueueAll_(Iterator<? extends E> iterator) {
+ do {
+ this.queue.enqueue(iterator.next());
+ } while (iterator.hasNext());
+ this.mutex.notifyAll();
+ return true;
}
/**
* "Enqueue" all the elements in the specified array.
+ * Return whether the queue changed as a result.
*/
- public void enqueueAll(E... array) {
+ public boolean enqueueAll(E... array) {
+ int len = array.length;
+ if (len == 0) {
+ return false;
+ }
synchronized (this.mutex) {
- this.enqueueAll_(array);
+ return this.enqueueAll_(array, len);
}
}
/**
* Pre-condition: synchronized
+ * Assume the array is not empty.
*/
- private void enqueueAll_(E[] array) {
- for (E element : array) {
- this.enqueue_(element);
- }
+ private boolean enqueueAll_(E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ this.queue.enqueue(array[i++]);
+ } while (i < arrayLength);
+ this.mutex.notifyAll();
+ return true;
}
/**
* Pop all the elements from the specified stack and "enqueue" them.
+ * Return whether the queue changed as a result.
*/
- public void enqueueAll(Stack<? extends E> stack) {
+ public boolean enqueueAll(Stack<? extends E> stack) {
+ if (stack.isEmpty()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.enqueueAll_(stack);
+ return this.enqueueAll_(stack);
}
}
/**
* Pre-condition: synchronized
+ * Assume the stack is not empty.
*/
- private void enqueueAll_(Stack<? extends E> stack) {
- while ( ! stack.isEmpty()) {
- this.enqueue_(stack.pop());
- }
+ private boolean enqueueAll_(Stack<? extends E> stack) {
+ do {
+ this.queue.enqueue(stack.pop());
+ } while ( ! stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
- * "Dequeue" all the elements from the second specified queue and
+ * "Dequeue" all the elements from the specified queue and
* "enqueue" them.
+ * Return whether the queue changed as a result.
* @see #drainTo(Queue)
*/
- public void enqueueAll(Queue<? extends E> q) {
+ public boolean enqueueAll(Queue<? extends E> q) {
+ if (q.isEmpty()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.enqueueAll_(q);
+ return this.enqueueAll_(q);
}
}
/**
* Pre-condition: synchronized
+ * Assume the queue is not empty.
*/
- private void enqueueAll_(Queue<? extends E> q) {
- while ( ! q.isEmpty()) {
- this.enqueue_(q.dequeue());
- }
+ private boolean enqueueAll_(Queue<? extends E> q) {
+ do {
+ this.queue.enqueue(q.dequeue());
+ } while ( ! q.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
* "Drain" all the current items from the queue and return them in a list.
*/
- public Iterable<E> drain() {
- return this.drainTo(new ArrayList<E>());
+ public ArrayList<E> drain() {
+ ArrayList<E> result = new ArrayList<E>();
+ this.drainTo(result);
+ return result;
}
/**
* "Drain" all the current items from the queue into specified collection.
- * Return the collection.
+ * Return whether the queue changed as a result.
*/
- public <C extends Collection<? super E>> C drainTo(C c) {
+ public boolean drainTo(Collection<? super E> collection) {
synchronized (this.mutex) {
- return this.drainTo_(c);
+ return this.drainTo_(collection);
}
}
/**
* Pre-condition: synchronized
*/
- private <C extends Collection<? super E>> C drainTo_(C c) {
- boolean changed = false;
- while ( ! this.queue.isEmpty()) {
- c.add(this.queue.dequeue());
- changed = true;
+ private boolean drainTo_(Collection<? super E> collection) {
+ if (this.queue.isEmpty()) {
+ return false;
}
- if (changed) {
- this.mutex.notifyAll();
+ return this.drainTo__(collection);
+ }
+
+ /**
+ * Pre-condition: synchronized
+ * Assume the queue is not empty.
+ */
+ private boolean drainTo__(Collection<? super E> collection) {
+ do {
+ collection.add(this.queue.dequeue());
+ } while ( ! this.queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the queue into specified list
+ * at the specified index.
+ * Return whether the queue changed as a result.
+ */
+ public boolean drainTo(List<? super E> list, int index) {
+ synchronized (this.mutex) {
+ return this.drainTo_(list, index);
}
- return c;
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private boolean drainTo_(List<? super E> list, int index) {
+ if (this.queue.isEmpty()) {
+ return false;
+ }
+ if (index == list.size()) {
+ return this.drainTo__(list);
+ }
+ ArrayList<E> temp = new ArrayList<E>();
+ this.drainTo__(temp);
+ list.addAll(index, temp);
+ return true;
}
/**
* "Drain" all the current items from the queue into specified stack.
- * Return the stack.
+ * Return whether the queue changed as a result.
*/
- public <S extends Stack<? super E>> S drainTo(S stack) {
+ public boolean drainTo(Stack<? super E> stack) {
synchronized (this.mutex) {
return this.drainTo_(stack);
}
@@ -430,24 +487,23 @@ public class SynchronizedQueue<E>
/**
* Pre-condition: synchronized
*/
- private <S extends Stack<? super E>> S drainTo_(S stack) {
- boolean changed = false;
- while ( ! this.queue.isEmpty()) {
- stack.push(this.queue.dequeue());
- changed = true;
+ private boolean drainTo_(Stack<? super E> stack) {
+ if (this.queue.isEmpty()) {
+ return false;
}
- if (changed) {
- this.mutex.notifyAll();
- }
- return stack;
+ do {
+ stack.push(this.queue.dequeue());
+ } while ( ! this.queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
* "Drain" all the current items from the queue into specified queue.
- * Return the specified queue.
+ * Return whether the queue changed as a result.
* @see #enqueueAll(Queue)
*/
- public <Q extends Queue<? super E>> Q drainTo(Q q) {
+ public boolean drainTo(Queue<? super E> q) {
synchronized (this.mutex) {
return this.drainTo_(q);
}
@@ -456,16 +512,68 @@ public class SynchronizedQueue<E>
/**
* Pre-condition: synchronized
*/
- private <Q extends Queue<? super E>> Q drainTo_(Q q) {
- boolean changed = false;
- while ( ! this.queue.isEmpty()) {
+ private boolean drainTo_(Queue<? super E> q) {
+ if (this.queue.isEmpty()) {
+ return false;
+ }
+ do {
q.enqueue(this.queue.dequeue());
- changed = true;
+ } while ( ! this.queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the queue
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each item.
+ * Return whether the queue changed as a result.
+ */
+ public <K> boolean drainTo(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ synchronized (this.mutex) {
+ return this.drainTo_(map, keyTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K> boolean drainTo_(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ if (this.queue.isEmpty()) {
+ return false;
}
- if (changed) {
- this.mutex.notifyAll();
+ do {
+ MapTools.add(map, this.queue.dequeue(), keyTransformer);
+ } while ( ! this.queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Drain" all the current items from the queue
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each popped item and the specified value transformer
+ * to generator the value for each dequeued item.
+ * Return whether the queue changed as a result.
+ */
+ public <K, V> boolean drainTo(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ synchronized (this.mutex) {
+ return this.drainTo_(map, keyTransformer, valueTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K, V> boolean drainTo_(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ if (this.queue.isEmpty()) {
+ return false;
}
- return q;
+ do {
+ MapTools.add(map, this.queue.dequeue(), keyTransformer, valueTransformer);
+ } while ( ! this.queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ArrayStack.java
index 20fdf3102b..ed5fe75d7b 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ArrayStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ArrayStack.java
@@ -7,17 +7,18 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.Arrays;
import java.util.EmptyStackException;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Resizable-array LIFO implementation of the {@link Stack} interface.
* @param <E> the type of elements maintained by the stack
- * @see FixedSizeArrayStack
+ * @see FixedCapacityArrayStack
* @see StackTools
*/
public class ArrayStack<E>
@@ -25,9 +26,6 @@ public class ArrayStack<E>
{
private transient E[] elements;
- /** The index of where the next "pushed" element will go. */
- private transient int next = 0;
-
private int size = 0;
private static final long serialVersionUID = 1L;
@@ -59,11 +57,7 @@ public class ArrayStack<E>
public void push(E element) {
this.ensureCapacity(this.size + 1);
- this.elements[this.next] = element;
- if (++this.next == this.elements.length) {
- this.next = 0;
- }
- this.size++;
+ this.elements[this.size++] = element;
}
/**
@@ -71,14 +65,12 @@ public class ArrayStack<E>
* the specified minimum capacity.
*/
public void ensureCapacity(int minCapacity) {
- int oldCapacity = this.elements.length;
- if (oldCapacity < minCapacity) {
- int newCapacity = ((oldCapacity * 3) >> 1) + 1;
+ if (this.elements.length < minCapacity) {
+ int newCapacity = ((this.elements.length * 3) >> 1) + 1;
if (newCapacity < minCapacity) {
newCapacity = minCapacity;
}
this.elements = this.copyElements(newCapacity);
- this.next = this.size;
}
}
@@ -88,16 +80,14 @@ public class ArrayStack<E>
public void trimToSize() {
if (this.elements.length > this.size) {
this.elements = this.copyElements(this.size);
- this.next = this.size;
}
}
private E[] copyElements(int newCapacity) {
@SuppressWarnings("unchecked")
E[] newElements = (E[]) new Object[newCapacity];
- int len = this.size;
- if (len != 0) {
- System.arraycopy(this.elements, 0, newElements, 0, len);
+ if (this.size != 0) {
+ System.arraycopy(this.elements, 0, newElements, 0, this.size);
}
return newElements;
}
@@ -106,14 +96,9 @@ public class ArrayStack<E>
if (this.size == 0) {
throw new EmptyStackException();
}
- int index = this.next;
- if (index == 0) {
- index = this.elements.length;
- }
- index--;
+ int index = this.size - 1;
E element = this.elements[index];
this.elements[index] = null; // allow GC to work
- this.next = index;
this.size--;
return element;
}
@@ -122,12 +107,7 @@ public class ArrayStack<E>
if (this.size == 0) {
throw new EmptyStackException();
}
- int index = this.next;
- if (index == 0) {
- index = this.elements.length;
- }
- index--;
- return this.elements[index];
+ return this.elements[this.size - 1];
}
public boolean isEmpty() {
@@ -151,14 +131,9 @@ public class ArrayStack<E>
}
}
- /**
- * Print the elements in the order in which they are "pushed" on to
- * the stack (as opposed to the order in which they will be "popped"
- * off of the stack).
- */
@Override
public String toString() {
- return Arrays.toString(this.copyElements(this.size));
+ return Arrays.toString(ArrayTools.reverse(this.copyElements(this.size)));
}
@@ -170,21 +145,8 @@ public class ArrayStack<E>
Object[] array = this.elements;
int elementsLength = array.length;
stream.writeInt(elementsLength);
- if (this.size == 0) {
- return;
- }
- // save the elements in contiguous order
- if (this.next >= this.size) { // elements are contiguous
- for (int i = (this.next - this.size); i < this.next; i++) {
- stream.writeObject(array[i]);
- }
- } else { // (this.next < this.size) - elements wrap past end of array
- for (int i = (elementsLength - (this.size - this.next)); i < elementsLength; i++) {
- stream.writeObject(array[i]);
- }
- for (int i = 0; i < this.next; i++) {
- stream.writeObject(array[i]);
- }
+ for (int i = 0; i < this.size; i++) {
+ stream.writeObject(array[i]);
}
}
@@ -198,6 +160,5 @@ public class ArrayStack<E>
array[i] = stream.readObject();
}
this.elements = (E[]) array;
- this.next = this.size;
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/DequeStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/DequeStack.java
new file mode 100644
index 0000000000..20aaab9841
--- /dev/null
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/DequeStack.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.internal.stack;
+
+import java.io.Serializable;
+import java.util.EmptyStackException;
+import java.util.NoSuchElementException;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.stack.Stack;
+
+/**
+ * Adapt a {@link Deque} to the {@link Stack} interface.
+ * Elements are pushed to and popped from the head of the deque.
+ * @param <E> the type of elements maintained by the stack
+ * @see StackTools
+ */
+public class DequeStack<E>
+ implements Stack<E>, Serializable
+{
+ private Deque<E> deque;
+
+ private static final long serialVersionUID = 1L;
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a stack, adapting the specified deque.
+ * Elements are pushed to and popped from the head of the deque.
+ */
+ public DequeStack(Deque<E> deque) {
+ super();
+ this.deque = deque;
+ }
+
+
+ // ********** Stack implementation **********
+
+ public void push(E element) {
+ this.deque.enqueueHead(element);
+ }
+
+ public E pop() {
+ try {
+ return this.deque.dequeueHead();
+ } catch (NoSuchElementException ex) {
+ throw new EmptyStackException();
+ }
+ }
+
+ public E peek() {
+ try {
+ return this.deque.peekHead();
+ } catch (NoSuchElementException ex) {
+ throw new EmptyStackException();
+ }
+ }
+
+ public boolean isEmpty() {
+ return this.deque.isEmpty();
+ }
+
+
+ // ********** standard methods **********
+
+ @Override
+ public String toString() {
+ return this.deque.toString();
+ }
+}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/EmptyStack.java
index e1ed4b3027..cf18881346 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/EmptyStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/EmptyStack.java
@@ -7,11 +7,11 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.EmptyStackException;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Empty implementation of the {@link Stack} interface.
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/FixedCapacityArrayStack.java
index 3eec5f9028..44b55aba7f 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/FixedSizeArrayStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/FixedCapacityArrayStack.java
@@ -7,22 +7,23 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.Arrays;
import java.util.EmptyStackException;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
- * Fixed-size array LIFO implementation of the {@link Stack} interface.
+ * Fixed-capacity array LIFO implementation of the {@link Stack} interface.
* This implementation will throw an exception if its capacity is exceeded.
* @param <E> the type of elements maintained by the stack
* @see ArrayStack
* @see StackTools
*/
-public class FixedSizeArrayStack<E>
+public class FixedCapacityArrayStack<E>
implements Stack<E>, Cloneable, Serializable
{
private E[] elements;
@@ -41,7 +42,7 @@ public class FixedSizeArrayStack<E>
* Construct an empty stack with the specified capacity.
*/
@SuppressWarnings("unchecked")
- public FixedSizeArrayStack(int capacity) {
+ public FixedCapacityArrayStack(int capacity) {
super();
if (capacity < 0) {
throw new IllegalArgumentException("Illegal capacity: " + capacity); //$NON-NLS-1$
@@ -107,9 +108,9 @@ public class FixedSizeArrayStack<E>
// ********** standard methods **********
@Override
- public FixedSizeArrayStack<E> clone() {
+ public FixedCapacityArrayStack<E> clone() {
int len = this.elements.length;
- FixedSizeArrayStack<E> clone = new FixedSizeArrayStack<E>(len);
+ FixedCapacityArrayStack<E> clone = new FixedCapacityArrayStack<E>(len);
System.arraycopy(this.elements, 0, clone.elements, 0, len);
clone.next = this.next;
clone.size = this.size;
@@ -123,26 +124,16 @@ public class FixedSizeArrayStack<E>
*/
@Override
public String toString() {
- return Arrays.toString(this.copyElements());
+ return Arrays.toString(ArrayTools.reverse(this.copyElements()));
}
private Object[] copyElements() {
- if (this.size == 0) {
+ int len = this.size;
+ if (len == 0) {
return ObjectTools.EMPTY_OBJECT_ARRAY;
}
- Object[] result = new Object[this.size];
- if (this.next >= this.size) {
- // elements are contiguous, but not to end of array
- System.arraycopy(this.elements, (this.next - this.size), result, 0, this.size);
- } else if (this.next == 0) {
- // elements are contiguous to end of array
- System.arraycopy(this.elements, (this.elements.length - this.size), result, 0, this.size);
- } else {
- // elements wrap past end of array
- int fragmentSize = this.size - this.next;
- System.arraycopy(this.elements, (this.elements.length - fragmentSize), result, 0, fragmentSize);
- System.arraycopy(this.elements, 0, result, fragmentSize, (this.size - fragmentSize));
- }
+ Object[] result = new Object[len];
+ System.arraycopy(this.elements, 0, result, 0, len);
return result;
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/LinkedStack.java
index 97456c6753..87aba7e2ae 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/LinkedStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/LinkedStack.java
@@ -7,13 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.Arrays;
import java.util.EmptyStackException;
-import org.eclipse.jpt.common.utility.collection.Stack;
import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Linked LIFO implementation of the {@link Stack} interface.
@@ -212,6 +212,11 @@ public class LinkedStack<E>
return this;
}
+ @Override
+ public String toString() {
+ return ObjectTools.singletonToString(this);
+ }
+
private static final long serialVersionUID = 1L;
private Object readResolve() {
// replace this object with the singleton
@@ -260,5 +265,10 @@ public class LinkedStack<E>
NodeFactory<E> copy() {
return new CachingNodeFactory<E>(this.maxCacheSize);
}
+
+ @Override
+ public String toString() {
+ return ObjectTools.toString(this, this.cacheSize);
+ }
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ListStack.java
index b9a08fd845..fd9c0c30af 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/ListStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/ListStack.java
@@ -7,12 +7,13 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.EmptyStackException;
import java.util.List;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import org.eclipse.jpt.common.utility.internal.collection.ListTools;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Adapt a {@link List} to the {@link Stack} interface.
@@ -54,7 +55,7 @@ public class ListStack<E>
if (size == 0) {
throw new EmptyStackException();
}
- return this.list.remove(size - 1);
+ return this.list.remove(--size);
}
public E peek() {
@@ -62,7 +63,7 @@ public class ListStack<E>
if (size == 0) {
throw new EmptyStackException();
}
- return this.list.get(size - 1);
+ return this.list.get(--size);
}
public boolean isEmpty() {
@@ -74,6 +75,6 @@ public class ListStack<E>
@Override
public String toString() {
- return this.list.toString();
+ return ListTools.reverse(this.list).toString();
}
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/StackTools.java
index 57eb050ba0..40ddeb4df1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/StackTools.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/StackTools.java
@@ -7,14 +7,18 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import java.util.Map;
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
* {@link Stack} utility methods.
@@ -26,59 +30,50 @@ public class StackTools {
/**
* Push all the elements returned by the specified iterable
* on the specified stack.
- * Return the stack.
+ * Return whether the stack changed as a result.
*/
- public static <S extends Stack<? super E>, E> S pushAll(S stack, Iterable<? extends E> iterable) {
+ public static <E> boolean pushAll(Stack<? super E> stack, Iterable<? extends E> iterable) {
return pushAll(stack, iterable.iterator());
}
/**
* Push all the elements returned by the specified iterator
* on the specified stack.
- * Return the stack.
+ * Return whether the stack changed as a result.
*/
- public static <S extends Stack<? super E>, E> S pushAll(S stack, Iterator<? extends E> iterator) {
- while (iterator.hasNext()) {
- stack.push(iterator.next());
- }
- return stack;
+ public static <E> boolean pushAll(Stack<? super E> stack, Iterator<? extends E> iterator) {
+ return iterator.hasNext() && pushAll_(stack, iterator);
}
/**
- * Push all the elements in the specified array
- * on the specified stack.
- * Return the stack.
+ * assume the iterator is not empty
*/
- public static <S extends Stack<? super E>, E> S pushAll(S stack, E... array) {
- for (E element : array) {
- stack.push(element);
- }
- return stack;
+ private static <E> boolean pushAll_(Stack<? super E> stack, Iterator<? extends E> iterator) {
+ do {
+ stack.push(iterator.next());
+ } while (iterator.hasNext());
+ return true;
}
/**
- * Dequeue all the elements from the specified queue and push them
+ * Push all the elements in the specified array
* on the specified stack.
- * Return the stack.
+ * Return whether the stack changed as a result.
*/
- public static <S extends Stack<? super E>, E> S pushAll(S stack, Queue<? extends E> queue) {
- while ( ! queue.isEmpty()) {
- stack.push(queue.dequeue());
- }
- return stack;
+ public static <E> boolean pushAll(Stack<? super E> stack, E... array) {
+ int len = array.length;
+ return (len != 0) && pushAll_(stack, array, len);
}
/**
- * Pop all the elements from the second specified stack and push them
- * on the first specified stack.
- * Return the first stack.
- * @see #popAllTo(Stack, Stack)
+ * assume the array is not empty
*/
- public static <S extends Stack<? super E>, E> S pushAll(S stack1, Stack<? extends E> stack2) {
- while ( ! stack2.isEmpty()) {
- stack1.push(stack2.pop());
- }
- return stack1;
+ private static <E> boolean pushAll_(Stack<? super E> stack, E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ stack.push(array[i++]);
+ } while (i < arrayLength);
+ return true;
}
@@ -89,100 +84,127 @@ public class StackTools {
* list.
*/
public static <E> ArrayList<E> popAll(Stack<? extends E> stack) {
- return popAllTo(stack, new ArrayList<E>());
+ ArrayList<E> result = new ArrayList<E>();
+ popAllTo(stack, result);
+ return result;
}
/**
* Pop all the elements from the specified stack and add them to the
* specified collection.
- * Return the collection.
+ * Return whether the stack changed as a result.
*/
- public static <C extends Collection<? super E>, E> C popAllTo(Stack<? extends E> stack, C collection) {
- while ( ! stack.isEmpty()) {
- collection.add(stack.pop());
- }
- return collection;
+ public static <E> boolean popAllTo(Stack<? extends E> stack, Collection<? super E> collection) {
+ return ( ! stack.isEmpty()) && popAllTo_(stack, collection);
}
/**
- * Pop all the elements from the specified stack and enqueue them on the
- * specified queue.
- * Return the queue.
+ * assume the stack is not empty
*/
- public static <Q extends Queue<? super E>, E> Q popAllTo(Stack<? extends E> stack, Q queue) {
- while ( ! stack.isEmpty()) {
- queue.enqueue(stack.pop());
- }
- return queue;
+ private static <E> boolean popAllTo_(Stack<? extends E> stack, Collection<? super E> collection) {
+ do {
+ collection.add(stack.pop());
+ } while ( ! stack.isEmpty());
+ return true;
}
/**
- * Pop all the elements from the first specified stack and push them
- * on the second specified stack.
- * Return the second stack.
- * @see #pushAll(Stack, Stack)
+ * Pop all the elements from the specified stack
+ * to the specified list at the specified index.
+ * Return whether the stack changed as a result.
*/
- public static <S extends Stack<? super E>, E> S popAllTo(Stack<? extends E> stack1, S stack2) {
- while ( ! stack1.isEmpty()) {
- stack2.push(stack1.pop());
- }
- return stack2;
+ public static <E> boolean popAllTo(Stack<? extends E> stack, List<? super E> list, int index) {
+ return ( ! stack.isEmpty()) && popAllTo_(stack, list, index);
}
+ /**
+ * assume the stack is not empty
+ */
+ private static <E> boolean popAllTo_(Stack<? extends E> stack, List<? super E> list, int index) {
+ return (index == list.size()) ? popAllTo_(stack, list) : list.addAll(index, popAll(stack));
+ }
- // ********** factory methods **********
+ /**
+ * Pop all the elements from the specified stack and enqueue them on the
+ * specified queue.
+ * Return whether the stack changed as a result.
+ */
+ public static <E> boolean popAllTo(Stack<? extends E> stack, Queue<? super E> queue) {
+ return ( ! stack.isEmpty()) && popAllTo_(stack, queue);
+ }
/**
- * Return an empty LIFO stack.
+ * assume the stack is not empty
*/
- public static <E> ArrayStack<E> stack() {
- return arrayStack();
+ private static <E> boolean popAllTo_(Stack<? extends E> stack, Queue<? super E> queue) {
+ do {
+ queue.enqueue(stack.pop());
+ } while ( ! stack.isEmpty());
+ return true;
}
/**
- * Return an empty LIFO stack with the specified initial capacity.
+ * Pop all the elements from the first specified stack and push them
+ * on the second specified stack.
+ * Return whether the first stack changed as a result.
*/
- public static <E> ArrayStack<E> stack(int initialCapacity) {
- return arrayStack(initialCapacity);
+ public static <E> boolean popAllTo(Stack<? extends E> stack1, Stack<? super E> stack2) {
+ return ( ! stack1.isEmpty()) && popAllTo_(stack1, stack2);
}
/**
- * Return a LIFO stack corresponding to the specified iterable.
+ * assume stack 1 is not empty
*/
- public static <E> ArrayStack<E> stack(Iterable<? extends E> iterable) {
- return arrayStack(iterable);
+ private static <E> boolean popAllTo_(Stack<? extends E> stack1, Stack<? super E> stack2) {
+ do {
+ stack2.push(stack1.pop());
+ } while ( ! stack1.isEmpty());
+ return true;
}
/**
- * Return a LIFO stack corresponding to the specified iterable.
- * The specified iterable size is a performance hint.
+ * Pop all the elements from the specified stack, passing each element to the
+ * specified key transformer. Map the generated key to its element.
+ * Return whether the stack changed as a result.
*/
- public static <E> ArrayStack<E> stack(Iterable<? extends E> iterable, int iterableSize) {
- return arrayStack(iterable, iterableSize);
+// public static <K, V, E extends V> boolean popAllTo(Stack<E> stack, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ public static <K, V> boolean popAllTo(Stack<? extends V> stack, Map<K, V> map, Transformer<? super V, ? extends K> keyTransformer) {
+ return ( ! stack.isEmpty()) && popAllTo_(stack, map, keyTransformer);
}
/**
- * Return a LIFO stack corresponding to the specified iterator.
+ * assume the stack is not empty
*/
- public static <E> ArrayStack<E> stack(Iterator<? extends E> iterator) {
- return arrayStack(iterator);
+ private static <K, V, E extends V> boolean popAllTo_(Stack<E> stack, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer) {
+ do {
+ MapTools.add(map, stack.pop(), keyTransformer);
+ } while ( ! stack.isEmpty());
+ return true;
}
/**
- * Return a LIFO stack corresponding to the specified iterator.
- * The specified iterator size is a performance hint.
+ * Pop all the elements from the specified stack, passing each element to the
+ * specified key and value transformers. Add the generated key/value pairs
+ * to the specified map.
+ * Return whether the stack changed as a result.
*/
- public static <E> ArrayStack<E> stack(Iterator<? extends E> iterator, int iteratorSize) {
- return arrayStack(iterator, iteratorSize);
+ public static <K, V, E> boolean popAllTo(Stack<E> stack, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ return ( ! stack.isEmpty()) && popAllTo_(stack, map, keyTransformer, valueTransformer);
}
/**
- * Return a LIFO stack corresponding to the specified array.
+ * assume the stack is not empty
*/
- public static <E> ArrayStack<E> stack(E... array) {
- return arrayStack(array);
+ private static <K, V, E> boolean popAllTo_(Stack<E> stack, Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ do {
+ MapTools.add(map, stack.pop(), keyTransformer, valueTransformer);
+ } while ( ! stack.isEmpty());
+ return true;
}
+
+ // ********** array stack factory methods **********
+
/**
* Return an array-based LIFO stack corresponding.
*/
@@ -228,7 +250,9 @@ public class StackTools {
* first element returned by {@link Stack#pop()}; the first, last.).
*/
public static <E> ArrayStack<E> arrayStack(Iterator<? extends E> iterator) {
- return pushAll(StackTools.<E>arrayStack(), iterator);
+ ArrayStack<E> result = StackTools.arrayStack();
+ pushAll(result, iterator);
+ return result;
}
/**
@@ -240,16 +264,23 @@ public class StackTools {
* The specified iterator size is a performance hint.
*/
public static <E> ArrayStack<E> arrayStack(Iterator<? extends E> iterator, int iteratorSize) {
- return pushAll(StackTools.<E>arrayStack(iteratorSize), iterator);
+ ArrayStack<E> result = StackTools.arrayStack(iteratorSize);
+ pushAll(result, iterator);
+ return result;
}
/**
* Return an array-based LIFO stack corresponding to the specified array.
*/
public static <E> ArrayStack<E> arrayStack(E... array) {
- return pushAll(StackTools.<E>arrayStack(array.length), array);
+ ArrayStack<E> result = StackTools.arrayStack(array.length);
+ pushAll(result, array);
+ return result;
}
+
+ // ********** linked stack factory methods **********
+
/**
* Return an empty link-based LIFO stack with no node cache.
*/
@@ -286,7 +317,9 @@ public class StackTools {
* Return a link-based LIFO stack corresponding to the specified iterator.
*/
public static <E> LinkedStack<E> linkedStack(Iterator<? extends E> iterator) {
- return pushAll(StackTools.<E>linkedStack(), iterator);
+ LinkedStack<E> result = StackTools.linkedStack();
+ pushAll(result, iterator);
+ return result;
}
/**
@@ -295,14 +328,18 @@ public class StackTools {
* Specify a cache size of -1 for an unlimited cache.
*/
public static <E> LinkedStack<E> linkedStack(Iterator<? extends E> iterator, int cacheSize) {
- return pushAll(StackTools.<E>linkedStack(cacheSize), iterator);
+ LinkedStack<E> result = StackTools.linkedStack(cacheSize);
+ pushAll(result, iterator);
+ return result;
}
/**
* Return a link-based LIFO stack corresponding to the specified array.
*/
public static <E> LinkedStack<E> linkedStack(E... array) {
- return pushAll(StackTools.<E>linkedStack(), array);
+ LinkedStack<E> result = StackTools.linkedStack();
+ pushAll(result, array);
+ return result;
}
/**
@@ -311,32 +348,58 @@ public class StackTools {
* Specify a cache size of -1 for an unlimited cache.
*/
public static <E> LinkedStack<E> linkedStack(E[] array, int cacheSize) {
- return pushAll(StackTools.<E>linkedStack(cacheSize), array);
+ LinkedStack<E> result = StackTools.linkedStack(cacheSize);
+ pushAll(result, array);
+ return result;
}
+
+ // ********** fixed capacity stack factory methods **********
+
/**
- * Return a fixed-size stack with the specified capacity.
+ * Return a fixed-capacity stack with the specified capacity.
*/
- public static <E> FixedSizeArrayStack<E> fixedSizeStack(int capacity) {
- return new FixedSizeArrayStack<E>(capacity);
+ public static <E> FixedCapacityArrayStack<E> fixedCapacityArrayStack(int capacity) {
+ return new FixedCapacityArrayStack<E>(capacity);
}
/**
- * Return a fized-size stack containing the elements of the specified
+ * Return a fized-capacity stack containing the elements of the specified
* collection. The stack will pop its elements in reverse of the
* order they are returned by the collection's iterator (i.e. the
* last element returned by the collection's iterator will be the
* first element returned by {@link Stack#pop()}; the first, last.).
*/
- public static <E> FixedSizeArrayStack<E> fixedSizeStack(Collection<? extends E> collection) {
- return pushAll(StackTools.<E>fixedSizeStack(collection.size()), collection);
+ public static <E> FixedCapacityArrayStack<E> fixedCapacityArrayStack(Collection<? extends E> collection) {
+ FixedCapacityArrayStack<E> result = StackTools.fixedCapacityArrayStack(collection.size());
+ pushAll(result, collection);
+ return result;
}
+
+ // ********** synchronized stack factory methods **********
+
/**
- * Adapt the specified list to the {@link Stack} interface.
+ * Return a synchronized stack.
*/
- public static <E> ListStack<E> wrap(List<E> list) {
- return new ListStack<E>(list);
+ public static <E> SynchronizedStack<E> synchronizedStack() {
+ ArrayStack<E> stack = arrayStack();
+ return synchronizedStack(stack);
+ }
+
+ /**
+ * Return a stack that synchronizes with specified mutex.
+ */
+ public static <E> SynchronizedStack<E> synchronizedStack(Object mutex) {
+ LinkedStack<E> stack = linkedStack();
+ return synchronizedStack(stack, mutex);
+ }
+
+ /**
+ * Return a stack that synchronizes the specified stack.
+ */
+ public static <E> SynchronizedStack<E> synchronizedStack(Stack<E> stack) {
+ return new SynchronizedStack<E>(stack);
}
/**
@@ -347,18 +410,28 @@ public class StackTools {
return new SynchronizedStack<E>(stack, mutex);
}
+
+ // ********** misc stack factory methods **********
+
/**
- * Return a stack that synchronizes the specified stack.
+ * Adapt the specified list to the {@link Stack} interface.
*/
- public static <E> SynchronizedStack<E> synchronizedStack(Stack<E> stack) {
- return new SynchronizedStack<E>(stack);
+ public static <E> ListStack<E> adapt(List<E> list) {
+ return new ListStack<E>(list);
+ }
+
+ /**
+ * Adapt the specified deque to the {@link Stack} interface.
+ */
+ public static <E> DequeStack<E> adapt(Deque<E> deque) {
+ return new DequeStack<E>(deque);
}
/**
* Return an unmodifiable empty LIFO stack.
*/
public static <E> Stack<E> emptyStack() {
- return EmptyStack.<E>instance();
+ return EmptyStack.instance();
}
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedStack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/SynchronizedStack.java
index 4f4381512c..b8baf0e2f4 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/SynchronizedStack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/stack/SynchronizedStack.java
@@ -7,16 +7,20 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.internal.collection;
+package org.eclipse.jpt.common.utility.internal.stack;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EmptyStackException;
import java.util.Iterator;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.collection.Stack;
+import java.util.List;
+import java.util.Map;
import org.eclipse.jpt.common.utility.command.Command;
+import org.eclipse.jpt.common.utility.internal.collection.MapTools;
+import org.eclipse.jpt.common.utility.queue.Queue;
+import org.eclipse.jpt.common.utility.stack.Stack;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
/**
* Thread-safe implementation of the {@link Stack} interface.
@@ -65,20 +69,6 @@ public class SynchronizedStack<E>
this.mutex = this;
}
- /**
- * Construct an empty synchronized stack that locks on the specified mutex.
- */
- public SynchronizedStack(Object mutex) {
- this(new LinkedStack<E>(), mutex);
- }
-
- /**
- * Construct an empty synchronized stack that locks on itself.
- */
- public SynchronizedStack() {
- this(new LinkedStack<E>());
- }
-
// ********** Stack implementation **********
@@ -302,152 +292,220 @@ public class SynchronizedStack<E>
}
- // ********** additional public protocol **********
+ // ********** additional (synchronized) public protocol **********
/**
* "Push" all the elements returned by the specified iterable.
+ * Return whether the stack changed as a result.
*/
- public void pushAll(Iterable<? extends E> iterable) {
- this.pushAll(iterable.iterator());
+ public boolean pushAll(Iterable<? extends E> iterable) {
+ return this.pushAll(iterable.iterator());
}
/**
* "Push" all the elements returned by the specified iterator.
+ * Return whether the stack changed as a result.
*/
- public void pushAll(Iterator<? extends E> iterator) {
+ public boolean pushAll(Iterator<? extends E> iterator) {
+ if ( ! iterator.hasNext()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.pushAll_(iterator);
+ return this.pushAll_(iterator);
}
}
/**
* Pre-condition: synchronized
+ * Assume the iterator is not empty.
*/
- private void pushAll_(Iterator<? extends E> iterator) {
- while (iterator.hasNext()) {
- this.push_(iterator.next());
- }
+ private boolean pushAll_(Iterator<? extends E> iterator) {
+ do {
+ this.stack.push(iterator.next());
+ } while (iterator.hasNext());
+ this.mutex.notifyAll();
+ return true;
}
/**
* "Push" all the elements in the specified array.
+ * Return whether the stack changed as a result.
*/
- public void pushAll(E... array) {
+ public boolean pushAll(E... array) {
+ int len = array.length;
+ if (len == 0) {
+ return false;
+ }
synchronized (this.mutex) {
- this.pushAll_(array);
+ return this.pushAll_(array, len);
}
}
/**
* Pre-condition: synchronized
+ * Assume the array is not empty.
*/
- private void pushAll_(E[] array) {
- for (E element : array) {
- this.push_(element);
- }
+ private boolean pushAll_(E[] array, int arrayLength) {
+ int i = 0;
+ do {
+ this.stack.push(array[i++]);
+ } while (i < arrayLength);
+ this.mutex.notifyAll();
+ return true;
}
/**
- * Pop all the elements from the specified stack and "push" them.
+ * "Pop" all the elements from the specified stack and "push" them.
+ * Return whether the stack changed as a result.
*/
- public void pushAll(Stack<? extends E> s) {
+ public boolean pushAll(Stack<? extends E> s) {
+ if (s.isEmpty()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.pushAll_(s);
+ return this.pushAll_(s);
}
}
/**
* Pre-condition: synchronized
+ * Assume the stack is not empty.
*/
- private void pushAll_(Stack<? extends E> s) {
- while ( ! s.isEmpty()) {
- this.push_(s.pop());
- }
+ private boolean pushAll_(Stack<? extends E> s) {
+ do {
+ this.stack.push(s.pop());
+ } while ( ! s.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
- * "Dequeue" all the elements from the second specified queue and
+ * "Dequeue" all the elements from the specified queue and
* "push" them.
+ * Return whether the stack changed as a result.
* @see #popAllTo(Queue)
*/
- public void pushAll(Queue<? extends E> queue) {
+ public boolean pushAll(Queue<? extends E> queue) {
+ if (queue.isEmpty()) {
+ return false;
+ }
synchronized (this.mutex) {
- this.pushAll_(queue);
+ return this.pushAll_(queue);
}
}
/**
* Pre-condition: synchronized
+ * Assume the queue is not empty.
+ */
+ private boolean pushAll_(Queue<? extends E> queue) {
+ do {
+ this.stack.push(queue.dequeue());
+ } while ( ! queue.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Pop" all the current items from the stack and return them in a list.
+ */
+ public ArrayList<E> popAll() {
+ ArrayList<E> result = new ArrayList<E>();
+ this.popAllTo(result);
+ return result;
+ }
+
+ /**
+ * "Pop" all the current items from the stack into specified collection.
+ * Return whether the stack changed as a result.
*/
- private void pushAll_(Queue<? extends E> queue) {
- while ( ! queue.isEmpty()) {
- this.push_(queue.dequeue());
+ public boolean popAllTo(Collection<? super E> collection) {
+ synchronized (this.mutex) {
+ return this.popAllTo_(collection);
}
}
/**
- * Pop all the current items from the stack and return them in a list.
+ * Pre-condition: synchronized
*/
- public Iterable<E> popAll() {
- return this.popAllTo(new ArrayList<E>());
+ private boolean popAllTo_(Collection<? super E> collection) {
+ if (this.stack.isEmpty()) {
+ return false;
+ }
+ return this.popAllTo__(collection);
}
/**
- * Pop all the current items from the stack into specified collection.
- * Return the collection.
+ * Pre-condition: synchronized
+ * Assume the stack is not empty.
*/
- public <C extends Collection<? super E>> C popAllTo(C c) {
+ private boolean popAllTo__(Collection<? super E> collection) {
+ do {
+ collection.add(this.stack.pop());
+ } while ( ! this.stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Pop" all the current items from the stack into specified list
+ * at the specified index.
+ * Return whether the stack changed as a result.
+ */
+ public boolean popAllTo(List<? super E> list, int index) {
synchronized (this.mutex) {
- return this.popAllTo_(c);
+ return this.popAllTo_(list, index);
}
}
/**
* Pre-condition: synchronized
*/
- private <C extends Collection<? super E>> C popAllTo_(C c) {
- boolean changed = false;
- while ( ! this.stack.isEmpty()) {
- c.add(this.stack.pop());
- changed = true;
+ private boolean popAllTo_(List<? super E> list, int index) {
+ if (this.stack.isEmpty()) {
+ return false;
}
- if (changed) {
- this.mutex.notifyAll();
+ if (index == list.size()) {
+ return this.popAllTo__(list);
}
- return c;
+ ArrayList<E> temp = new ArrayList<E>();
+ this.popAllTo__(temp);
+ list.addAll(index, temp);
+ return true;
}
/**
- * Pop all the current items from the stack into specified stack.
- * Return the stack.
+ * "Pop" all the current items from the stack
+ * and "push" them onto the specified stack.
+ * Return whether the stack changed as a result.
*/
- public <S extends Stack<? super E>> S popAllTo(S s) {
+ public boolean popAllTo(Stack<? super E> stack2) {
synchronized (this.mutex) {
- return this.popAllTo_(s);
+ return this.popAllTo_(stack2);
}
}
/**
* Pre-condition: synchronized
*/
- private <S extends Stack<? super E>> S popAllTo_(S s) {
- boolean changed = false;
- while ( ! this.stack.isEmpty()) {
- s.push(this.stack.pop());
- changed = true;
+ public boolean popAllTo_(Stack<? super E> stack2) {
+ if (this.stack.isEmpty()) {
+ return false;
}
- if (changed) {
- this.mutex.notifyAll();
- }
- return s;
+ do {
+ stack2.push(this.stack.pop());
+ } while ( ! this.stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
- * Pop all the current items from the stack into specified queue.
- * Return the specified queue.
+ * "Pop" all the current items from the stack
+ * and "enqueue" them on the specified queue.
+ * Return whether the stack changed as a result.
* @see #pushAll(Queue)
*/
- public <Q extends Queue<? super E>> Q popAllTo(Q queue) {
+ public boolean popAllTo(Queue<? super E> queue) {
synchronized (this.mutex) {
return this.popAllTo_(queue);
}
@@ -456,16 +514,68 @@ public class SynchronizedStack<E>
/**
* Pre-condition: synchronized
*/
- private <Q extends Queue<? super E>> Q popAllTo_(Q queue) {
- boolean changed = false;
- while ( ! this.stack.isEmpty()) {
+ public boolean popAllTo_(Queue<? super E> queue) {
+ if (this.stack.isEmpty()) {
+ return false;
+ }
+ do {
queue.enqueue(this.stack.pop());
- changed = true;
+ } while ( ! this.stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Pop" all the current items from the stack
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each item.
+ * Return whether the stack changed as a result.
+ */
+ public <K> boolean popAllTo(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ synchronized (this.mutex) {
+ return this.popAllTo_(map, keyTransformer);
+ }
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K> boolean popAllTo_(Map<K, ? super E> map, Transformer<? super E, ? extends K> keyTransformer) {
+ if (this.stack.isEmpty()) {
+ return false;
+ }
+ do {
+ MapTools.add(map, this.stack.pop(), keyTransformer);
+ } while ( ! this.stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
+ }
+
+ /**
+ * "Pop" all the current items from the stack
+ * and add them on the specified map, using the specified key transformer
+ * to generate the key for each popped item and the specified value transformer
+ * to generator the value for each popped item.
+ * Return whether the stack changed as a result.
+ */
+ public <K, V> boolean popAllTo(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ synchronized (this.mutex) {
+ return this.popAllTo_(map, keyTransformer, valueTransformer);
}
- if (changed) {
- this.mutex.notifyAll();
+ }
+
+ /**
+ * Pre-condition: synchronized
+ */
+ private <K, V> boolean popAllTo_(Map<K, V> map, Transformer<? super E, ? extends K> keyTransformer, Transformer<? super E, ? extends V> valueTransformer) {
+ if (this.stack.isEmpty()) {
+ return false;
}
- return queue;
+ do {
+ MapTools.add(map, this.stack.pop(), keyTransformer, valueTransformer);
+ } while ( ! this.stack.isEmpty());
+ this.mutex.notifyAll();
+ return true;
}
/**
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Queue.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/queue/Queue.java
index 53299251fe..2b04a58fa1 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Queue.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/queue/Queue.java
@@ -7,7 +7,10 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.collection;
+package org.eclipse.jpt.common.utility.queue;
+
+import org.eclipse.jpt.common.utility.deque.Deque;
+import org.eclipse.jpt.common.utility.stack.Stack;
/**
* Interface defining the classic queue behavior,
@@ -20,9 +23,10 @@ package org.eclipse.jpt.common.utility.collection;
* will almost certainly be broken (repeatedly) as the API evolves.
*
* @param <E> the type of elements contained by the queue
- * @see org.eclipse.jpt.common.utility.internal.collection.ArrayQueue
- * @see org.eclipse.jpt.common.utility.internal.collection.LinkedQueue
- * @see org.eclipse.jpt.common.utility.internal.collection.QueueTools
+ * @see org.eclipse.jpt.common.utility.internal.queue.ArrayQueue
+ * @see org.eclipse.jpt.common.utility.internal.queue.LinkedQueue
+ * @see org.eclipse.jpt.common.utility.internal.queue.QueueTools
+ * @see Deque Deque - for an interface without the semantic baggage of {@link java.util.Deque}
* @see Stack Stack - for an interface without the semantic baggage of {@link java.util.Stack}
*/
public interface Queue<E> {
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Stack.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/stack/Stack.java
index 11efaf5600..df382cc955 100644
--- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/collection/Stack.java
+++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/stack/Stack.java
@@ -7,7 +7,9 @@
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
-package org.eclipse.jpt.common.utility.collection;
+package org.eclipse.jpt.common.utility.stack;
+
+import org.eclipse.jpt.common.utility.queue.Queue;
/**
* Interface defining the classic stack behavior,
@@ -20,9 +22,9 @@ package org.eclipse.jpt.common.utility.collection;
* will almost certainly be broken (repeatedly) as the API evolves.
*
* @param <E> the type of elements contained by the stack
- * @see org.eclipse.jpt.common.utility.internal.collection.ArrayStack
- * @see org.eclipse.jpt.common.utility.internal.collection.LinkedStack
- * @see org.eclipse.jpt.common.utility.internal.collection.StackTools
+ * @see org.eclipse.jpt.common.utility.internal.stack.ArrayStack
+ * @see org.eclipse.jpt.common.utility.internal.stack.LinkedStack
+ * @see org.eclipse.jpt.common.utility.internal.stack.StackTools
* @see Queue Queue - for an interface without the semantic baggage of {@link java.util.Queue}
*/
public interface Stack<E> {
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java
index df1c3a16ba..69ac508837 100644
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -134,8 +134,8 @@ public class ASTToolsTests
Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
assertEquals(
- ListTools.list(new String[] {fqOtherClassName, fqOtherClassName2}),
- ListTools.list(actual));
+ ListTools.arrayList(new String[] {fqOtherClassName, fqOtherClassName2}),
+ ListTools.arrayList(actual));
}
public void testResolveFullyQualifiedNames2() throws Exception {
@@ -162,8 +162,8 @@ public class ASTToolsTests
Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
assertEquals(
- ListTools.list(new String[] {null, fqOtherClassName}),
- ListTools.list(actual));
+ ListTools.arrayList(new String[] {null, fqOtherClassName}),
+ ListTools.arrayList(actual));
}
public void testResolveFullyQualifiedNames3() throws Exception {
@@ -190,7 +190,7 @@ public class ASTToolsTests
Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
assertEquals(
- ListTools.list(new String[] {null, fqOtherClassName}),
- ListTools.list(actual));
+ ListTools.arrayList(new String[] {null, fqOtherClassName}),
+ ListTools.arrayList(actual));
}
}
diff --git a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/TreeContentProviderUiTest.java b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/TreeContentProviderUiTest.java
index 6e95ea0f73..5c349e0515 100644
--- a/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/TreeContentProviderUiTest.java
+++ b/common/tests/org.eclipse.jpt.common.ui.tests/src/org/eclipse/jpt/common/ui/tests/internal/jface/TreeContentProviderUiTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -376,7 +376,7 @@ public class TreeContentProviderUiTest
public CollectionValueModel<TreeNode> transform(TreeNode value) {
return (value instanceof Nest) ?
this.transform((Nest) value) :
- new StaticCollectionValueModel<TreeNode>(CollectionTools.collection(value));
+ new StaticCollectionValueModel<TreeNode>(CollectionTools.hashBag(value));
}
private CollectionValueModel<TreeNode> transform(Nest nest) {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
index 34edf4821c..28e0f2a141 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/JptCommonUtilityTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,11 +9,10 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal;
-import junit.framework.Test;
-import junit.framework.TestSuite;
import org.eclipse.jpt.common.utility.tests.internal.collection.JptCommonUtilityCollectionTests;
import org.eclipse.jpt.common.utility.tests.internal.command.JptCommonUtilityCommandTests;
import org.eclipse.jpt.common.utility.tests.internal.comparator.JptCommonUtilityComparatorTests;
+import org.eclipse.jpt.common.utility.tests.internal.deque.JptCommonUtilityDequeTests;
import org.eclipse.jpt.common.utility.tests.internal.enumeration.JptCommonUtilityEnumerationTests;
import org.eclipse.jpt.common.utility.tests.internal.exception.JptCommonUtilityExceptionTests;
import org.eclipse.jpt.common.utility.tests.internal.factory.JptCommonUtilityFactoryTests;
@@ -24,8 +23,12 @@ import org.eclipse.jpt.common.utility.tests.internal.jdbc.JptCommonUtilityJDBCTe
import org.eclipse.jpt.common.utility.tests.internal.model.JptCommonUtilityModelTests;
import org.eclipse.jpt.common.utility.tests.internal.node.JptCommonUtilityNodeTests;
import org.eclipse.jpt.common.utility.tests.internal.predicate.JptCommonUtilityPredicateTests;
+import org.eclipse.jpt.common.utility.tests.internal.queue.JptCommonUtilityQueueTests;
import org.eclipse.jpt.common.utility.tests.internal.reference.JptCommonUtilityReferenceTests;
+import org.eclipse.jpt.common.utility.tests.internal.stack.JptCommonUtilityStackTests;
import org.eclipse.jpt.common.utility.tests.internal.transformer.JptCommonUtilityTransformerTests;
+import junit.framework.Test;
+import junit.framework.TestSuite;
/**
* decentralize test creation code
@@ -38,6 +41,7 @@ public class JptCommonUtilityTests {
suite.addTest(JptCommonUtilityCollectionTests.suite());
suite.addTest(JptCommonUtilityCommandTests.suite());
suite.addTest(JptCommonUtilityComparatorTests.suite());
+ suite.addTest(JptCommonUtilityDequeTests.suite());
suite.addTest(JptCommonUtilityEnumerationTests.suite());
suite.addTest(JptCommonUtilityExceptionTests.suite());
suite.addTest(JptCommonUtilityFactoryTests.suite());
@@ -48,7 +52,9 @@ public class JptCommonUtilityTests {
suite.addTest(JptCommonUtilityModelTests.suite());
suite.addTest(JptCommonUtilityNodeTests.suite());
suite.addTest(JptCommonUtilityPredicateTests.suite());
+ suite.addTest(JptCommonUtilityQueueTests.suite());
suite.addTest(JptCommonUtilityReferenceTests.suite());
+ suite.addTest(JptCommonUtilityStackTests.suite());
suite.addTest(JptCommonUtilityTransformerTests.suite());
suite.addTestSuite(ArrayToolsTests.class);
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/AbstractRepeatingElementListTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/AbstractRepeatingElementListTests.java
index 6c8c23dc1b..4170eb8497 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/AbstractRepeatingElementListTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/AbstractRepeatingElementListTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -70,7 +70,7 @@ public abstract class AbstractRepeatingElementListTests
boolean exCaught = false;
try {
- list.addAll(CollectionTools.collection("foo", "bar"));
+ list.addAll(CollectionTools.hashBag("foo", "bar"));
fail("bogus list: " + list);
} catch (UnsupportedOperationException ex) {
exCaught = true;
@@ -84,7 +84,7 @@ public abstract class AbstractRepeatingElementListTests
boolean exCaught = false;
try {
- list.addAll(1, CollectionTools.collection("foo", "bar"));
+ list.addAll(1, CollectionTools.hashBag("foo", "bar"));
fail("bogus list: " + list);
} catch (UnsupportedOperationException ex) {
exCaught = true;
@@ -168,6 +168,9 @@ public abstract class AbstractRepeatingElementListTests
List<String> list = this.buildList(3);
assertEquals(0, list.indexOf(this.getElement()));
assertEquals(-1, list.indexOf(new Object()));
+
+ list = this.buildList(0);
+ assertEquals(-1, list.indexOf(this.getElement()));
}
public void testIsEmpty() {
@@ -207,6 +210,10 @@ public abstract class AbstractRepeatingElementListTests
List<String> list = this.buildList(3);
assertEquals(2, list.lastIndexOf(this.getElement()));
assertEquals(-1, list.lastIndexOf(new Object()));
+
+ list = this.buildList(0);
+ assertEquals(-1, list.indexOf(this.getElement()));
+ assertEquals(-1, list.lastIndexOf(new Object()));
}
public void testListIterator() {
@@ -474,6 +481,19 @@ public abstract class AbstractRepeatingElementListTests
assertNull(array[20]);
}
+ public void testToString() {
+ List<String> list1 = this.buildList(3);
+ List<String> list2 = new ArrayList<String>();
+ list2.add(this.getElement());
+ list2.add(this.getElement());
+ list2.add(this.getElement());
+ assertEquals(list2.toString(), list1.toString());
+
+ list1 = this.buildList(0);
+ list2 = new ArrayList<String>();
+ assertEquals(list2.toString(), list1.toString());
+ }
+
public abstract List<String> buildList(int size);
public abstract String getElement();
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/BagTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/BagTests.java
index 8f72babc00..42682e35dd 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/BagTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/BagTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle. All rights reserved.
+ * Copyright (c) 2010, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,76 +9,813 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.collection;
-import junit.framework.TestCase;
-
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
import org.eclipse.jpt.common.utility.collection.Bag;
-import org.eclipse.jpt.common.utility.internal.collection.EmptyBag;
-import org.eclipse.jpt.common.utility.internal.collection.HashBag;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.internal.ObjectTools;
+import org.eclipse.jpt.common.utility.tests.internal.MultiThreadedTestCase;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+//subclass MultiThreadedTestCase for subclasses of this class
@SuppressWarnings("nls")
-public class BagTests extends TestCase {
+public abstract class BagTests
+ extends MultiThreadedTestCase
+{
+ private Bag<String> bag;
- public BagTests(String name) {
+ protected BagTests(String name) {
super(name);
}
- public void testEmptyBag_iterator() throws Exception {
- assertFalse(EmptyBag.instance().iterator().hasNext());
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.bag = this.buildBag();
+ }
+
+ protected Bag<String> buildBag() {
+ Bag<String> b = this.buildBag_();
+ b.add(null);
+ b.add(new String("one"));
+ b.add(new String("two"));
+ b.add(new String("two"));
+ b.add(new String("three"));
+ b.add(new String("three"));
+ b.add(new String("three"));
+ b.add(new String("four"));
+ b.add(new String("four"));
+ b.add(new String("four"));
+ b.add(new String("four"));
+ return b;
+ }
+
+ protected abstract Bag<String> buildBag_();
+
+ protected abstract Bag<String> buildBag(Collection<String> c);
+
+ protected abstract Bag<String> buildBag(int initialCapacity, float loadFactor);
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private Collection<String> buildCollection() {
+ Collection<String> c = new ArrayList<String>();
+ c.add(new String("foo"));
+ c.add(new String("foo"));
+ c.add(new String("bar"));
+ c.add(new String("bar"));
+ c.add(new String("bar"));
+ return c;
}
- public void testEmptyBag_size() throws Exception {
- assertEquals(0, EmptyBag.instance().size());
+ public void testCtorCollection() {
+ Collection<String> c = this.buildCollection();
+ Bag<String> b = this.buildBag(c);
+ for (String s : c) {
+ assertTrue(b.contains(s));
+ }
+ }
+
+ public void testCtorIntFloat() {
+ boolean exCaught;
+
+ exCaught = false;
+ try {
+ this.bag = this.buildBag(-20, 0.66f);
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
+ try {
+ this.bag = this.buildBag(20, -0.66f);
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
}
- public void testEmptyBag_uniqueIterator() throws Exception {
- assertFalse(EmptyBag.instance().uniqueIterator().hasNext());
+ public void testAdd() {
+ // the other adds took place in setUp
+ assertTrue(this.bag.add("five"));
+
+ assertTrue(this.bag.contains("one"));
+ assertTrue(this.bag.contains("two"));
+ assertTrue(this.bag.contains("three"));
+ assertTrue(this.bag.contains("four"));
+ assertTrue(this.bag.contains("five"));
}
- public void testEmptyBag_uniqueCount() throws Exception {
- assertEquals(0, EmptyBag.instance().uniqueCount());
+ public void testAddCount() {
+ // the other adds took place in setUp
+ this.bag.add("minus3", -3);
+ this.bag.add("zero", 0);
+ this.bag.add("five", 5);
+
+ assertFalse(this.bag.contains("minus3"));
+ assertFalse(this.bag.contains("zero"));
+ assertEquals(1, this.bag.count("one"));
+ assertEquals(2, this.bag.count("two"));
+ assertEquals(3, this.bag.count("three"));
+ assertEquals(4, this.bag.count("four"));
+ assertEquals(5, this.bag.count("five"));
+
+ this.bag.add("three", 2);
+ assertEquals(5, this.bag.count("three"));
}
- public void testEmptyBag_count() throws Exception {
- assertEquals(0, EmptyBag.instance().count("foo"));
+ public void testAddAll() {
+ Collection<String> c = this.buildCollection();
+ assertTrue(this.bag.addAll(c));
+ for (String s : c) {
+ assertTrue(this.bag.contains(s));
+ }
}
- public void testEmptyBag_entries() throws Exception {
- assertFalse(EmptyBag.instance().entries().hasNext());
+ public void testClear() {
+ assertTrue(this.bag.contains("one"));
+ assertTrue(this.bag.contains("two"));
+ assertTrue(this.bag.contains("three"));
+ assertTrue(this.bag.contains("four"));
+ assertTrue(this.bag.contains(null));
+ assertEquals(11, this.bag.size());
+ this.bag.clear();
+ assertFalse(this.bag.contains("one"));
+ assertFalse(this.bag.contains("two"));
+ assertFalse(this.bag.contains("three"));
+ assertFalse(this.bag.contains("four"));
+ assertFalse(this.bag.contains(null));
+ assertEquals(0, this.bag.size());
}
- public void testEmptyBag_remove() throws Exception {
- assertFalse(EmptyBag.instance().remove("foo", 3));
+ public void testClone() {
+ @SuppressWarnings("unchecked")
+ Bag<String> bag2 = (Bag<String>) ObjectTools.execute(this.bag, "clone");
+ assertTrue(this.bag != bag2);
+ assertEquals(this.bag, bag2);
+ assertTrue(this.bag.hashCode() == bag2.hashCode());
}
- public void testEmptyBag_add() throws Exception {
+ public void testContains() {
+ assertTrue(this.bag.contains(null));
+ assertTrue(this.bag.contains("one"));
+ assertTrue(this.bag.contains("two"));
+ assertTrue(this.bag.contains("three"));
+ assertTrue(this.bag.contains("four"));
+ assertTrue(this.bag.contains(new String("four")));
+ assertTrue(this.bag.contains("fo" + "ur"));
+ assertFalse(this.bag.contains("five"));
+ }
+
+ public void testContainsAll() {
+ Collection<String> c = new ArrayList<String>();
+ c.add(null);
+ c.add(new String("one"));
+ c.add(new String("two"));
+ c.add(new String("three"));
+ c.add(new String("four"));
+ assertTrue(this.bag.containsAll(c));
+ }
+
+ public void testCount() {
+ assertEquals(0, this.bag.count("zero"));
+ assertEquals(1, this.bag.count("one"));
+ assertEquals(2, this.bag.count("two"));
+ assertEquals(3, this.bag.count("three"));
+ assertEquals(4, this.bag.count("four"));
+ assertEquals(0, this.bag.count("five"));
+ }
+
+ public void testEqualsObject() {
+ Bag<String> bag2 = this.buildBag();
+ assertEquals(this.bag, this.bag);
+ assertEquals(this.bag, bag2);
+
+ bag2.add("four");
+ assertFalse(this.bag.equals(bag2)); // same unique counts; different sizes
+ bag2.remove("four");
+
+ bag2.add("five");
+ bag2.remove("four");
+ assertFalse(this.bag.equals(bag2)); // same sizes; different unique counts
+ bag2.remove("five");
+ bag2.add("four");
+
+ bag2.remove("two");
+ bag2.add("four");
+ assertFalse(this.bag.equals(bag2)); // same sizes; same unique counts
+
+ Collection<String> c = new ArrayList<String>(this.bag);
+ assertFalse(this.bag.equals(c));
+ }
+
+ public void testHashCode() {
+ Bag<String> bag2 = this.buildBag();
+ assertEquals(this.bag.hashCode(), bag2.hashCode());
+ }
+
+ public void testIsEmpty() {
+ assertFalse(this.bag.isEmpty());
+ this.bag.clear();
+ assertTrue(this.bag.isEmpty());
+ this.bag.add("foo");
+ assertFalse(this.bag.isEmpty());
+ }
+
+ public void testEmptyIterator() {
+ this.bag.clear();
+ Iterator<String> iterator = this.bag.iterator();
+ assertFalse(iterator.hasNext());
+
boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
try {
- EmptyBag.instance().add("foo", 3);
- fail();
- } catch (UnsupportedOperationException ex) {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
exCaught = true;
}
assertTrue(exCaught);
}
- public void testEmptyBag_equals() throws Exception {
- assertTrue(EmptyBag.instance().equals(EmptyBag.instance()));
- assertFalse(EmptyBag.instance().equals("foo"));
+ public void testIterator() {
+ int i = 0;
+ Iterator<String> iterator = this.bag.iterator();
+ assertTrue(iterator.hasNext());
+ while (iterator.hasNext()) {
+ iterator.next();
+ i++;
+ }
+ assertEquals(11, i);
+ assertFalse(iterator.hasNext());
- Bag<Object> bag = new HashBag<Object>();
- assertTrue(EmptyBag.instance().equals(bag));
- bag.add("foo");
- assertFalse(EmptyBag.instance().equals(bag));
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ iterator.remove();
+ assertEquals(10, this.bag.size());
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ // start over
+ iterator = this.bag.iterator();
+ this.bag.add("five");
+ exCaught = false;
+ try {
+ iterator.next();
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testIterator_remove_all() {
+ assertEquals(4, this.bag.count("four"));
+ Iterator<String> iterator = this.bag.iterator();
+ String next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if ((next != null) && next.equals("four")) {
+ iterator.remove();
+ }
+ }
+ assertEquals(0, this.bag.count("four"));
+ }
+
+ public void testIterator_remove_CME() {
+ Iterator<String> iterator = this.bag.iterator();
+ assertTrue(iterator.hasNext());
+ boolean exCaught = false;
+ try {
+ String next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.equals("four")) {
+ this.bag.remove("two");
+ iterator.remove();
+ }
+ }
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEmptyUniqueIterator() {
+ this.bag.clear();
+ Iterator<String> iterator = this.bag.uniqueIterator();
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
}
- public void testEmptyBag_hashCode() throws Exception {
- assertEquals(0, EmptyBag.instance().hashCode());
+ public void testUniqueIterator() {
+ int i = 0;
+ Iterator<String> iterator = this.bag.uniqueIterator();
+ assertTrue(iterator.hasNext());
+ while (iterator.hasNext()) {
+ iterator.next();
+ i++;
+ }
+ assertEquals(5, i);
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ // start over
+ iterator = this.bag.uniqueIterator();
+ Object next = null;
+ while (iterator.hasNext() && !"four".equals(next)) {
+ next = iterator.next();
+ }
+ iterator.remove();
+ assertEquals(7, this.bag.size());
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ // start over
+ iterator = this.bag.uniqueIterator();
+ this.bag.add("five");
+ exCaught = false;
+ try {
+ iterator.next();
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
}
- public void testEmptyBag_serialization() throws Exception {
- Bag<?> xxx = TestTools.serialize(EmptyBag.instance());
- assertSame(EmptyBag.instance(), xxx);
+ public void testEmptyEntries() {
+ this.bag.clear();
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEntries() {
+ int i = 0;
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertTrue(iterator.hasNext());
+ while (iterator.hasNext()) {
+ iterator.next();
+ i++;
+ }
+ assertEquals(5, i);
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ // start over
+ iterator = this.bag.entries();
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ iterator.remove();
+ break;
+ }
+ }
+ assertEquals(7, this.bag.size());
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ // start over
+ iterator = this.bag.entries();
+ this.bag.add("five");
+ exCaught = false;
+ try {
+ iterator.next();
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEntries_remove_CME() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertTrue(iterator.hasNext());
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ this.bag.remove("two");
+ iterator.remove();
+ }
+ }
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEntry_setCount_increase() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count("four"));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ assertEquals(4, next.setCount(42));
+ break;
+ }
+ }
+ assertEquals(42, this.bag.count("four"));
+ assertEquals(49, this.bag.size());
+ }
+
+ public void testEntry_setCount_same() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count("four"));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ assertEquals(4, next.setCount(4));
+ break;
+ }
+ }
+ assertEquals(4, this.bag.count("four"));
+ assertEquals(11, this.bag.size());
+ }
+
+ public void testEntry_setCount_derease() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count("four"));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ assertEquals(4, next.setCount(2));
+ break;
+ }
+ }
+ assertEquals(2, this.bag.count("four"));
+ assertEquals(9, this.bag.size());
+ }
+
+ public void testEntry_setCount_IAE1() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ next.setCount(0);
+ fail(next.toString());
+ }
+ }
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEntry_setCount_IAE2() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ next.setCount(-33);
+ fail(next.toString());
+ }
+ }
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_equalsObject() {
+ Iterator<Bag.Entry<String>> iterator1 = this.bag.entries();
+ Bag<String> bag2 = this.buildBag();
+ Bag.Entry<String> next1 = null;
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals("four")) {
+ break;
+ }
+ }
+ assertFalse(next1.equals("four"));
+ Iterator<Bag.Entry<String>> iterator2 = bag2.entries();
+ Bag.Entry<String> next2 = null;
+ while (iterator2.hasNext()) {
+ next2 = iterator2.next();
+ if (next2.getElement().equals("four")) {
+ break;
+ }
+ }
+ assertEquals(next1, next2);
+
+ bag2.remove("four");
+ iterator1 = this.bag.entries();
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals("four")) {
+ break;
+ }
+ }
+ iterator2 = bag2.entries();
+ while (iterator2.hasNext()) {
+ next2 = iterator2.next();
+ if (next2.getElement().equals("four")) {
+ break;
+ }
+ }
+ assertEquals(next1.getElement(), next2.getElement());
+ assertFalse(next1.equals(next2));
+
+ iterator1 = this.bag.entries();
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals("three")) {
+ break;
+ }
+ }
+ assertEquals(next1.getCount(), next2.getCount());
+ assertFalse(next1.equals(next2));
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_hashCode() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ break;
+ }
+ }
+ assertEquals(4 * "four".hashCode(), next.hashCode());
+
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement() == null) {
+ break;
+ }
+ }
+ assertEquals(0, next.hashCode());
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_toString() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals("four")) {
+ break;
+ }
+ }
+ assertEquals("four=>4", next.toString());
+ }
+
+ public void testRemove() {
+ assertTrue(this.bag.remove("one"));
+ assertFalse(this.bag.contains("one"));
+ assertFalse(this.bag.remove("one"));
+
+ assertTrue(this.bag.remove("two"));
+ assertTrue(this.bag.remove("two"));
+ assertFalse(this.bag.contains("two"));
+ assertFalse(this.bag.remove("two"));
+ }
+
+ public void testRemoveCount() {
+ assertFalse(this.bag.remove("one", 0));
+ assertTrue(this.bag.contains("one"));
+
+ assertTrue(this.bag.remove("one", 1));
+ assertFalse(this.bag.contains("one"));
+ assertFalse(this.bag.remove("one"));
+
+ assertFalse(this.bag.remove("two", -3));
+ assertTrue(this.bag.remove("two", 1));
+ assertTrue(this.bag.contains("two"));
+
+ assertTrue(this.bag.remove("two", 1));
+ assertFalse(this.bag.contains("two"));
+ assertFalse(this.bag.remove("two"));
+
+ assertTrue(this.bag.remove("three", 3));
+ assertFalse(this.bag.contains("three"));
+ assertFalse(this.bag.remove("three"));
+ }
+
+ public void testRemoveAll() {
+ Collection<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add("three");
+ assertTrue(this.bag.removeAll(c));
+ assertFalse(this.bag.contains("one"));
+ assertFalse(this.bag.contains("three"));
+ assertFalse(this.bag.remove("one"));
+ assertFalse(this.bag.remove("three"));
+ assertFalse(this.bag.removeAll(c));
+ }
+
+ public void testRetainAll() {
+ Collection<String> c = new ArrayList<String>();
+ c.add("one");
+ c.add("three");
+ assertTrue(this.bag.retainAll(c));
+ assertTrue(this.bag.contains("one"));
+ assertTrue(this.bag.contains("three"));
+ assertFalse(this.bag.contains("two"));
+ assertFalse(this.bag.contains("four"));
+ assertFalse(this.bag.remove("two"));
+ assertFalse(this.bag.remove("four"));
+ assertFalse(this.bag.retainAll(c));
+ }
+
+ public void testSize() {
+ assertTrue(this.bag.size() == 11);
+ this.bag.add("five");
+ this.bag.add("five");
+ this.bag.add("five");
+ this.bag.add("five");
+ this.bag.add("five");
+ assertEquals(16, this.bag.size());
+ }
+
+ public void testSerialization() throws Exception {
+ Bag<String> bag2 = TestTools.serialize(this.bag);
+
+ assertTrue("same object?", this.bag != bag2);
+ assertEquals(11, bag2.size());
+ assertEquals(this.bag, bag2);
+ // look for similar elements
+ assertTrue(bag2.contains(null));
+ assertTrue(bag2.contains("one"));
+ assertTrue(bag2.contains("two"));
+ assertTrue(bag2.contains("three"));
+ assertTrue(bag2.contains("four"));
+
+ int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
+ for (String s : bag2) {
+ if (s == null) {
+ nullCount++;
+ } else if (s.equals("one")) {
+ oneCount++;
+ } else if (s.equals("two")) {
+ twoCount++;
+ } else if (s.equals("three")) {
+ threeCount++;
+ } else if (s.equals("four")) {
+ fourCount++;
+ }
+ }
+ assertEquals(1, nullCount);
+ assertEquals(1, oneCount);
+ assertEquals(2, twoCount);
+ assertEquals(3, threeCount);
+ assertEquals(4, fourCount);
+ }
+
+ public void testSerialization_empty() throws Exception {
+ this.bag.clear();
+ Bag<String> bag2 = TestTools.serialize(this.bag);
+
+ assertTrue("same object?", this.bag != bag2);
+ assertEquals(0, bag2.size());
+ assertEquals(this.bag, bag2);
+ }
+
+ public void testToArray() {
+ Object[] a = this.bag.toArray();
+ assertEquals(11, a.length);
+ assertTrue(ArrayTools.contains(a, null));
+ assertTrue(ArrayTools.contains(a, "one"));
+ assertTrue(ArrayTools.contains(a, "two"));
+ assertTrue(ArrayTools.contains(a, "three"));
+ assertTrue(ArrayTools.contains(a, "four"));
+ }
+
+ public void testToArrayObjectArray() {
+ String[] a = new String[12];
+ a[11] = "not null";
+ String[] b = this.bag.toArray(a);
+ assertEquals(a, b);
+ assertEquals(12, a.length);
+ assertTrue(ArrayTools.contains(a, null));
+ assertTrue(ArrayTools.contains(a, "one"));
+ assertTrue(ArrayTools.contains(a, "two"));
+ assertTrue(ArrayTools.contains(a, "three"));
+ assertTrue(ArrayTools.contains(a, "four"));
+ assertTrue(a[11] == null);
+ }
+
+ public void testToString() {
+ String s = this.bag.toString();
+ assertTrue(s.startsWith("["));
+ assertTrue(s.endsWith("]"));
+ int commaCount = 0;
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == ',') {
+ commaCount++;
+ }
+ }
+ assertEquals(10, commaCount);
+ assertTrue(s.indexOf("one") != -1);
+ assertTrue(s.indexOf("two") != -1);
+ assertTrue(s.indexOf("three") != -1);
+ assertTrue(s.indexOf("four") != -1);
+ assertTrue(s.indexOf("null") != -1);
}
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/CollectionToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/CollectionToolsTests.java
index d198057575..a9f30d140a 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/CollectionToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/CollectionToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -20,17 +20,18 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.collection.Bag;
import org.eclipse.jpt.common.utility.internal.ClassTools;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.collection.EmptyBag;
+import org.eclipse.jpt.common.utility.internal.collection.IdentityHashBag;
+import org.eclipse.jpt.common.utility.internal.collection.SynchronizedBag;
import org.eclipse.jpt.common.utility.internal.comparator.ComparatorTools;
import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterator.EmptyIterator;
import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
import org.eclipse.jpt.common.utility.tests.internal.ArrayToolsTests;
+import junit.framework.TestCase;
@SuppressWarnings("nls")
public class CollectionToolsTests
@@ -164,7 +165,7 @@ public class CollectionToolsTests
String[] a = this.buildStringArray1();
assertTrue(CollectionTools.addAll(list, a));
assertEquals(6, list.size());
- assertTrue(list.containsAll(CollectionTools.collection(a)));
+ assertTrue(list.containsAll(CollectionTools.hashBag(a)));
}
public void testAddAllCollectionObjectArray_StringListEmptyArray() {
@@ -177,7 +178,7 @@ public class CollectionToolsTests
String[] a = this.buildStringArray1();
assertFalse(CollectionTools.addAll(set, a));
assertEquals(3, set.size());
- assertTrue(set.containsAll(CollectionTools.collection(a)));
+ assertTrue(set.containsAll(CollectionTools.hashBag(a)));
assertFalse(CollectionTools.addAll(set, new String[0]));
}
@@ -193,7 +194,7 @@ public class CollectionToolsTests
assertTrue(CollectionTools.addAll(list, a));
assertEquals(6, list.size());
- assertTrue(list.containsAll(CollectionTools.collection(a)));
+ assertTrue(list.containsAll(CollectionTools.hashBag(a)));
}
public void testAddAllCollectionObjectArray_ObjectUnmodified() {
@@ -201,118 +202,81 @@ public class CollectionToolsTests
Set<Object> set = this.buildObjectSet1();
assertFalse(CollectionTools.addAll(set, a));
assertEquals(3, set.size());
- assertTrue(set.containsAll(CollectionTools.collection(a)));
- }
-
-
- // ********** bag **********
-
- public void testBagIterable() {
- Iterable<String> iterable = this.buildStringList1();
- Bag<String> b = CollectionTools.bag(iterable);
- assertEquals(3, b.size());
- assertTrue(b.containsAll(this.buildStringList1()));
+ assertTrue(set.containsAll(CollectionTools.hashBag(a)));
}
- public void testBagIterableInt() {
- Iterable<String> iterable = this.buildStringList1();
- Bag<String> b = CollectionTools.bag(iterable, 3);
- assertEquals(3, b.size());
- assertTrue(b.containsAll(this.buildStringList1()));
- }
- public void testBagIterator_String() {
- Bag<String> b = CollectionTools.bag(this.buildStringList1().iterator());
- assertEquals(3, b.size());
- assertTrue(b.containsAll(this.buildStringList1()));
- }
+ // ********** hash bag **********
- public void testBagIterator_StringObject() {
- Collection<String> c = new ArrayList<String>();
- c.add("zero");
- c.add("one");
- c.add("two");
- c.add("three");
- Bag<Object> b = CollectionTools.<Object>bag(c.iterator());
- assertEquals(4, b.size());
- assertTrue(b.containsAll(c));
- }
-
- public void testBagIterator_Empty() {
- Bag<String> b = CollectionTools.bag(EmptyIterator.<String>instance());
- assertEquals(0, b.size());
- }
-
- public void testBagIteratorInt() {
- Bag<String> b = CollectionTools.bag(this.buildStringList1().iterator(), 3);
- assertEquals(3, b.size());
- assertTrue(b.containsAll(this.buildStringList1()));
- }
-
- public void testBagIteratorInt_Empty() {
- Bag<String> b = CollectionTools.bag(EmptyIterator.<String>instance(), 3);
- assertEquals(0, b.size());
- }
-
- public void testBagObjectArray() {
- Bag<String> b = CollectionTools.bag(this.buildStringArray1());
- assertEquals(3, b.size());
- assertTrue(CollectionTools.containsAll(b, (Object[]) this.buildStringArray1()));
- }
-
- public void testBagObjectArray_Vararg() {
- Bag<String> b = CollectionTools.bag("foo", "bar", "baz");
- assertEquals(3, b.size());
- assertTrue(CollectionTools.containsAll(b, new Object[]{"foo", "bar", "baz"}));
- }
-
- public void testBagObjectArray_Empty() {
- Bag<String> b = CollectionTools.bag(EmptyBag.<String>instance());
- assertEquals(0, b.size());
+ public void testHashBagIntFloat() {
+ Collection<String> c = CollectionTools.hashBag(42, 0.88f);
+ assertEquals(0, c.size());
+ assertTrue(c.isEmpty());
}
-
- // ********** collection **********
-
- public void testCollectionIterable() {
+ public void testHashBagIterable() {
Iterable<String> iterable = this.buildStringList1();
- Collection<String> c = CollectionTools.collection(iterable);
+ Collection<String> c = CollectionTools.hashBag(iterable);
assertEquals(3, c.size());
assertTrue(c.containsAll(this.buildStringList1()));
}
- public void testCollectionIterableInt() {
+ public void testHashBagIterableInt() {
Iterable<String> iterable = this.buildStringList1();
- Collection<String> c = CollectionTools.collection(iterable, 3);
+ Collection<String> c = CollectionTools.hashBag(iterable, 3);
assertEquals(3, c.size());
assertTrue(c.containsAll(this.buildStringList1()));
}
- public void testCollectionIterator() {
- Collection<String> c = CollectionTools.collection(this.buildStringList1().iterator());
+ public void testHashBagIterator() {
+ Collection<String> c = CollectionTools.hashBag(this.buildStringList1().iterator());
assertEquals(3, c.size());
assertTrue(c.containsAll(this.buildStringList1()));
}
- public void testCollectionIterator_ObjectString() {
- Collection<Object> c = CollectionTools.<Object>collection(this.buildStringList1().iterator());
+ public void testHashBagIterator_ObjectString() {
+ Collection<Object> c = CollectionTools.<Object>hashBag(this.buildStringList1().iterator());
assertEquals(3, c.size());
assertTrue(c.containsAll(this.buildStringList1()));
}
- public void testCollectionIteratorInt() {
- Collection<String> c = CollectionTools.collection(this.buildStringList1().iterator(), 3);
+ public void testHashBagIteratorInt() {
+ Collection<String> c = CollectionTools.hashBag(this.buildStringList1().iterator(), 3);
assertEquals(3, c.size());
assertTrue(c.containsAll(this.buildStringList1()));
}
- public void testCollectionObjectArray() {
- Collection<String> c = CollectionTools.collection(this.buildStringArray1());
+ public void testHashBagObjectArray() {
+ Collection<String> c = CollectionTools.hashBag(this.buildStringArray1());
assertEquals(3, c.size());
assertTrue(CollectionTools.containsAll(c, (Object[]) this.buildStringArray1()));
}
+ // ********** synchronized bag **********
+
+ public void testSynchronizedBagObject() {
+ Object mutex = "foo";
+ SynchronizedBag<String> sBag = CollectionTools.synchronizedBag(mutex);
+ assertEquals(mutex, sBag.getMutex());
+ }
+
+ public void testSynchronizedBagBagObject() {
+ Bag<String> bag = CollectionTools.hashBag();
+ Object mutex = "foo";
+ SynchronizedBag<String> sBag = CollectionTools.synchronizedBag(bag, mutex);
+ assertEquals(mutex, sBag.getMutex());
+ }
+
+
+ // ********** identity hash bag **********
+
+ public void testIdentityHashBagIntFloat() {
+ IdentityHashBag<String> bag = CollectionTools.identityHashBag(42, 0.88f);
+ assertTrue(bag.isEmpty());
+ }
+
+
// ********** contains all **********
public void testContainsAllCollectionIterable() {
@@ -348,22 +312,50 @@ public class CollectionToolsTests
// ********** filter **********
public void testFilterCollectionFilter() {
- Collection<String> c = CollectionTools.collection(new String[] { "zero", "one", "two", "three", "four" });
+ Collection<String> c = CollectionTools.hashBag(new String[] { "zero", "one", "two", "three", "four" });
Collection<String> actual = CollectionTools.filter(c, new ArrayToolsTests.StringLengthEquals(3));
- Collection<String> expected = CollectionTools.collection(new String[] { "one", "two" });
+ Collection<String> expected = CollectionTools.hashBag(new String[] { "one", "two" });
assertEquals(expected, actual);
}
public void testFilterCollectionFilterTransparent() {
- Collection<String> c = CollectionTools.collection(new String[] { "zero", "one", "two", "three", "four" });
+ Collection<String> c = CollectionTools.hashBag(new String[] { "zero", "one", "two", "three", "four" });
Collection<String> actual = CollectionTools.filter(c, PredicateTools.<String>true_());
- Collection<String> expected = CollectionTools.collection(new String[] { "zero", "one", "two", "three", "four" });
+ Collection<String> expected = CollectionTools.hashBag(new String[] { "zero", "one", "two", "three", "four" });
assertEquals(expected, actual);
assertNotSame(expected, actual);
}
+ // ********** identity bag **********
+
+ // tested in IdentityHashBagTests
+
// ********** partition **********
+ public void testPartitionCollectionInt_negative() {
+ this.verifyPartitionCollectionException(-3);
+ }
+
+ public void testPartitionCollectionInt_0() {
+ this.verifyPartitionCollectionException(0);
+ }
+
+ public void testPartitionCollectionInt_tooMany() {
+ this.verifyPartitionCollectionException(6);
+ }
+
+ public void verifyPartitionCollectionException(int count) {
+ Collection<String> c = Arrays.asList(new String[] { "zero", "one", "two", "three", "four" });
+ boolean exCaught = false;
+ try {
+ ArrayList<ArrayList<String>> actual = CollectionTools.partition(c, count);
+ fail("bogus partition: " + actual);
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testPartitionCollectionInt_1() {
Collection<String> c = Arrays.asList(new String[] { "zero", "one", "two", "three", "four" });
ArrayList<ArrayList<String>> actual = CollectionTools.partition(c, 1);
@@ -792,6 +784,18 @@ public class CollectionToolsTests
}
+ // ********** to array fix **********
+
+ public void testToArrayCollectionClass() {
+ List<String> list = Arrays.asList(new String[] { "zero", "one", "two" });
+ String[] actual = CollectionTools.toArray(list, String.class);
+ assertEquals(3, actual.length);
+ assertEquals("zero", actual[0]);
+ assertEquals("one", actual[1]);
+ assertEquals("two", actual[2]);
+ }
+
+
// ********** transform **********
public void testTransformCollectionTransformer() {
@@ -804,23 +808,23 @@ public class CollectionToolsTests
}
- // ********** set **********
+ // ********** hash set **********
- public void testSetIterable() {
+ public void testHashSetIterable() {
Iterable<String> iterable = this.buildStringSet1();
- assertEquals(this.buildStringSet1(), CollectionTools.set(iterable));
+ assertEquals(this.buildStringSet1(), CollectionTools.hashSet(iterable));
}
- public void testSetIterableInt() {
+ public void testHashSetIterableInt() {
Iterable<String> iterable = this.buildStringSet1();
- assertEquals(this.buildStringSet1(), CollectionTools.set(iterable, 22));
+ assertEquals(this.buildStringSet1(), CollectionTools.hashSet(iterable, 22));
}
- public void testSetIterator_String() {
- assertEquals(this.buildStringSet1(), CollectionTools.set(this.buildStringSet1().iterator()));
+ public void testHashSetIterator_String() {
+ assertEquals(this.buildStringSet1(), CollectionTools.hashSet(this.buildStringSet1().iterator()));
}
- public void testSetIterator_Object() {
+ public void testHashSetIterator_Object() {
List<String> list = new ArrayList<String>();
list.add("0");
list.add("1");
@@ -833,21 +837,21 @@ public class CollectionToolsTests
Set<String> set = new HashSet<String>();
set.addAll(list);
- assertEquals(set, CollectionTools.<Object>set(list.iterator()));
+ assertEquals(set, CollectionTools.<Object>hashSet(list.iterator()));
}
- public void testSetIteratorInt() {
- assertEquals(this.buildStringSet1(), CollectionTools.set(this.buildStringSet1().iterator(), 3));
+ public void testHashSetIteratorInt() {
+ assertEquals(this.buildStringSet1(), CollectionTools.hashSet(this.buildStringSet1().iterator(), 3));
}
- public void testSetObjectArray() {
- assertEquals(this.buildStringSet1(), CollectionTools.set(this.buildStringSet1().toArray()));
+ public void testHashSetObjectArray() {
+ assertEquals(this.buildStringSet1(), CollectionTools.hashSet(this.buildStringSet1().toArray()));
}
- // ********** sorted set **********
+ // ********** tree set **********
- public void testSortedSetIterable() {
+ public void testTreeSetIterable() {
ArrayList<String> list = new ArrayList<String>();
list.add("0");
list.add("2");
@@ -858,11 +862,11 @@ public class CollectionToolsTests
ss1.addAll(list);
Iterable<String> iterable = list;
- SortedSet<String> ss2 = CollectionTools.<String>sortedSet(iterable);
+ SortedSet<String> ss2 = CollectionTools.<String>treeSet(iterable);
assertEquals(ss1, ss2);
}
- public void testSortedSetIterableInt() {
+ public void testTreeSetIterableInt() {
ArrayList<String> list = new ArrayList<String>();
list.add("0");
list.add("2");
@@ -873,11 +877,11 @@ public class CollectionToolsTests
ss1.addAll(list);
Iterable<String> iterable = list;
- SortedSet<String> ss2 = CollectionTools.<String>sortedSet(iterable, 5);
+ SortedSet<String> ss2 = CollectionTools.<String>treeSet(iterable, 5);
assertEquals(ss1, ss2);
}
- public void testSortedSetIterableComparator() {
+ public void testTreeSetIterableComparator() {
ArrayList<String> list = new ArrayList<String>();
list.add("0");
list.add("2");
@@ -888,11 +892,11 @@ public class CollectionToolsTests
ss1.addAll(list);
Iterable<String> iterable = list;
- SortedSet<String> ss2 = CollectionTools.<String>sortedSet(iterable, ComparatorTools.<String>reverseComparator());
+ SortedSet<String> ss2 = CollectionTools.<String>treeSet(iterable, ComparatorTools.<String>reverseComparator());
assertEquals(ss1, ss2);
}
- public void testSortedSetIterableComparatorInt() {
+ public void testTreeSetIterableComparatorInt() {
ArrayList<String> list = new ArrayList<String>();
list.add("0");
list.add("2");
@@ -903,34 +907,34 @@ public class CollectionToolsTests
ss1.addAll(list);
Iterable<String> iterable = list;
- SortedSet<String> ss2 = CollectionTools.<String>sortedSet(iterable, ComparatorTools.<String>reverseComparator(), 5);
+ SortedSet<String> ss2 = CollectionTools.<String>treeSet(iterable, ComparatorTools.<String>reverseComparator(), 5);
assertEquals(ss1, ss2);
}
- public void testSortedSetIterator() {
- assertEquals(this.buildSortedStringSet1(), CollectionTools.sortedSet(this.buildSortedStringSet1().iterator()));
+ public void testTreeSetIterator() {
+ assertEquals(this.buildSortedStringSet1(), CollectionTools.treeSet(this.buildSortedStringSet1().iterator()));
}
- public void testSortedSetIterator_TreeSet() {
+ public void testTreeSetIterator_TreeSet() {
SortedSet<String> ss1 = new TreeSet<String>();
ss1.add("0");
ss1.add("2");
ss1.add("3");
ss1.add("1");
- SortedSet<String> set2 = CollectionTools.<String>sortedSet(ss1.iterator());
+ SortedSet<String> set2 = CollectionTools.<String>treeSet(ss1.iterator());
assertEquals(ss1, set2);
}
- public void testSortedSetIteratorInt() {
- assertEquals(this.buildSortedStringSet1(), CollectionTools.sortedSet(this.buildSortedStringSet1().iterator(), 8));
+ public void testTreeSetIteratorInt() {
+ assertEquals(this.buildSortedStringSet1(), CollectionTools.treeSet(this.buildSortedStringSet1().iterator(), 8));
}
- public void testSortedSetObjectArray() {
- assertEquals(this.buildSortedStringSet1(), CollectionTools.sortedSet(this.buildStringSet1().toArray(new String[0])));
+ public void testTreeSetObjectArray() {
+ assertEquals(this.buildSortedStringSet1(), CollectionTools.treeSet(this.buildStringSet1().toArray(new String[0])));
}
- public void testSortedSetObjectArrayComparator() {
+ public void testTreeSetObjectArrayComparator() {
ArrayList<String> list = new ArrayList<String>();
list.add("0");
list.add("2");
@@ -941,11 +945,12 @@ public class CollectionToolsTests
ss1.addAll(list);
String[] array = list.toArray(new String[list.size()]);
- SortedSet<String> ss2 = CollectionTools.<String>sortedSet(array, ComparatorTools.<String>reverseComparator());
+ SortedSet<String> ss2 = CollectionTools.<String>treeSet(array, ComparatorTools.<String>reverseComparator());
assertEquals(ss1, ss2);
}
+
// ********** Old School Vector **********
public void testVectorIterable() {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/EmptyBagTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/EmptyBagTests.java
new file mode 100644
index 0000000000..685e1a3839
--- /dev/null
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/EmptyBagTests.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2015 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.common.utility.tests.internal.collection;
+
+import org.eclipse.jpt.common.utility.collection.Bag;
+import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.collection.HashBag;
+import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
+
+@SuppressWarnings("nls")
+public class EmptyBagTests
+ extends TestCase
+{
+ public EmptyBagTests(String name) {
+ super(name);
+ }
+
+ public void testEmptyBag_iterator() throws Exception {
+ assertFalse(CollectionTools.emptyBag().iterator().hasNext());
+ }
+
+ public void testEmptyBag_size() throws Exception {
+ assertEquals(0, CollectionTools.emptyBag().size());
+ }
+
+ public void testEmptyBag_uniqueIterator() throws Exception {
+ assertFalse(CollectionTools.emptyBag().uniqueIterator().hasNext());
+ }
+
+ public void testEmptyBag_uniqueCount() throws Exception {
+ assertEquals(0, CollectionTools.emptyBag().uniqueCount());
+ }
+
+ public void testEmptyBag_count() throws Exception {
+ assertEquals(0, CollectionTools.emptyBag().count("foo"));
+ }
+
+ public void testEmptyBag_entries() throws Exception {
+ assertFalse(CollectionTools.emptyBag().entries().hasNext());
+ }
+
+ public void testEmptyBag_remove() throws Exception {
+ assertFalse(CollectionTools.emptyBag().remove("foo", 3));
+ }
+
+ public void testEmptyBag_add() throws Exception {
+ boolean exCaught = false;
+ try {
+ CollectionTools.emptyBag().add("foo", 3);
+ fail();
+ } catch (UnsupportedOperationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEmptyBag_equals() throws Exception {
+ assertTrue(CollectionTools.emptyBag().equals(CollectionTools.emptyBag()));
+ assertFalse(CollectionTools.emptyBag().equals("foo"));
+
+ Bag<Object> bag = new HashBag<Object>();
+ assertTrue(CollectionTools.emptyBag().equals(bag));
+ bag.add("foo");
+ assertFalse(CollectionTools.emptyBag().equals(bag));
+ }
+
+ public void testEmptyBag_hashCode() throws Exception {
+ assertEquals(0, CollectionTools.emptyBag().hashCode());
+ }
+
+ public void testEmptyBag_serialization() throws Exception {
+ Bag<?> xxx = TestTools.serialize(CollectionTools.emptyBag());
+ assertSame(CollectionTools.emptyBag(), xxx);
+ }
+
+}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/HashBagTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/HashBagTests.java
index a03d98e267..a17bfa72b0 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/HashBagTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/HashBagTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,379 +9,37 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.collection;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import junit.framework.TestCase;
-
import org.eclipse.jpt.common.utility.collection.Bag;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.SystemTools;
import org.eclipse.jpt.common.utility.internal.collection.HashBag;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
@SuppressWarnings("nls")
-public class HashBagTests extends TestCase {
- private HashBag<String> bag;
-
+public class HashBagTests
+ extends BagTests
+{
public HashBagTests(String name) {
super(name);
}
@Override
- protected void setUp() throws Exception {
- super.setUp();
- this.bag = this.buildBag();
- }
-
- private HashBag<String> buildBag() {
- HashBag<String> b = new HashBag<String>();
- b.add(null);
- b.add(new String("one"));
- b.add(new String("two"));
- b.add(new String("two"));
- b.add(new String("three"));
- b.add(new String("three"));
- b.add(new String("three"));
- b.add(new String("four"));
- b.add(new String("four"));
- b.add(new String("four"));
- b.add(new String("four"));
- return b;
+ protected Bag<String> buildBag_() {
+ return new HashBag<String>();
}
@Override
- protected void tearDown() throws Exception {
- TestTools.clear(this);
- super.tearDown();
- }
-
- private Collection<String> buildCollection() {
- Collection<String> c = new ArrayList<String>();
- c.add(new String("foo"));
- c.add(new String("foo"));
- c.add(new String("bar"));
- c.add(new String("bar"));
- c.add(new String("bar"));
- return c;
- }
-
- public void testCtorCollection() {
- Collection<String> c = this.buildCollection();
- Bag<String> b = new HashBag<String>(c);
- for (String s : c) {
- assertTrue(b.contains(s));
- }
- }
-
- public void testCtorIntFloat() {
- boolean exCaught;
-
- exCaught = false;
- try {
- this.bag = new HashBag<String>(-20, 0.66f);
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- exCaught = false;
- try {
- this.bag = new HashBag<String>(20, -0.66f);
- } catch (IllegalArgumentException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
- public void testAdd() {
- // the other adds took place in setUp
- assertTrue(this.bag.add("five"));
-
- assertTrue(this.bag.contains("one"));
- assertTrue(this.bag.contains("two"));
- assertTrue(this.bag.contains("three"));
- assertTrue(this.bag.contains("four"));
- assertTrue(this.bag.contains("five"));
- }
-
- public void testAddCount() {
- // the other adds took place in setUp
- this.bag.add("minus3", -3);
- this.bag.add("zero", 0);
- this.bag.add("five", 5);
-
- assertFalse(this.bag.contains("minus3"));
- assertFalse(this.bag.contains("zero"));
- assertEquals(1, this.bag.count("one"));
- assertEquals(2, this.bag.count("two"));
- assertEquals(3, this.bag.count("three"));
- assertEquals(4, this.bag.count("four"));
- assertEquals(5, this.bag.count("five"));
-
- this.bag.add("three", 2);
- assertEquals(5, this.bag.count("three"));
- }
-
- public void testAddAll() {
- Collection<String> c = this.buildCollection();
- assertTrue(this.bag.addAll(c));
- for (String s : c) {
- assertTrue(this.bag.contains(s));
- }
- }
-
- public void testClear() {
- assertTrue(this.bag.contains("one"));
- assertTrue(this.bag.contains("two"));
- assertTrue(this.bag.contains("three"));
- assertTrue(this.bag.contains("four"));
- assertTrue(this.bag.contains(null));
- assertEquals(11, this.bag.size());
- this.bag.clear();
- assertFalse(this.bag.contains("one"));
- assertFalse(this.bag.contains("two"));
- assertFalse(this.bag.contains("three"));
- assertFalse(this.bag.contains("four"));
- assertFalse(this.bag.contains(null));
- assertEquals(0, this.bag.size());
- }
-
- public void testClone() {
- Bag<String> bag2 = this.bag.clone();
- assertTrue(this.bag != bag2);
- assertEquals(this.bag, bag2);
- assertTrue(this.bag.hashCode() == bag2.hashCode());
- }
-
- public void testContains() {
- assertTrue(this.bag.contains(null));
- assertTrue(this.bag.contains("one"));
- assertTrue(this.bag.contains("two"));
- assertTrue(this.bag.contains("three"));
- assertTrue(this.bag.contains("four"));
- assertTrue(this.bag.contains(new String("four")));
- assertTrue(this.bag.contains("fo" + "ur"));
- assertFalse(this.bag.contains("five"));
- }
-
- public void testContainsAll() {
- Collection<String> c = new ArrayList<String>();
- c.add(null);
- c.add(new String("one"));
- c.add(new String("two"));
- c.add(new String("three"));
- c.add(new String("four"));
- assertTrue(this.bag.containsAll(c));
- }
-
- public void testCount() {
- assertEquals(0, this.bag.count("zero"));
- assertEquals(1, this.bag.count("one"));
- assertEquals(2, this.bag.count("two"));
- assertEquals(3, this.bag.count("three"));
- assertEquals(4, this.bag.count("four"));
- assertEquals(0, this.bag.count("five"));
- }
-
- public void testEquals() {
- Bag<String> bag2 = this.buildBag();
- assertEquals(this.bag, bag2);
- bag2.add("five");
- assertFalse(this.bag.equals(bag2));
- Collection<String> c = new ArrayList<String>(this.bag);
- assertFalse(this.bag.equals(c));
- }
-
- public void testHashCode() {
- Bag<String> bag2 = this.buildBag();
- assertEquals(this.bag.hashCode(), bag2.hashCode());
- }
-
- public void testIsEmpty() {
- assertFalse(this.bag.isEmpty());
- this.bag.clear();
- assertTrue(this.bag.isEmpty());
- this.bag.add("foo");
- assertFalse(this.bag.isEmpty());
- }
-
- public void testEmptyIterator() {
- this.bag.clear();
- Iterator<String> iterator = this.bag.iterator();
- assertFalse(iterator.hasNext());
-
- boolean exCaught = false;
- Object element = null;
- try {
- element = iterator.next();
- fail(element.toString());
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- exCaught = false;
- try {
- iterator.remove();
- } catch (IllegalStateException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
- public void testIterator() {
- int i = 0;
- Iterator<String> iterator = this.bag.iterator();
- assertTrue(iterator.hasNext());
- while (iterator.hasNext()) {
- iterator.next();
- i++;
- }
- assertEquals(11, i);
- assertFalse(iterator.hasNext());
-
- boolean exCaught = false;
- Object element = null;
- try {
- element = iterator.next();
- fail(element.toString());
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- iterator.remove();
- assertEquals(10, this.bag.size());
-
- exCaught = false;
- try {
- iterator.remove();
- } catch (IllegalStateException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- // start over
- iterator = this.bag.iterator();
- this.bag.add("five");
- exCaught = false;
- try {
- iterator.next();
- } catch (ConcurrentModificationException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
- }
-
- public void testUniqueIterator() {
- int i = 0;
- Iterator<String> iterator = this.bag.uniqueIterator();
- assertTrue(iterator.hasNext());
- while (iterator.hasNext()) {
- iterator.next();
- i++;
- }
- assertEquals(5, i);
- assertFalse(iterator.hasNext());
-
- boolean exCaught = false;
- Object element = null;
- try {
- element = iterator.next();
- fail(element.toString());
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- // start over
- iterator = this.bag.uniqueIterator();
- Object next = null;
- while (iterator.hasNext() && !"four".equals(next)) {
- next = iterator.next();
- }
- iterator.remove();
- assertEquals(7, this.bag.size());
-
- exCaught = false;
- try {
- iterator.remove();
- } catch (IllegalStateException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- // start over
- iterator = this.bag.uniqueIterator();
- this.bag.add("five");
- exCaught = false;
- try {
- iterator.next();
- } catch (ConcurrentModificationException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ protected Bag<String> buildBag(Collection<String> c) {
+ return new HashBag<String>(c);
}
- public void testEntries() {
- int i = 0;
- Iterator<Bag.Entry<String>> iterator = this.bag.entries();
- assertTrue(iterator.hasNext());
- while (iterator.hasNext()) {
- iterator.next();
- i++;
- }
- assertEquals(5, i);
- assertFalse(iterator.hasNext());
-
- boolean exCaught = false;
- Object element = null;
- try {
- element = iterator.next();
- fail(element.toString());
- } catch (NoSuchElementException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- // start over
- iterator = this.bag.entries();
- Bag.Entry<String> next = null;
- while (iterator.hasNext()) {
- next = iterator.next();
- if (next.getElement().equals("four")) {
- iterator.remove();
- break;
- }
- }
- assertEquals(7, this.bag.size());
-
- exCaught = false;
- try {
- iterator.remove();
- } catch (IllegalStateException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
-
- // start over
- iterator = this.bag.entries();
- this.bag.add("five");
- exCaught = false;
- try {
- iterator.next();
- } catch (ConcurrentModificationException ex) {
- exCaught = true;
- }
- assertTrue(exCaught);
+ @Override
+ protected Bag<String> buildBag(int initialCapacity, float loadFactor) {
+ return new HashBag<String>(initialCapacity, loadFactor);
}
public void testHashingDistribution() throws Exception {
- Bag<String> bigBag = new HashBag<String>();
+ Bag<String> bigBag = this.buildBag();
for (int i = 0; i < 10000; i++) {
bigBag.add("object" + i);
}
@@ -408,149 +66,4 @@ public class HashBagTests extends TestCase {
}
}
}
-
- public void testRemove() {
- assertTrue(this.bag.remove("one"));
- assertFalse(this.bag.contains("one"));
- assertFalse(this.bag.remove("one"));
-
- assertTrue(this.bag.remove("two"));
- assertTrue(this.bag.remove("two"));
- assertFalse(this.bag.contains("two"));
- assertFalse(this.bag.remove("two"));
- }
-
- public void testRemoveCount() {
- assertFalse(this.bag.remove("one", 0));
- assertTrue(this.bag.contains("one"));
-
- assertTrue(this.bag.remove("one", 1));
- assertFalse(this.bag.contains("one"));
- assertFalse(this.bag.remove("one"));
-
- assertFalse(this.bag.remove("two", -3));
- assertTrue(this.bag.remove("two", 1));
- assertTrue(this.bag.contains("two"));
-
- assertTrue(this.bag.remove("two", 1));
- assertFalse(this.bag.contains("two"));
- assertFalse(this.bag.remove("two"));
-
- assertTrue(this.bag.remove("three", 3));
- assertFalse(this.bag.contains("three"));
- assertFalse(this.bag.remove("three"));
- }
-
- public void testRemoveAll() {
- Collection<String> c = new ArrayList<String>();
- c.add("one");
- c.add("three");
- assertTrue(this.bag.removeAll(c));
- assertFalse(this.bag.contains("one"));
- assertFalse(this.bag.contains("three"));
- assertFalse(this.bag.remove("one"));
- assertFalse(this.bag.remove("three"));
- assertFalse(this.bag.removeAll(c));
- }
-
- public void testRetainAll() {
- Collection<String> c = new ArrayList<String>();
- c.add("one");
- c.add("three");
- assertTrue(this.bag.retainAll(c));
- assertTrue(this.bag.contains("one"));
- assertTrue(this.bag.contains("three"));
- assertFalse(this.bag.contains("two"));
- assertFalse(this.bag.contains("four"));
- assertFalse(this.bag.remove("two"));
- assertFalse(this.bag.remove("four"));
- assertFalse(this.bag.retainAll(c));
- }
-
- public void testSize() {
- assertTrue(this.bag.size() == 11);
- this.bag.add("five");
- this.bag.add("five");
- this.bag.add("five");
- this.bag.add("five");
- this.bag.add("five");
- assertEquals(16, this.bag.size());
- }
-
- public void testSerialization() throws Exception {
- Bag<String> bag2 = TestTools.serialize(this.bag);
-
- assertTrue("same object?", this.bag != bag2);
- assertEquals(11, bag2.size());
- assertEquals(this.bag, bag2);
- // look for similar elements
- assertTrue(bag2.contains(null));
- assertTrue(bag2.contains("one"));
- assertTrue(bag2.contains("two"));
- assertTrue(bag2.contains("three"));
- assertTrue(bag2.contains("four"));
-
- int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
- for (String s : bag2) {
- if (s == null) {
- nullCount++;
- } else if (s.equals("one")) {
- oneCount++;
- } else if (s.equals("two")) {
- twoCount++;
- } else if (s.equals("three")) {
- threeCount++;
- } else if (s.equals("four")) {
- fourCount++;
- }
- }
- assertEquals(1, nullCount);
- assertEquals(1, oneCount);
- assertEquals(2, twoCount);
- assertEquals(3, threeCount);
- assertEquals(4, fourCount);
- }
-
- public void testToArray() {
- Object[] a = this.bag.toArray();
- assertEquals(11, a.length);
- assertTrue(ArrayTools.contains(a, null));
- assertTrue(ArrayTools.contains(a, "one"));
- assertTrue(ArrayTools.contains(a, "two"));
- assertTrue(ArrayTools.contains(a, "three"));
- assertTrue(ArrayTools.contains(a, "four"));
- }
-
- public void testToArrayObjectArray() {
- String[] a = new String[12];
- a[11] = "not null";
- String[] b = this.bag.toArray(a);
- assertEquals(a, b);
- assertEquals(12, a.length);
- assertTrue(ArrayTools.contains(a, null));
- assertTrue(ArrayTools.contains(a, "one"));
- assertTrue(ArrayTools.contains(a, "two"));
- assertTrue(ArrayTools.contains(a, "three"));
- assertTrue(ArrayTools.contains(a, "four"));
- assertTrue(a[11] == null);
- }
-
- public void testToString() {
- String s = this.bag.toString();
- assertTrue(s.startsWith("["));
- assertTrue(s.endsWith("]"));
- int commaCount = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s.charAt(i) == ',') {
- commaCount++;
- }
- }
- assertEquals(10, commaCount);
- assertTrue(s.indexOf("one") != -1);
- assertTrue(s.indexOf("two") != -1);
- assertTrue(s.indexOf("three") != -1);
- assertTrue(s.indexOf("four") != -1);
- assertTrue(s.indexOf("null") != -1);
- }
-
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashBagTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashBagTests.java
index 23aa0f14d5..1fb037c1e4 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashBagTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashBagTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -14,17 +14,19 @@ import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.NoSuchElementException;
-
-import junit.framework.TestCase;
-
+import org.eclipse.jpt.common.utility.collection.Bag;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.SystemTools;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
import org.eclipse.jpt.common.utility.internal.collection.IdentityHashBag;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
@SuppressWarnings("nls")
-public class IdentityHashBagTests extends TestCase {
+public class IdentityHashBagTests
+ extends TestCase
+{
private IdentityHashBag<String> bag;
private String one = "one";
private String two = "two";
@@ -44,19 +46,23 @@ public class IdentityHashBagTests extends TestCase {
}
protected IdentityHashBag<String> buildBag() {
- IdentityHashBag<String> result = new IdentityHashBag<String>();
- result.add(null);
- result.add(this.one);
- result.add(this.two);
- result.add(this.two);
- result.add(this.three);
- result.add(this.three);
- result.add(this.three);
- result.add(this.four);
- result.add(this.four);
- result.add(this.four);
- result.add(this.four);
- return result;
+ return CollectionTools.identityHashBag(this.buildBagContents());
+ }
+
+ protected Collection<String> buildBagContents() {
+ ArrayList<String> c = new ArrayList<String>();
+ c.add(null);
+ c.add(this.one);
+ c.add(this.two);
+ c.add(this.two);
+ c.add(this.three);
+ c.add(this.three);
+ c.add(this.three);
+ c.add(this.four);
+ c.add(this.four);
+ c.add(this.four);
+ c.add(this.four);
+ return c;
}
@Override
@@ -199,17 +205,32 @@ public class IdentityHashBagTests extends TestCase {
assertEquals(0, this.bag.count("five"));
}
- public void testEquals() {
- IdentityHashBag<String> bag2 = this.buildBag();
+ public void testEqualsObject() {
+ assertEquals(this.bag, this.bag);
+ IdentityHashBag<String> bag2 = CollectionTools.identityHashBag(this.buildBagContents(), 20);
assertEquals(this.bag, bag2);
- bag2.add("five");
- assertFalse(this.bag.equals(bag2));
+
+ bag2.add(this.four);
+ assertFalse(this.bag.equals(bag2)); // same unique counts; different sizes
+ bag2.remove(this.four);
+
+ String five = "five";
+ bag2.add(five);
+ bag2.remove(this.four);
+ assertFalse(this.bag.equals(bag2)); // same sizes; different unique counts
+ bag2.remove(five);
+ bag2.add(this.four);
+
+ bag2.remove(this.two);
+ bag2.add(this.four);
+ assertFalse(this.bag.equals(bag2)); // same sizes; same unique counts
+
Collection<String> c = new ArrayList<String>(this.bag);
assertFalse(this.bag.equals(c));
}
public void testHashCode() {
- IdentityHashBag<String> bag2 = this.buildBag();
+ IdentityHashBag<String> bag2 = CollectionTools.identityHashBag(this.buildBagContents().toArray(StringTools.EMPTY_STRING_ARRAY));
assertEquals(this.bag.hashCode(), bag2.hashCode());
}
@@ -287,6 +308,30 @@ public class IdentityHashBagTests extends TestCase {
assertTrue("ConcurrentModificationException not thrown", exCaught);
}
+ public void testEmptyUniqueIterator() {
+ this.bag.clear();
+ Iterator<String> iterator = this.bag.uniqueIterator();
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testUniqueIterator() {
int i = 0;
Iterator<String> iterator = this.bag.uniqueIterator();
@@ -338,6 +383,30 @@ public class IdentityHashBagTests extends TestCase {
assertTrue(exCaught);
}
+ public void testEmptyEntries() {
+ this.bag.clear();
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertFalse(iterator.hasNext());
+
+ boolean exCaught = false;
+ Object element = null;
+ try {
+ element = iterator.next();
+ fail(element.toString());
+ } catch (NoSuchElementException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+
+ exCaught = false;
+ try {
+ iterator.remove();
+ } catch (IllegalStateException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testEntries() {
int i = 0;
Iterator<org.eclipse.jpt.common.utility.collection.Bag.Entry<String>> iterator = this.bag.entries();
@@ -392,6 +461,25 @@ public class IdentityHashBagTests extends TestCase {
assertTrue(exCaught);
}
+ public void testEntries_remove_CME() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertTrue(iterator.hasNext());
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ this.bag.remove(this.two);
+ iterator.remove();
+ }
+ }
+ } catch (ConcurrentModificationException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
public void testHashingDistribution() throws Exception {
IdentityHashBag<String> bigBag = new IdentityHashBag<String>();
for (int i = 0; i < 10000; i++) {
@@ -501,13 +589,13 @@ public class IdentityHashBagTests extends TestCase {
assertTrue("same object?", this.bag != bag2);
assertEquals(11, bag2.size());
- assertEquals(CollectionTools.bag(this.bag.iterator()), CollectionTools.bag(bag2.iterator()));
+ assertEquals(CollectionTools.hashBag(this.bag.iterator()), CollectionTools.hashBag(bag2.iterator()));
// look for similar elements
- assertTrue(CollectionTools.bag(bag2.iterator()).contains(null));
- assertTrue(CollectionTools.bag(bag2.iterator()).contains("one"));
- assertTrue(CollectionTools.bag(bag2.iterator()).contains("two"));
- assertTrue(CollectionTools.bag(bag2.iterator()).contains("three"));
- assertTrue(CollectionTools.bag(bag2.iterator()).contains("four"));
+ assertTrue(CollectionTools.hashBag(bag2.iterator()).contains(null));
+ assertTrue(CollectionTools.hashBag(bag2.iterator()).contains("one"));
+ assertTrue(CollectionTools.hashBag(bag2.iterator()).contains("two"));
+ assertTrue(CollectionTools.hashBag(bag2.iterator()).contains("three"));
+ assertTrue(CollectionTools.hashBag(bag2.iterator()).contains("four"));
int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
for (String next : bag2) {
@@ -528,6 +616,15 @@ public class IdentityHashBagTests extends TestCase {
assertEquals(3, threeCount);
assertEquals(4, fourCount);
}
+
+ public void testSerialization_empty() throws Exception {
+ this.bag.clear();
+ Bag<String> bag2 = TestTools.serialize(this.bag);
+
+ assertTrue("same object?", this.bag != bag2);
+ assertEquals(0, bag2.size());
+ assertEquals(this.bag, bag2);
+ }
public void testToArray() {
Object[] a = this.bag.toArray();
@@ -571,4 +668,169 @@ public class IdentityHashBagTests extends TestCase {
assertTrue(s.indexOf("null") != -1);
}
+ public void testEntry_setCount_increase() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count(this.four));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ assertEquals(4, next.setCount(42));
+ break;
+ }
+ }
+ assertEquals(42, this.bag.count(this.four));
+ assertEquals(49, this.bag.size());
+ }
+
+ public void testEntry_setCount_same() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count(this.four));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ assertEquals(4, next.setCount(4));
+ break;
+ }
+ }
+ assertEquals(4, this.bag.count(this.four));
+ assertEquals(11, this.bag.size());
+ }
+
+ public void testEntry_setCount_derease() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ assertEquals(4, this.bag.count(this.four));
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ assertEquals(4, next.setCount(2));
+ break;
+ }
+ }
+ assertEquals(2, this.bag.count(this.four));
+ assertEquals(9, this.bag.size());
+ }
+
+ public void testEntry_setCount_IAE1() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ next.setCount(0);
+ fail(next.toString());
+ }
+ }
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ public void testEntry_setCount_IAE2() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ boolean exCaught = false;
+ try {
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ next.setCount(-33);
+ fail(next.toString());
+ }
+ }
+ } catch (IllegalArgumentException ex) {
+ exCaught = true;
+ }
+ assertTrue(exCaught);
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_equalsObject() {
+ Iterator<Bag.Entry<String>> iterator1 = this.bag.entries();
+ Bag<String> bag2 = this.buildBag();
+ Bag.Entry<String> next1 = null;
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ assertFalse(next1.equals(this.four));
+ Iterator<Bag.Entry<String>> iterator2 = bag2.entries();
+ Bag.Entry<String> next2 = null;
+ while (iterator2.hasNext()) {
+ next2 = iterator2.next();
+ if (next2.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ assertEquals(next1, next2);
+
+ bag2.remove(this.four);
+ iterator1 = this.bag.entries();
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ iterator2 = bag2.entries();
+ while (iterator2.hasNext()) {
+ next2 = iterator2.next();
+ if (next2.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ assertEquals(next1.getElement(), next2.getElement());
+ assertFalse(next1.equals(next2));
+
+ iterator1 = this.bag.entries();
+ while (iterator1.hasNext()) {
+ next1 = iterator1.next();
+ if (next1.getElement().equals(this.three)) {
+ break;
+ }
+ }
+ assertEquals(next1.getCount(), next2.getCount());
+ assertFalse(next1.equals(next2));
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_hashCode() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ assertEquals(4 * this.four.hashCode(), next.hashCode());
+
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement() == null) {
+ break;
+ }
+ }
+ assertEquals(0, next.hashCode());
+ }
+
+ @SuppressWarnings("null")
+ public void testEntry_toString() {
+ Iterator<Bag.Entry<String>> iterator = this.bag.entries();
+ Bag.Entry<String> next = null;
+ while (iterator.hasNext()) {
+ next = iterator.next();
+ if (next.getElement().equals(this.four)) {
+ break;
+ }
+ }
+ assertEquals("four=>4", next.toString());
+ }
}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashSetTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashSetTests.java
index 5dab6f4350..670246921f 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashSetTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/IdentityHashSetTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Oracle. All rights reserved.
+ * Copyright (c) 2013, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -12,13 +12,14 @@ package org.eclipse.jpt.common.utility.tests.internal.collection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.ArrayTools;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
import org.eclipse.jpt.common.utility.internal.collection.IdentityHashSet;
import org.eclipse.jpt.common.utility.tests.internal.TestTools;
+import junit.framework.TestCase;
@SuppressWarnings("nls")
public class IdentityHashSetTests
@@ -83,8 +84,10 @@ public class IdentityHashSetTests
}
public void testCtorInt() {
- boolean exCaught;
+ this.set = new IdentityHashSet<String>(20);
+ assertNotNull(this.set);
+ boolean exCaught;
exCaught = false;
try {
this.set = new IdentityHashSet<String>(-20);
@@ -161,6 +164,7 @@ public class IdentityHashSetTests
}
public void testEquals() {
+ assertEquals(this.set, this.set);
IdentityHashSet<String> set2 = this.buildSet();
assertEquals(this.set, set2);
set2.add("five");
@@ -169,6 +173,13 @@ public class IdentityHashSetTests
assertFalse(this.set.equals(c));
}
+ public void testEquals_set() {
+ HashSet<String> set2 = new HashSet<String>(this.set);
+ assertEquals(this.set, set2);
+ set2.add("five");
+ assertFalse(this.set.equals(set2));
+ }
+
public void testHashCode() {
IdentityHashSet<String> set2 = this.buildSet();
assertEquals(this.set.hashCode(), set2.hashCode());
@@ -291,6 +302,21 @@ public class IdentityHashSetTests
assertFalse(this.set.retainAll(c));
}
+ public void testRetainAll_IHS() {
+ Collection<String> c = new IdentityHashSet<String>();
+ c.add(this.one);
+ c.add(new String(this.two));
+ c.add(this.three);
+ assertTrue(this.set.retainAll(c));
+ assertTrue(this.set.contains(this.one));
+ assertFalse(this.set.contains(this.two));
+ assertTrue(this.set.contains(this.three));
+ assertFalse(this.set.contains(this.four));
+ assertFalse(this.set.remove(this.two));
+ assertFalse(this.set.remove(this.four));
+ assertFalse(this.set.retainAll(c));
+ }
+
public void testSize() {
assertEquals(5, this.set.size());
String five = "five";
@@ -307,13 +333,13 @@ public class IdentityHashSetTests
assertTrue("same object?", this.set != set2);
assertEquals(5, set2.size());
- assertEquals(CollectionTools.set(this.set.iterator()), CollectionTools.set(set2.iterator()));
+ assertEquals(CollectionTools.hashSet(this.set.iterator()), CollectionTools.hashSet(set2.iterator()));
// look for similar elements
- assertTrue(CollectionTools.set(set2.iterator()).contains(null));
- assertTrue(CollectionTools.set(set2.iterator()).contains("one"));
- assertTrue(CollectionTools.set(set2.iterator()).contains("two"));
- assertTrue(CollectionTools.set(set2.iterator()).contains("three"));
- assertTrue(CollectionTools.set(set2.iterator()).contains("four"));
+ assertTrue(CollectionTools.hashSet(set2.iterator()).contains(null));
+ assertTrue(CollectionTools.hashSet(set2.iterator()).contains("one"));
+ assertTrue(CollectionTools.hashSet(set2.iterator()).contains("two"));
+ assertTrue(CollectionTools.hashSet(set2.iterator()).contains("three"));
+ assertTrue(CollectionTools.hashSet(set2.iterator()).contains("four"));
int nullCount = 0, oneCount = 0, twoCount = 0, threeCount = 0, fourCount = 0;
for (String next : set2) {
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
index 67a7c49947..77363e4645 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/JptCommonUtilityCollectionTests.java
@@ -20,25 +20,17 @@ public class JptCommonUtilityCollectionTests {
public static Test suite() {
TestSuite suite = new TestSuite(JptCommonUtilityCollectionTests.class.getPackage().getName());
- suite.addTestSuite(ArrayQueueTests.class);
- suite.addTestSuite(ArrayStackTests.class);
- suite.addTestSuite(BagTests.class);
suite.addTestSuite(CollectionToolsTests.class);
- suite.addTestSuite(FixedSizeArrayQueueTests.class);
- suite.addTestSuite(FixedSizeArrayStackTests.class);
+ suite.addTestSuite(EmptyBagTests.class);
suite.addTestSuite(HashBagTests.class);
suite.addTestSuite(IdentityHashBagTests.class);
suite.addTestSuite(IdentityHashSetTests.class);
- suite.addTestSuite(LinkedQueueTests.class);
- suite.addTestSuite(LinkedStackTests.class);
- suite.addTestSuite(ListQueueTests.class);
- suite.addTestSuite(ListStackTests.class);
suite.addTestSuite(ListToolsTests.class);
suite.addTestSuite(MapToolsTests.class);
suite.addTestSuite(NullElementListTests.class);
+ suite.addTestSuite(NullListTests.class);
suite.addTestSuite(RepeatingElementListTests.class);
- suite.addTestSuite(SynchronizedQueueTests.class);
- suite.addTestSuite(SynchronizedStackTests.class);
+ suite.addTestSuite(SynchronizedBagTests.class);
suite.addTestSuite(TightMapTests.class);
return suite;
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedQueueTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedQueueTests.java
deleted file mode 100644
index 31ec036f8b..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedQueueTests.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2015 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.collection;
-
-import java.util.Arrays;
-import org.eclipse.jpt.common.utility.collection.Queue;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.collection.LinkedQueue;
-
-@SuppressWarnings("nls")
-public class LinkedQueueTests
- extends QueueTests
-{
- public LinkedQueueTests(String name) {
- super(name);
- }
-
- @Override
- Queue<String> buildQueue() {
- return new LinkedQueue<String>();
- }
-
- public void testSize() {
- Queue<String> queue = this.buildQueue();
- String first = "first";
- String second = "second";
- String third = "third";
-
- assertEquals(0, ((Integer) ObjectTools.execute(queue, "size")).intValue());
- queue.enqueue(first);
- queue.enqueue(second);
- assertEquals(2, ((Integer) ObjectTools.execute(queue, "size")).intValue());
- queue.enqueue(third);
- assertEquals(3, ((Integer) ObjectTools.execute(queue, "size")).intValue());
- queue.dequeue();
- assertEquals(2, ((Integer) ObjectTools.execute(queue, "size")).intValue());
- queue.dequeue();
- queue.dequeue();
- assertEquals(0, ((Integer) ObjectTools.execute(queue, "size")).intValue());
- }
-
- public void testBuildElements() {
- Queue<String> queue = this.buildQueue();
- String first = "first";
- String second = "second";
- String third = "third";
- queue.enqueue(first);
- queue.enqueue(second);
- queue.enqueue(third);
-
- Object[] elements = new Object[] { first, second, third };
- assertTrue(Arrays.equals(elements, ((Object[]) ObjectTools.execute(queue, "buildElements"))));
- }
-
- public void testNodeCache() {
- Queue<String> queue = new LinkedQueue<String>(2);
- String first = "first";
- String second = "second";
- String third = "third";
- String fourth = "fourth";
- String fifth = "fifth";
-
- Object factory = ObjectTools.get(queue, "nodeFactory");
-
- this.verifyNodeCache(0, factory);
- queue.enqueue(first);
- this.verifyNodeCache(0, factory);
- queue.enqueue(second);
- queue.enqueue(third);
- queue.enqueue(fourth);
- queue.enqueue(fifth);
- this.verifyNodeCache(0, factory);
- assertNull(ObjectTools.get(factory, "cacheHead"));
-
- queue.dequeue();
- this.verifyNodeCache(1, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.dequeue();
- this.verifyNodeCache(2, factory);
- queue.enqueue(first);
- this.verifyNodeCache(1, factory);
- queue.enqueue(second);
- this.verifyNodeCache(0, factory);
- queue.enqueue(third);
- this.verifyNodeCache(0, factory);
- }
-
- public void verifyNodeCache(int size, Object factory) {
- assertEquals(size, ((Integer) ObjectTools.get(factory, "cacheSize")).intValue());
- int nodeCount = 0;
- for (Object node = ObjectTools.get(factory, "cacheHead"); node != null; node = ObjectTools.get(node, "next")) {
- nodeCount++;
- }
- assertEquals(size, nodeCount);
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedStackTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedStackTests.java
deleted file mode 100644
index b1dd06d91e..0000000000
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/LinkedStackTests.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2012, 2015 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0, which accompanies this distribution
- * and is available at http://www.eclipse.org/legal/epl-v10.html.
- *
- * Contributors:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.utility.tests.internal.collection;
-
-import java.util.Arrays;
-import org.eclipse.jpt.common.utility.collection.Stack;
-import org.eclipse.jpt.common.utility.internal.ObjectTools;
-import org.eclipse.jpt.common.utility.internal.collection.LinkedStack;
-
-@SuppressWarnings("nls")
-public class LinkedStackTests
- extends StackTests
-{
- public LinkedStackTests(String name) {
- super(name);
- }
-
- @Override
- Stack<String> buildStack() {
- return new LinkedStack<String>();
- }
-
- public void testSize() {
- Stack<String> stack = this.buildStack();
- String first = "first";
- String second = "second";
- String third = "third";
-
- assertEquals(0, ((Integer) ObjectTools.execute(stack, "size")).intValue());
- stack.push(first);
- stack.push(second);
- assertEquals(2, ((Integer) ObjectTools.execute(stack, "size")).intValue());
- stack.push(third);
- assertEquals(3, ((Integer) ObjectTools.execute(stack, "size")).intValue());
- stack.pop();
- assertEquals(2, ((Integer) ObjectTools.execute(stack, "size")).intValue());
- stack.pop();
- stack.pop();
- assertEquals(0, ((Integer) ObjectTools.execute(stack, "size")).intValue());
- }
-
- public void testBuildElements() {
- Stack<String> stack = this.buildStack();
- String first = "first";
- String second = "second";
- String third = "third";
- stack.push(first);
- stack.push(second);
- stack.push(third);
-
- Object[] elements = new Object[] { third, second, first };
- assertTrue(Arrays.equals(elements, ((Object[]) ObjectTools.execute(stack, "buildElements"))));
- }
-
- public void testNodeCache() {
- Stack<String> stack = new LinkedStack<String>(2);
- String first = "first";
- String second = "second";
- String third = "third";
- String fourth = "fourth";
- String fifth = "fifth";
-
- Object factory = ObjectTools.get(stack, "nodeFactory");
-
- this.verifyNodeCache(0, factory);
- stack.push(first);
- this.verifyNodeCache(0, factory);
- stack.push(second);
- stack.push(third);
- stack.push(fourth);
- stack.push(fifth);
- this.verifyNodeCache(0, factory);
- assertNull(ObjectTools.get(factory, "cacheHead"));
-
- stack.pop();
- this.verifyNodeCache(1, factory);
- stack.pop();
- this.verifyNodeCache(2, factory);
- stack.pop();
- this.verifyNodeCache(2, factory);
- stack.pop();
- this.verifyNodeCache(2, factory);
- stack.pop();
- this.verifyNodeCache(2, factory);
- stack.push(first);
- this.verifyNodeCache(1, factory);
- stack.push(second);
- this.verifyNodeCache(0, factory);
- stack.push(third);
- this.verifyNodeCache(0, factory);
- }
-
- public void verifyNodeCache(int size, Object factory) {
- assertEquals(size, ((Integer) ObjectTools.get(factory, "cacheSize")).intValue());
- int nodeCount = 0;
- for (Object node = ObjectTools.get(factory, "cacheHead"); node != null; node = ObjectTools.get(node, "next")) {
- nodeCount++;
- }
- assertEquals(size, nodeCount);
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListToolsTests.java
index d8045a0545..7dd8f7d10f 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/collection/ListToolsTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 Oracle. All rights reserved.
+ * Copyright (c) 2005, 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -18,11 +18,11 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.ListIterator;
import java.util.Random;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
-import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.ClassTools;
import org.eclipse.jpt.common.utility.internal.Range;
import org.eclipse.jpt.common.utility.internal.collection.CollectionTools;
@@ -31,7 +31,10 @@ import org.eclipse.jpt.common.utility.internal.comparator.ComparatorTools;
import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterator.EmptyIterator;
import org.eclipse.jpt.common.utility.internal.predicate.PredicateTools;
+import org.eclipse.jpt.common.utility.iterable.ListIterable;
import org.eclipse.jpt.common.utility.tests.internal.ArrayToolsTests;
+import org.eclipse.jpt.common.utility.transformer.Transformer;
+import junit.framework.TestCase;
@SuppressWarnings("nls")
public class ListToolsTests
@@ -40,6 +43,9 @@ public class ListToolsTests
public ListToolsTests(String name) {
super(name);
}
+
+ // ********** add all **********
+
public void testAddAllListIntObjectArray() {
List<String> list = this.buildStringList1();
ListTools.addAll(list, 2, new String[] { "X", "X", "X" });
@@ -171,7 +177,7 @@ public class ListToolsTests
// ********** diff **********
- public void testIndexOfDifference() {
+ public void testIndexOfDifference_none() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -183,7 +189,67 @@ public class ListToolsTests
assertEquals(3, ListTools.indexOfDifference(list1, list2));
}
- public void testLastIndexOfDifference() {
+ public void testIndexOfDifference_none_null() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add(null);
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(null);
+ list2.add(new String("c"));
+ assertEquals(3, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testIndexOfDifference_first() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("b"));
+ list2.add(new String("c"));
+ assertEquals(0, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testIndexOfDifference_middle() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("X"));
+ list2.add(new String("c"));
+ assertEquals(1, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testIndexOfDifference_middle_null() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add(null);
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("X"));
+ list2.add(new String("c"));
+ assertEquals(1, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testIndexOfDifference_last() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("b"));
+ list2.add(new String("X"));
+ assertEquals(2, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testIndexOfDifference_last_size() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -191,11 +257,105 @@ public class ListToolsTests
List<String> list2 = new ArrayList<String>();
list2.add(new String("a"));
list2.add(new String("b"));
+ assertEquals(2, ListTools.indexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_none() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("b"));
+ list2.add(new String("c"));
+ assertEquals(-1, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_none_null() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add(null);
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(null);
list2.add(new String("c"));
assertEquals(-1, ListTools.lastIndexOfDifference(list1, list2));
}
- public void testDifferenceRange() {
+ public void testLastIndexOfDifference_first() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("b"));
+ list2.add(new String("X"));
+ assertEquals(2, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_first_size() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("b"));
+ assertEquals(2, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_middle() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("X"));
+ list2.add(new String("c"));
+ assertEquals(1, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_middle_null1() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add(null);
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(new String("b"));
+ list2.add(new String("c"));
+ assertEquals(1, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_middle_null2() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add(null);
+ list2.add(new String("c"));
+ assertEquals(1, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testLastIndexOfDifference_last() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("b"));
+ list2.add(new String("c"));
+ assertEquals(0, ListTools.lastIndexOfDifference(list1, list2));
+ }
+
+ public void testDifferenceRange_none() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -207,6 +367,42 @@ public class ListToolsTests
assertNull(ListTools.differenceRange(list1, list2));
}
+ public void testDifferenceRange_single() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("b"));
+ list2.add(new String("c"));
+ assertEquals(new Range(0, 0), ListTools.differenceRange(list1, list2));
+ }
+
+ public void testDifferenceRange_some() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("Y"));
+ list2.add(new String("c"));
+ assertEquals(new Range(0, 1), ListTools.differenceRange(list1, list2));
+ }
+
+ public void testDifferenceRange_all() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("Y"));
+ list2.add(new String("Z"));
+ assertEquals(new Range(0, 2), ListTools.differenceRange(list1, list2));
+ }
+
// ********** filter **********
@@ -228,7 +424,7 @@ public class ListToolsTests
// ********** identity diff **********
- public void testIndexOfIdentityDifference() {
+ public void testIndexOfIdentityDifference_none() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -240,7 +436,31 @@ public class ListToolsTests
assertEquals(3, ListTools.indexOfIdentityDifference(list1, list2));
}
- public void testLastIndexOfIdentityDifference() {
+ public void testIndexOfIdentityDifference_zero() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add("b");
+ list2.add("c");
+ assertEquals(0, ListTools.indexOfIdentityDifference(list1, list2));
+ }
+
+ public void testIndexOfIdentityDifference_last() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add("a");
+ list2.add("b");
+ list2.add(new String("c"));
+ assertEquals(2, ListTools.indexOfIdentityDifference(list1, list2));
+ }
+
+ public void testLastIndexOfIdentityDifference_none() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -252,7 +472,42 @@ public class ListToolsTests
assertEquals(-1, ListTools.lastIndexOfIdentityDifference(list1, list2));
}
- public void testIdentityDifferenceRange() {
+ public void testLastIndexOfIdentityDifference_zero() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("a"));
+ list2.add("b");
+ list2.add("c");
+ assertEquals(0, ListTools.lastIndexOfIdentityDifference(list1, list2));
+ }
+
+ public void testLastIndexOfIdentityDifference_first() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add("a");
+ list2.add("b");
+ list2.add(new String("c"));
+ assertEquals(2, ListTools.lastIndexOfIdentityDifference(list1, list2));
+ }
+
+ public void testLastIndexOfIdentityDifference_size() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add("a");
+ list2.add("b");
+ assertEquals(2, ListTools.lastIndexOfIdentityDifference(list1, list2));
+ }
+
+ public void testIdentityDifferenceRange_none() {
List<String> list1 = new ArrayList<String>();
list1.add("a");
list1.add("b");
@@ -264,6 +519,42 @@ public class ListToolsTests
assertNull(ListTools.identityDifferenceRange(list1, list2));
}
+ public void testIdentityDifferenceRange_single() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add("b");
+ list2.add("c");
+ assertEquals(new Range(0, 0), ListTools.identityDifferenceRange(list1, list2));
+ }
+
+ public void testIdentityDifferenceRange_some() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("Y"));
+ list2.add("c");
+ assertEquals(new Range(0, 1), ListTools.identityDifferenceRange(list1, list2));
+ }
+
+ public void testIdentityDifferenceRange_all() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add("a");
+ list1.add("b");
+ list1.add("c");
+ List<String> list2 = new ArrayList<String>();
+ list2.add(new String("X"));
+ list2.add(new String("Y"));
+ list2.add(new String("Z"));
+ assertEquals(new Range(0, 2), ListTools.identityDifferenceRange(list1, list2));
+ }
+
// ********** index of **********
@@ -273,6 +564,7 @@ public class ListToolsTests
assertEquals(1, ListTools.indexOf(list, "B", 1));
assertEquals(-1, ListTools.indexOf(list, "B", 2));
assertEquals(-1, ListTools.indexOf(list, "B", 22));
+ assertEquals(-1, ListTools.indexOf(new ArrayList<String>(), "B", 1));
}
public void testIndexOfListObjectInt_Null() {
@@ -287,9 +579,12 @@ public class ListToolsTests
String s = "B";
List<String> list = Arrays.asList(new String[] { "A", s, "C", "D" });
assertEquals(1, ListTools.identityIndexOf(list, s, -11));
+ assertEquals(1, ListTools.identityIndexOf(list, s, 0));
assertEquals(1, ListTools.identityIndexOf(list, s, 1));
assertEquals(-1, ListTools.identityIndexOf(list, s, 2));
assertEquals(-1, ListTools.identityIndexOf(list, s, 22));
+ assertEquals(-1, ListTools.identityIndexOf(list, s, 4));
+ assertEquals(-1, ListTools.identityIndexOf(new ArrayList<String>(), s, 1));
}
public void testIdentityIndexOfListObjectInt_NotFound() {
@@ -395,7 +690,12 @@ public class ListToolsTests
assertEquals(-1, ListTools.lastIndexOf(list, "B", -11));
assertEquals(1, ListTools.lastIndexOf(list, "B", 1));
assertEquals(1, ListTools.lastIndexOf(list, "B", 2));
+ assertEquals(1, ListTools.lastIndexOf(list, "B", 4));
+ assertEquals(-1, ListTools.lastIndexOf(list, null, 4));
assertEquals(1, ListTools.lastIndexOf(list, "B", 22));
+ assertEquals(0, ListTools.lastIndexOf(list, "A", 22));
+ assertEquals(-1, ListTools.lastIndexOf(list, "XXXs", 22));
+ assertEquals(-1, ListTools.lastIndexOf(new ArrayList<String>(), "XXXs", 22));
}
public void testLastIndexOfListObjectInt_Null() {
@@ -404,6 +704,8 @@ public class ListToolsTests
assertEquals(1, ListTools.lastIndexOf(list, null, 1));
assertEquals(1, ListTools.lastIndexOf(list, null, 2));
assertEquals(1, ListTools.lastIndexOf(list, null, 22));
+ list = Arrays.asList(new String[] { null, "A", "C", "D" });
+ assertEquals(0, ListTools.lastIndexOf(list, null, 22));
}
public void testLastIdentityIndexOfListObjectInt() {
@@ -412,7 +714,9 @@ public class ListToolsTests
assertEquals(-1, ListTools.lastIdentityIndexOf(list, s, -11));
assertEquals(1, ListTools.lastIdentityIndexOf(list, s, 1));
assertEquals(1, ListTools.lastIdentityIndexOf(list, s, 2));
+ assertEquals(1, ListTools.lastIdentityIndexOf(list, s, 4));
assertEquals(1, ListTools.lastIdentityIndexOf(list, s, 22));
+ assertEquals(-1, ListTools.lastIdentityIndexOf(new ArrayList<String>(), s, 22));
}
public void testLastIdentityIndexOfListObjectInt_NotFound() {
@@ -426,49 +730,49 @@ public class ListToolsTests
}
- // ********** list **********
+ // ********** array list **********
- public void testListIterable() {
+ public void testArrayListIterable() {
Iterable<String> iterable = this.buildStringList1();
- assertEquals(this.buildStringList1(), ListTools.list(iterable));
+ assertEquals(this.buildStringList1(), ListTools.arrayList(iterable));
}
- public void testListIterableInt() {
+ public void testArrayListIterableInt() {
Iterable<String> iterable = this.buildStringList1();
- assertEquals(this.buildStringList1(), ListTools.list(iterable, 3));
+ assertEquals(this.buildStringList1(), ListTools.arrayList(iterable, 3));
}
- public void testListIterator_String() {
- List<String> list = ListTools.list(this.buildStringList1().iterator());
+ public void testArrayListIterator_String() {
+ List<String> list = ListTools.arrayList(this.buildStringList1().iterator());
assertEquals(this.buildStringList1(), list);
}
- public void testListIterator_StringObject() {
+ public void testArrayListIterator_StringObject() {
List<String> list1 = new ArrayList<String>();
list1.add("0");
list1.add("1");
list1.add("2");
list1.add("3");
- List<Object> list2 = ListTools.<Object>list(list1.iterator());
+ List<Object> list2 = ListTools.<Object>arrayList(list1.iterator());
assertEquals(list1, list2);
}
- public void testListIterator_Empty() {
- assertEquals(0, ListTools.list(EmptyIterator.instance()).size());
+ public void testArrayListIterator_Empty() {
+ assertEquals(0, ListTools.arrayList(EmptyIterator.instance()).size());
}
- public void testListIteratorInt() {
- List<String> list = ListTools.list(this.buildStringList1().iterator(), 3);
+ public void testArrayListIteratorInt() {
+ List<String> list = ListTools.arrayList(this.buildStringList1().iterator(), 3);
assertEquals(this.buildStringList1(), list);
}
- public void testListIteratorInt_Empty() {
- assertEquals(0, ListTools.list(EmptyIterator.instance(), 5).size());
+ public void testArrayListIteratorInt_Empty() {
+ assertEquals(0, ListTools.arrayList(EmptyIterator.instance(), 5).size());
}
- public void testListObjectArray() {
- List<String> list = ListTools.list(this.buildStringArray1());
+ public void testArrayListObjectArray() {
+ List<String> list = ListTools.arrayList(this.buildStringArray1());
assertEquals(this.buildStringList1(), list);
}
@@ -712,6 +1016,16 @@ public class ListToolsTests
}
}
+ public void testReverseList() {
+ List<String> list = this.buildStringList1();
+ List<String> result = ListTools.reverse(list);
+ assertSame(list, result);
+ assertEquals("two", list.get(0));
+ assertEquals("one", list.get(1));
+ assertEquals("zero", list.get(2));
+ assertEquals(3, list.size());
+ }
+
public void testShuffleList() {
List<String> list = this.buildStringList1();
List<String> result = ListTools.shuffle(list);
@@ -730,6 +1044,22 @@ public class ListToolsTests
ss.addAll(list);
List<String> result = ListTools.sort(list);
assertSame(list, result);
+ Iterator<String> ssIterator = ss.iterator();
+ for (Iterator<String> listIterator = list.iterator(); listIterator.hasNext(); ) {
+ assertEquals(ssIterator.next(), listIterator.next());
+ }
+ }
+
+ public void testSortListComparator() {
+ List<String> list = this.buildStringList1();
+ SortedSet<String> ss = new TreeSet<String>(ComparatorTools.<String>reverseComparator());
+ ss.addAll(list);
+ List<String> result = ListTools.sort(list, ComparatorTools.<String>reverseComparator());
+ assertSame(list, result);
+ Iterator<String> ssIterator = ss.iterator();
+ for (Iterator<String> listIterator = list.iterator(); listIterator.hasNext(); ) {
+ assertEquals(ssIterator.next(), listIterator.next());
+ }
}
public void testSwapListIntInt() {
@@ -743,6 +1073,87 @@ public class ListToolsTests
}
+ // ********** transformers ********