public final class

CollectionUtil

extends Object
java.lang.Object
   ↳ com.atlassian.jira.util.collect.CollectionUtil

Summary

Public Constructors
CollectionUtil()
Public Methods
static <T> boolean contains(Iterator<? extends T> iterator, Predicate<T> predicate)
Does the supplied Iterator contain anything that matches the predicate?
static <T> boolean contains(Iterable<? extends T> iterable, Predicate<T> predicate)
Does the supplied Iterable contain anything that matches the predicate?
static <T> List<T> copyAsImmutableList(Collection<? extends T> copy)
Return an immutable list copy of the passed collection.
static <K, V> Map<K, V> copyAsImmutableMap(Map<? extends K, ? extends V> copy)
Return an immutable copy of the passed map.
static <T> Set<T> copyAsImmutableSet(Collection<? extends T> copy)
Return an immutable set copy of the passed collection.
static <T> Collection<T> filter(Collection<T> collection, Predicate<? super T> predicate)
Create a filtered Collection.
static <T> Iterator<T> filter(Iterator<T> iterator, Predicate<? super T> predicate)
Create a filtered Iterator.
static <T> Iterable<T> filter(Iterable<T> iterable, Predicate<? super T> predicate)
Create a filtered Iterable.
static <T, R extends T> Collection<R> filterByType(Iterable<T> iterable, Class<R> subclass)
Filter a Collection for the specified subtype.
static <T> T findFirstMatch(Iterable<? extends T> iterable, Predicate<T> predicate)
Return the first found element that the predicate matches.
static <T> T first(Iterable<? extends T> iterable)
Get the first element of a an Iterable in iteration order, or null if empty.
static <T> void foreach(Iterable<T> iterable, Consumer<T> consumer)
For each element in the iterator, consume the contents.
static <T> void foreach(Iterator<? extends T> iterator, Consumer<T> consumer)
For each element in the iterator, consume the contents.
static <T> int indexOf(Iterable<? extends T> iterable, Predicate<? super T> predicate)
Returns the index of the first element that matches the predicate.
static <K, R, S> Map<K, S> map(Map<K, R> map, Function<R, S> mapper)
Take a map and eagerly transform all values into a new, immutable Map.
static <T> List<T> sort(Collection<? extends T> collection, Comparator<T> comparator)
Copy and sort the passed collection and return an unmodifiable List of the elements.
static <T> List<T> toList(Enumeration<? extends T> enumeration)
Turn the enumeration into a list.
static <T> List<T> toList(Iterable<? extends T> iterable)
Turn the iterable into a list.
static <T> List<T> toList(Iterator<? extends T> iterator)
Turn the iterator into a list.
static <T> Set<T> toSet(Iterable<? extends T> iterable)
Turn the iterable into a Set.
static <T> Set<T> toSet(Iterator<? extends T> iterator)
Turn the iterable into a Set.
static <T, R> List<R> 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 <T, R> List<R> 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 <T, R> Iterable<R> transformAndFilter(Iterable<T> iterable, Function<T, R> transformer, Predicate<R> predicate)
static <T, R> Iterator<R> 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 <T, R> Set<R> 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CollectionUtil ()

Public Methods

public static boolean contains (Iterator<? extends T> iterator, Predicate<T> predicate)

Does the supplied Iterator contain anything that matches the predicate?

Parameters
iterator containing elements
predicate the matcher
Returns
  • true if the predicate returns true for any elements.

public static boolean contains (Iterable<? extends T> iterable, Predicate<T> predicate)

Does the supplied Iterable contain anything that matches the predicate?

Parameters
iterable containing elements
predicate the matcher
Returns
  • true if the predicate returns true for any elements.

public static List<T> copyAsImmutableList (Collection<? extends T> copy)

Return an immutable list copy of the passed collection.

Parameters
copy the collection to copy.
Returns
  • an immutable list copy of the passed collection.

public static Map<K, V> copyAsImmutableMap (Map<? extends K, ? extends V> copy)

Return an immutable copy of the passed map. The type of the reurned map is not gaurenteed to match the type of the passed map. If this is important, than do it yourself.

Parameters
copy the map to copy.
Returns
  • the copied and immutable map.

public static Set<T> copyAsImmutableSet (Collection<? extends T> copy)

Return an immutable set copy of the passed collection.

Parameters
copy the collection to copy.
Returns
  • an immutable set copy of the passed collection.

public static Collection<T> filter (Collection<T> collection, Predicate<? super T> predicate)

Create a filtered Collection.

Parameters
collection an iterable whose iterators only returns elements approved by the predicate
predicate for checking the elements
Returns

public static Iterator<T> filter (Iterator<T> iterator, Predicate<? super T> predicate)

Create a filtered Iterator.

Parameters
iterator an iterator that only returns elements approved by the predicate
predicate for checking the elements
Returns

public static Iterable<T> filter (Iterable<T> iterable, Predicate<? super T> predicate)

Create a filtered Iterable.

Parameters
iterable an iterable whose iterators only returns elements approved by the predicate
predicate for checking the elements
Returns

public static Collection<R> filterByType (Iterable<T> iterable, Class<R> subclass)

Filter a Collection for the specified subtype.

Parameters
iterable an iterable whose values are of the source type
subclass the result type, only return elements if they are of this type
Returns

public static T findFirstMatch (Iterable<? extends T> iterable, Predicate<T> predicate)

Return the first found element that the predicate matches.

Parameters
iterable that may contain the element to return
predicate to match the desired element
Returns
  • the first matched element or null if none found

public static T first (Iterable<? extends T> iterable)

Get the first element of a an Iterable in iteration order, or null if empty.

Parameters
iterable the thing to get something from.
Returns
  • the first thing the iterator spits out. May

public static void foreach (Iterable<T> iterable, Consumer<T> consumer)

For each element in the iterator, consume the contents.

Parameters
iterable to iterate over the elements, may be null
consumer to consume the elements

public static void foreach (Iterator<? extends T> iterator, Consumer<T> consumer)

For each element in the iterator, consume the contents.

Parameters
iterator to iterate over the elements
consumer to consume the elements

public static int indexOf (Iterable<? extends T> iterable, Predicate<? super T> predicate)

Returns the index of the first element that matches the predicate.

Parameters
iterable collection of elements
predicate to match the desired element
Returns
  • the 0-based index of the first element that matches the predicate or -1 if none found

public static Map<K, S> map (Map<K, R> map, Function<R, S> mapper)

Take a map and eagerly transform all values into a new, immutable Map.

Parameters
map the original map
mapper the mapping function
Returns
  • a new immutable map

public static List<T> sort (Collection<? extends T> collection, Comparator<T> comparator)

Copy and sort the passed collection and return an unmodifiable List of the elements.

Parameters
collection the collection to copy
comparator for sorting
Returns
  • an unmodifiable List view of the elements.

public static List<T> toList (Enumeration<? extends T> enumeration)

Turn the enumeration into a list.

Parameters
enumeration to enumerate over the elements
Returns
  • an unmodifiable List of the elements in the iterator

public static List<T> toList (Iterable<? extends T> iterable)

Turn the iterable into a list.

Parameters
iterable to iterate over the elements
Returns
  • an unmodifiable List of the elements in the iterator

public static List<T> toList (Iterator<? extends T> iterator)

Turn the iterator into a list.

Parameters
iterator to iterate over the elements
Returns
  • an unmodifiable List of the elements in the iterator

public static Set<T> toSet (Iterable<? extends T> iterable)

Turn the iterable into a Set.

Parameters
iterable to iterate over the elements
Returns
  • an unmodifiable Set of the elements in the iterator

public static Set<T> toSet (Iterator<? extends T> iterator)

Turn the iterable into a Set.

Parameters
iterator to iterate over the elements
Returns
  • an unmodifiable Set of the elements in the iterator

public static List<R> 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.

Parameters
iterator to iterate over the contents
transformer the function that performs the transformation
Returns
  • an unmodifiable List of the transformed type

public static List<R> 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.

Note, this performs a copy and applies the transform to all elements. If you want a lazily applied function, see Transform

Parameters
iterable the contents
transformer the function that performs the transformation
Returns
  • an unmodifiable List of the transformed type

public static Iterable<R> transformAndFilter (Iterable<T> iterable, Function<T, R> transformer, Predicate<R> predicate)

public static Iterator<R> 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.

Parameters
iterator the contents
transformer the function that performs the transformation
Returns

public static Set<R> 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.

Note, this performs a copy and applies the transform to all elements.

Parameters
iterable the contents
transformer the function that performs the transformation
Returns
  • an unmodifiable Set of the transformed type