public final class CollectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <T,U> com.google.common.collect.ImmutableCollection<U> |
filterAndTransform(Collection<T> elements,
com.google.common.base.Function<T,com.google.common.base.Optional<U>> function)
Filters and transforms the matching elements.
|
static <T> com.google.common.collect.ImmutableList<T> |
remove(List<? extends T> source,
List<? extends T> toRemove)
Removes the given elements from the given list.
|
static <T> com.google.common.collect.ImmutableSet<T> |
remove(Set<? extends T> source,
Set<? extends T> toRemove)
Removes the given elements from the given set.
|
static <T> Pair<com.google.common.collect.ImmutableCollection<T>,com.google.common.collect.ImmutableCollection<T>> |
separate(Collection<T> elements,
com.google.common.base.Predicate<? super T> predicate)
Separates the elements of the given collection by the given predicate into two collections.
|
static <T> com.google.common.collect.ImmutableList<T> |
tailSubList(Collection<T> collection,
int n)
Returns the n last elements of the given collection.
|
static <E> com.google.common.collect.ImmutableSet<E> |
toSetKeepFirst(Collection<E> elements,
com.google.common.base.Equivalence<E> equivalence)
Returns a set of the given elements where element equality is defined by the given Equivalence instance.
|
static <E> com.google.common.collect.ImmutableSet<E> |
toSetKeepLast(Collection<E> elements,
com.google.common.base.Equivalence<E> equivalence)
Returns a set of the given elements where element equality is defined by the given Equivalence instance.
|
static <T> List<T> |
toTypedList(List list)
'Converts' the given list to a typed list.
|
static <K,V> Map<K,V> |
toTypedMap(Map map)
'Converts' the given map to a typed map.
|
static <T> Set<T> |
toTypedSet(Set set)
'Converts' the given set to a typed set.
|
static <V,W> List<Object> |
transformListRecursively(List<? extends Object> list,
com.google.common.base.Function<V,W> atomicValueFunction)
Recursively transforms the values of the given list by applying the given function.
|
static <K,V,W> Map<K,Object> |
transformMapRecursively(Map<K,? extends Object> map,
com.google.common.base.Function<V,W> atomicValueFunction)
Recursively transforms the values of the given map by applying the given function.
|
static <V,W> Set<Object> |
transformSetRecursively(Set<? extends Object> set,
com.google.common.base.Function<V,W> atomicValueFunction)
Recursively transforms the values of the given set by applying the given function.
|
static <T,V> Map<T,V> |
unmodifiableDetachedMap(Map<T,V> map)
Converts the map to an immutable map.
|
public static <V,W> List<Object> transformListRecursively(List<? extends Object> list, com.google.common.base.Function<V,W> atomicValueFunction)
List
, Set
, or
Map
, all other value types are considered 'atomic' and will have the given transformation function applied.V
- the type of the atomic values contained in this list, top-level or nestedW
- the type of the result valueslist
- the list whose values to transformatomicValueFunction
- the transformation function to apply on the list valuespublic static <V,W> Set<Object> transformSetRecursively(Set<? extends Object> set, com.google.common.base.Function<V,W> atomicValueFunction)
List
, Set
, or
Map
, all other value types are considered 'atomic' and will have the given transformation function applied.V
- the type of the atomic values contained in this set, top-level or nestedW
- the type of the result valuesset
- the set whose values to transformatomicValueFunction
- the transformation function to apply on the set valuespublic static <K,V,W> Map<K,Object> transformMapRecursively(Map<K,? extends Object> map, com.google.common.base.Function<V,W> atomicValueFunction)
List
, Set
, or
Map
, all other value types are considered 'atomic' and will have the given transformation function applied.K
- the type of the keyV
- the type of the atomic values contained in this map, top-level or nestedW
- the type of the result valuesmap
- the map whose values to transformatomicValueFunction
- the transformation function to apply on the map valuespublic static <T> com.google.common.collect.ImmutableList<T> tailSubList(Collection<T> collection, int n)
T
- the type of the listcollection
- the collection from which to return the n last elementsn
- the number of elements to returnpublic static <E> com.google.common.collect.ImmutableSet<E> toSetKeepFirst(Collection<E> elements, com.google.common.base.Equivalence<E> equivalence)
E
- the type of the setelements
- the elements to put in a Setequivalence
- the Equivalence that defines equality of two elementspublic static <E> com.google.common.collect.ImmutableSet<E> toSetKeepLast(Collection<E> elements, com.google.common.base.Equivalence<E> equivalence)
E
- the type of the setelements
- the elements to put in a Setequivalence
- the Equivalence that defines equality of two elementspublic static <T> Pair<com.google.common.collect.ImmutableCollection<T>,com.google.common.collect.ImmutableCollection<T>> separate(Collection<T> elements, com.google.common.base.Predicate<? super T> predicate)
T
- the type of the collectionelements
- the elements to separatepredicate
- the predicate by which to separate the elementspublic static <T,U> com.google.common.collect.ImmutableCollection<U> filterAndTransform(Collection<T> elements, com.google.common.base.Function<T,com.google.common.base.Optional<U>> function)
T
- the type of the elementsU
- the type of the returned and transformed collectionelements
- the elements to filter and transformfunction
- the transformation to apply, returns Optional.absent()
for non-matching elementspublic static <T,V> Map<T,V> unmodifiableDetachedMap(Map<T,V> map)
T
- the type of the keyV
- the type of the valuemap
- the map, can be nullpublic static <T> com.google.common.collect.ImmutableList<T> remove(List<? extends T> source, List<? extends T> toRemove)
T
- the type of the listsource
- the list to remove fromtoRemove
- the elements to removepublic static <T> com.google.common.collect.ImmutableSet<T> remove(Set<? extends T> source, Set<? extends T> toRemove)
T
- the type of the setsource
- the set to remove fromtoRemove
- the elements to removepublic static <T> List<T> toTypedList(List list)
T
- the type of the listlist
- the list to 'convert'public static <T> Set<T> toTypedSet(Set set)
T
- the type of the setset
- the set to 'convert'public static <K,V> Map<K,V> toTypedMap(Map map)
K
- the type of the keyV
- the type of the valuemap
- the map to 'convert'Copyright © 2010 - 2018 edorasware ag. All Rights Reserved.