diff options
author | Brian Vosburgh | 2013-07-12 22:09:18 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-07-12 22:13:19 +0000 |
commit | f529fc18fa9f5ae17e94bfb6a40f6888eecb16f2 (patch) | |
tree | 43ed5b03116707358c2f27a41f4a959eb71b1fe3 /common | |
parent | 130b1f61dc07afd5834f824870a9685dd8423066 (diff) | |
download | webtools.dali-f529fc18fa9f5ae17e94bfb6a40f6888eecb16f2.tar.gz webtools.dali-f529fc18fa9f5ae17e94bfb6a40f6888eecb16f2.tar.xz webtools.dali-f529fc18fa9f5ae17e94bfb6a40f6888eecb16f2.zip |
add CollectionTools.identityBag(...) factory methods
Diffstat (limited to 'common')
-rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/collection/CollectionTools.java | 52 |
1 files changed, 52 insertions, 0 deletions
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 5fc5eef3a5..bb357d44e4 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 @@ -615,6 +615,58 @@ public final class CollectionTools { } + // ********** identity bag factory methods ********** + + /** + * Return an identity bag corresponding to the specified iterable. + */ + public static <E> IdentityHashBag<E> identityBag(Iterable<? extends E> iterable) { + return identityBag(iterable.iterator()); + } + + /** + * 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. + */ + 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; + } + + /** + * Return an identity bag corresponding to the specified array. + */ + 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; + } + + // ********** collection factory methods ********** /** |