public final class CollectionUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
findFirstCommonItem(java.lang.Iterable<T> ref,
java.lang.Iterable<T> other)
Finds the first item in a collection that also appears in another collection.
|
static <K,T> groovy.lang.Tuple2<K,T> |
findFirstCommonItem(java.lang.Iterable<T> ref,
java.util.Map<K,? extends java.lang.Iterable<T>> others)
Finds the first item in a collection that also appears in any of a number of other collections.
|
static <T> T |
findFirstCommonItem(java.util.Iterator<T> refIterator,
java.util.Iterator<T> otherIterator)
Finds the first item in an iterator that also appears in another iterator.
|
static <K,T> groovy.lang.Tuple2<K,T> |
findFirstCommonItem(java.util.Iterator<T> refIterator,
java.util.Map<K,? extends java.util.Iterator<T>> otherIterators)
Finds the first item on an iterator that also appears on any of a number of other
iterators.
|
public static <K,T> groovy.lang.Tuple2<K,T> findFirstCommonItem(java.util.Iterator<T> refIterator,
java.util.Map<K,? extends java.util.Iterator<T>> otherIterators)
This could have easily been implemented by Set logic, but the iterators may represent possibly quite long sequences, so we don't want to consume more items than necessary.
The iterators that are passed in will be (partly) consumed by this method, so the caller should not make any assumptions about their state when the method returns.
K - the key typeT - the item typerefIterator - the iterator with the reference items to look forotherIterators - a map containing a number of other iterators as values. The map keys
may be used to identify from which iterator the matching item came.Tuple2 that consists of: otherIterators that contained the match;null if refIterator is disjoint with all otherIterators.public static <K,T> groovy.lang.Tuple2<K,T> findFirstCommonItem(java.lang.Iterable<T> ref,
java.util.Map<K,? extends java.lang.Iterable<T>> others)
K - the key typeT - the item typeref - the collection containing the reference itemsothers - a Map containing a number of other collections as values. The map keys
may be used to identify from which collection the matching item cameTuple2 that consists of: otherIterators that contained the match;null if ref is disjoint with all others.public static <T> T findFirstCommonItem(java.util.Iterator<T> refIterator,
java.util.Iterator<T> otherIterator)
T - the item typerefIterator - the iterator returning the reference itemsotherIterator - the iterator to compare withnull if the two iterators are disjointpublic static <T> T findFirstCommonItem(java.lang.Iterable<T> ref,
java.lang.Iterable<T> other)
T - the item typeref - the collection containing the reference itemsother - the collection to compare withnull if the two collections are disjoint