public class CollectionUtil
extends java.lang.Object
CloseableIterator
s.Constructor and Description |
---|
CollectionUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
addAllFromIterator(java.util.Collection<T> collection,
CloseableIterator<T> iter)
Add all the elements of a given CloseableIterator to a given Collection.
|
static <T> java.util.List<T> |
asList(CloseableIterator<T> iter)
Return the elements of a given CloseableIterator as a List.
|
static <T> java.util.Set<T> |
asSet(CloseableIterator<T> iter)
Return the elements of a given CloseableIterator as a Set.
|
static java.util.Set<java.lang.String> |
difference(java.util.Set<java.lang.String> a,
java.util.Set<java.lang.String> b) |
static <T> java.lang.Iterable<T> |
forEach(java.util.Iterator<T> iter)
A convenience method to use an iterator in a for-each loop.
|
static java.util.Set<java.lang.String> |
intersection(java.util.List<java.util.Set<java.lang.String>> sets) |
static java.util.Set<java.lang.String> |
intersection(java.util.Set<java.lang.String> a,
java.util.Set<java.lang.String> b) |
static java.util.Set<java.lang.String> |
union(java.util.List<java.util.Set<java.lang.String>> sets) |
public static java.util.Set<java.lang.String> difference(java.util.Set<java.lang.String> a, java.util.Set<java.lang.String> b)
a
- b
- public static java.util.Set<java.lang.String> union(java.util.List<java.util.Set<java.lang.String>> sets)
public static java.util.Set<java.lang.String> intersection(java.util.List<java.util.Set<java.lang.String>> sets)
public static java.util.Set<java.lang.String> intersection(java.util.Set<java.lang.String> a, java.util.Set<java.lang.String> b)
public static <T> void addAllFromIterator(java.util.Collection<T> collection, CloseableIterator<T> iter) throws RepositoryException
collection
- a collection to be added toiter
- an iterator, the elements of which will be added to the collectionRepositoryException
public static <T> java.util.List<T> asList(CloseableIterator<T> iter) throws RepositoryException
iter
- an iteratorRepositoryException
public static <T> java.util.Set<T> asSet(CloseableIterator<T> iter) throws RepositoryException
iter
- an iteratorRepositoryException
public static <T> java.lang.Iterable<T> forEach(java.util.Iterator<T> iter)
CloseableIterator
:
CloseableIterator<DataElement> iter = dobj.listDataElements();
try {
for(DataElement element : CollectionUtil.forEach(iter)) {
// ...
}
} catch (UncheckedRepositoryException e) {
e.throwCause();
} finally {
iter.close();
}
Note that the returned Iterable does not allow its iterator()
method to return a fresh iterator each time; the iteration is once-only.iter
- an iterator