|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.jira.util.collect.CollectionUtil
public final class CollectionUtil
Constructor Summary | |
---|---|
CollectionUtil()
|
Method Summary | ||
---|---|---|
static
|
contains(Iterable<? extends T> iterable,
Predicate<T> predicate)
Does the supplied Iterable contain anything that matches the predicate? |
|
static
|
contains(Iterator<? extends T> iterator,
Predicate<T> predicate)
Does the supplied Iterator contain anything that matches the predicate? |
|
static
|
copyAsImmutableList(Collection<? extends T> copy)
Return an immutable list copy of the passed collection. |
|
static
|
copyAsImmutableMap(Map<? extends K,? extends V> copy)
Return an immutable copy of the passed map. |
|
static
|
copyAsImmutableSet(Collection<? extends T> copy)
Return an immutable set copy of the passed collection. |
|
static
|
filter(Collection<T> collection,
Predicate<? super T> predicate)
Create a filtered Collection . |
|
static
|
filter(Iterable<T> iterable,
Predicate<? super T> predicate)
Create a filtered Iterable . |
|
static
|
filter(Iterator<T> iterator,
Predicate<? super T> predicate)
Create a filtered Iterator . |
|
static
|
filterByType(Iterable<T> iterable,
Class<R> subclass)
Filter a Collection for the specified subtype. |
|
static
|
findFirstMatch(Iterable<? extends T> iterable,
Predicate<T> predicate)
Return the first found element that the predicate matches. |
|
static
|
first(Iterable<? extends T> iterable)
Get the first element of a an Iterable in iteration order, or null if empty. |
|
static
|
foreach(Iterable<T> iterable,
Consumer<T> consumer)
For each element in the iterator, consume the contents. |
|
static
|
foreach(Iterator<? extends T> iterator,
Consumer<T> consumer)
For each element in the iterator, consume the contents. |
|
static
|
indexOf(Iterable<? extends T> iterable,
Predicate<? super T> predicate)
Returns the index of the first element that matches the predicate. |
|
static
|
map(Map<K,R> map,
Function<R,S> mapper)
Take a map and eagerly transform all values into a new, immutable Map. |
|
static
|
sort(Collection<? extends T> collection,
Comparator<T> comparator)
Copy and sort the passed collection and return an unmodifiable List of the elements. |
|
static
|
toList(Enumeration<? extends T> enumeration)
Turn the enumeration into a list. |
|
static
|
toList(Iterable<? extends T> iterable)
Turn the iterable into a list. |
|
static
|
toList(Iterator<? extends T> iterator)
Turn the iterator into a list. |
|
static
|
toSet(Iterable<? extends T> iterable)
Turn the iterable into a Set. |
|
static
|
toSet(Iterator<? extends T> iterator)
Turn the iterable into a Set. |
|
static
|
transform(Iterable<? extends T> iterable,
Function<T,R> transformer)
Return a List that is transformed from elements of the input type
to elements of the output type by a transformer function. |
|
static
|
transform(Iterator<? extends T> iterator,
Function<T,R> transformer)
Return a List that is transformed from elements of the input type to elements of the output type by a transformer function. |
|
static
|
transformAndFilter(Iterable<T> iterable,
Function<T,R> transformer,
Predicate<R> predicate)
|
|
static
|
transformIterator(Iterator<? extends T> iterator,
Function<T,R> transformer)
Return an Iterator that is transformed from elements of the input
type to elements of the output type by a transformer function. |
|
static
|
transformSet(Iterable<T> iterable,
Function<T,R> transformer)
Return a Set that is transformed from elements of the input type
to elements of the output type by a transformer function. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CollectionUtil()
Method Detail |
---|
public static <T> void foreach(@Nonnull Iterator<? extends T> iterator, @Nonnull Consumer<T> consumer)
T
- the type of element to consumeiterator
- to iterate over the elementsconsumer
- to consume the elementspublic static <T> void foreach(Iterable<T> iterable, @Nonnull Consumer<T> consumer)
T
- the element typeiterable
- to iterate over the elements, may be nullconsumer
- to consume the elementspublic static <T> List<T> toList(@Nonnull Iterator<? extends T> iterator)
T
- the element typeiterator
- to iterate over the elements
List
of the elements in the iteratorpublic static <T> List<T> toList(@Nonnull Iterable<? extends T> iterable)
T
- the element typeiterable
- to iterate over the elements
List
of the elements in the iteratorpublic static <T> List<T> toList(@Nonnull Enumeration<? extends T> enumeration)
T
- the element typeenumeration
- to enumerate over the elements
List
of the elements in the iteratorpublic static <T> Set<T> toSet(@Nonnull Iterable<? extends T> iterable)
T
- the element typeiterable
- to iterate over the elements
Set
of the elements in the iteratorpublic static <T> Set<T> toSet(@Nonnull Iterator<? extends T> iterator)
T
- the element typeiterator
- to iterate over the elements
Set
of the elements in the iteratorpublic static <T,R> List<R> transform(@Nonnull Iterator<? extends T> iterator, @Nonnull Function<T,R> transformer)
T
- the input typeR
- the out typeiterator
- to iterate over the contentstransformer
- the function that performs the transformation
public static <T,R> List<R> transform(@Nonnull Iterable<? extends T> iterable, @Nonnull Function<T,R> transformer)
List
that is transformed from elements of the input type
to elements of the output type by a transformer function.
Note, this performs a copy and applies the transform to all elements. If you want a lazily applied function, see Transform
T
- the input typeR
- the out typeiterable
- the contentstransformer
- the function that performs the transformation
public static <T,R> Iterator<R> transformIterator(@Nonnull Iterator<? extends T> iterator, @Nonnull Function<T,R> transformer)
Iterator
that is transformed from elements of the input
type to elements of the output type by a transformer function.
T
- the input typeR
- the out typeiterator
- the contentstransformer
- the function that performs the transformation
Iterator
of the transformed typepublic static <T,R> Set<R> transformSet(@Nonnull Iterable<T> iterable, @Nonnull Function<T,R> transformer)
Set
that is transformed from elements of the input type
to elements of the output type by a transformer function.
Note, this performs a copy and applies the transform to all elements.
T
- the input typeR
- the output typeiterable
- the contentstransformer
- the function that performs the transformation
public static <T> boolean contains(@Nonnull Iterator<? extends T> iterator, @Nonnull Predicate<T> predicate)
Iterator
contain anything that matches the predicate?
T
- the element typeiterator
- containing elementspredicate
- the matcher
public static <T> boolean contains(@Nonnull Iterable<? extends T> iterable, @Nonnull Predicate<T> predicate)
Iterable
contain anything that matches the predicate?
T
- the element typeiterable
- containing elementspredicate
- the matcher
public static <T> Iterator<T> filter(@Nonnull Iterator<T> iterator, @Nonnull Predicate<? super T> predicate)
Iterator
.
T
- the element typeiterator
- an iterator that only returns elements approved by the predicatepredicate
- for checking the elements
Iterator
public static <T> Iterable<T> filter(@Nonnull Iterable<T> iterable, @Nonnull Predicate<? super T> predicate)
Iterable
.
T
- the element typeiterable
- an iterable whose iterators only returns elements approved by the predicatepredicate
- for checking the elements
Iterable
public static <T,R> Iterable<R> transformAndFilter(Iterable<T> iterable, Function<T,R> transformer, Predicate<R> predicate)
public static <T> Collection<T> filter(@Nonnull Collection<T> collection, @Nonnull Predicate<? super T> predicate)
Collection
.
T
- the element typecollection
- an iterable whose iterators only returns elements approved by the predicatepredicate
- for checking the elements
Iterable
public static <T,R extends T> Collection<R> filterByType(@Nonnull Iterable<T> iterable, @Nonnull Class<R> subclass)
Collection
for the specified subtype.
T
- the incoming typeR
- the result typeiterable
- an iterable whose values are of the source typesubclass
- the result type, only return elements if they are of this type
Collection
of the subtypepublic static <T> List<T> sort(@Nonnull Collection<? extends T> collection, @Nonnull Comparator<T> comparator)
List
of the elements.
T
- the element typecollection
- the collection to copycomparator
- for sorting
List
view of the elements.public static <T> List<T> copyAsImmutableList(@Nonnull Collection<? extends T> copy)
T
- the type of elements for the returned collection.copy
- the collection to copy.
public static <T> Set<T> copyAsImmutableSet(@Nonnull Collection<? extends T> copy)
T
- the type of elements for the returned collection.copy
- the collection to copy.
public static <K,V> Map<K,V> copyAsImmutableMap(@Nonnull Map<? extends K,? extends V> copy)
K
- the type of key in the returned map.V
- the type of value in the returned map.copy
- the map to copy.
public static <T> T findFirstMatch(@Nonnull Iterable<? extends T> iterable, Predicate<T> predicate)
T
- the type of element to returniterable
- that may contain the element to returnpredicate
- to match the desired element
public static <T> int indexOf(@Nonnull Iterable<? extends T> iterable, @Nonnull Predicate<? super T> predicate)
T
- the type of the elementsiterable
- collection of elementspredicate
- to match the desired element
public static <T> T first(@Nonnull Iterable<? extends T> iterable)
Iterable
in iteration order, or null if empty.
T
- the typeiterable
- the thing to get something from.
public static <K,R,S> Map<K,S> map(Map<K,R> map, Function<R,S> mapper)
K
- the key typeR
- the original value typeS
- the new value typemap
- the original mapmapper
- the mapping function
for a lazy version.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |