org.eobjects.metamodel.util
Class CollectionUtils

java.lang.Object
  extended by org.eobjects.metamodel.util.CollectionUtils

public final class CollectionUtils
extends Object

Various utility methods for handling of collections and arrays.

Author:
Kasper Sørensen

Method Summary
static
<E> E[]
array(E[] existingArray, E... elements)
          Concatenates two arrays
static
<E> E[]
arrayOf(Class<E> elementClass, Object arrayOrElement)
           
static
<E> E[]
arrayRemove(E[] array, E elementToRemove)
           
static Object arrayRemove(Object array, Object elementToRemove)
           
static
<E> List<E>
concat(boolean removeDuplicates, Collection<? extends E> firstCollection, Collection<?>... collections)
           
static
<E> List<E>
filter(E[] items, Predicate<? super E> predicate)
           
static
<E> List<E>
filter(Iterable<E> items, Predicate<? super E> predicate)
           
static
<E> void
forEach(E[] items, Action<? super E> action)
           
static
<E> void
forEach(Iterable<E> items, Action<? super E> action)
           
static boolean isNullOrEmpty(Collection<?> col)
           
static
<E> boolean
isNullOrEmpty(E[] arr)
           
static
<I,O> List<O>
map(I[] items, Func<? super I,O> func)
           
static
<I,O> List<O>
map(Iterable<I> items, Func<? super I,O> func)
           
static List<?> toList(Object obj)
          General purpose list converter method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

array

public static <E> E[] array(E[] existingArray,
                            E... elements)
Concatenates two arrays

Parameters:
existingArray - an existing array
elements - the elements to add to the end of it
Returns:

concat

public static <E> List<E> concat(boolean removeDuplicates,
                                 Collection<? extends E> firstCollection,
                                 Collection<?>... collections)

arrayRemove

public static <E> E[] arrayRemove(E[] array,
                                  E elementToRemove)

arrayRemove

public static Object arrayRemove(Object array,
                                 Object elementToRemove)

arrayOf

public static <E> E[] arrayOf(Class<E> elementClass,
                              Object arrayOrElement)

filter

public static <E> List<E> filter(E[] items,
                                 Predicate<? super E> predicate)

filter

public static <E> List<E> filter(Iterable<E> items,
                                 Predicate<? super E> predicate)

map

public static <I,O> List<O> map(I[] items,
                                Func<? super I,O> func)

map

public static <I,O> List<O> map(Iterable<I> items,
                                Func<? super I,O> func)

forEach

public static <E> void forEach(E[] items,
                               Action<? super E> action)

forEach

public static <E> void forEach(Iterable<E> items,
                               Action<? super E> action)

isNullOrEmpty

public static <E> boolean isNullOrEmpty(E[] arr)

isNullOrEmpty

public static boolean isNullOrEmpty(Collection<?> col)

toList

public static List<?> toList(Object obj)
General purpose list converter method. Will convert arrays, collections, iterables etc. into lists. If the argument is a single object (such as a String or a POJO) it will be wrapped in a single-element list. Null will be converted to the empty list.

Parameters:
obj - any object
Returns:
a list representation of the object


Copyright © 2007-2013. All Rights Reserved.