public class CollectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <R,T> R |
aggregate(Collection<T> elements,
Aggregator<R,T> aggregator) |
static <T> boolean |
areDifferent(T... elements)
method that determines if any of the inputs is not .equal()
the method handles null gracefully: if all elements are null, they are considered equal.
|
static <T> boolean |
areEqual(T... elements)
method that determines if all inputs are .equal().
|
static <T> T[] |
combineArrays(T[] original,
T... additional) |
static boolean |
containsAny(Collection container,
Collection contained) |
static <T> void |
filter(Collection<T> items,
Criteria<T> criteria) |
static Collection |
intersect(Collection container,
Collection contained) |
static boolean |
isPrefix(Iterable suspectedPrefix,
Iterable container)
there's no point in being "type safe" in this method, as the returned value is not typed, and we would like to
support any type of iterable comparison.
|
static <R,T> List<R> |
map(Collection<T> elements,
Handler<R,T> handler) |
static <R,T> Map<T,R> |
mapToMap(Collection<T> elements,
Handler<R,T> handler) |
static <C extends Comparable,T> |
max(Collection<T> elements,
Handler<C,T> handler)
sometimes when we want to compare objects according to something that is already comparable,
it's easier to write a handler that generates that comparable than to write a comparator.
|
static Object |
nextOrNull(Iterator i) |
static <T> Map<T,HashSet<T>> |
reverseMap(Map<T,? extends Collection<T>> input) |
public static boolean isPrefix(Iterable suspectedPrefix, Iterable container)
suspectedPrefix
- some iterable whose may be a prefix for containercontainer
- the iterable who may or may not start with suspectedPrefixpublic static <T> boolean areEqual(T... elements)
T
- type of the elementselements
- to check if equalpublic static <T> boolean areDifferent(T... elements)
T
- type of the elementselements
- to check if differentpublic static Object nextOrNull(Iterator i)
i
- an iterator from which we want to retrieve the next element.public static <T> T[] combineArrays(T[] original, T... additional)
original
- an array we want to start with as prefixadditional
- an array we want to append as suffixpublic static <R,T> R aggregate(Collection<T> elements, Aggregator<R,T> aggregator)
R
- the resulting value of the aggregationT
- the type of the aggregated collectionelements
- the collection we would like to aggregateaggregator
- the aggregation strategy to use when aggregating the collectionpublic static <R,T> List<R> map(Collection<T> elements, Handler<R,T> handler)
R
- the result type of the application of the handler function on each of elements' elementsT
- the type of the elements collection and handler function input typeelements
- the collection to iteratehandler
- the function to apply on each element of elementspublic static <R,T> Map<T,R> mapToMap(Collection<T> elements, Handler<R,T> handler)
R
- the result type of the application of the handler function on each of elements' elementsT
- the type of the elements collection and handler function input typeelements
- the collection to iterate, each one will be a key in the resulting maphandler
- the function to apply on each element of elements in order to create a valuepublic static <C extends Comparable,T> Map.Entry<T,C> max(Collection<T> elements, Handler<C,T> handler)
C
- comparable typeT
- type of elementselements
- on a transformation of which we wish to find the maximumhandler
- to transform each element into a comparableMaxAggregator
public static boolean containsAny(Collection container, Collection contained)
container
- the containing collectioncontained
- the collection with a contained elementpublic static Collection intersect(Collection container, Collection contained)
container
- a collectioncontained
- another collectionpublic static <T> void filter(Collection<T> items, Criteria<T> criteria)
T
- the type of the collection and input parameter of the criteria
function returns nothing, works on the items collection in memory. iterator
of collection must support the remove method.items
- collection to filter according to criteriacriteria
- to use when filtering the items collectionpublic static <T> Map<T,HashSet<T>> reverseMap(Map<T,? extends Collection<T>> input)
T
- type of map and collectioninput
- map to reverseCopyright © 2004-2016. All Rights Reserved.