org.kuali.common.util
Class CollectionUtils

java.lang.Object
  extended by org.kuali.common.util.CollectionUtils

public class CollectionUtils
extends Object


Constructor Summary
CollectionUtils()
           
 
Method Summary
static List<Class<?>> asList(Class<?>... classes)
          Null safe method for converting an untyped array of classes into a list.
static
<T> List<T>
combine(T element, List<T> list)
          Return a combined list where required is always the first element in the list
static
<T> List<T>
combineLists(List<List<T>> listOfLists)
          Combine the list of lists into a single list
static
<K,V> Map<K,V>
combineMaps(List<Map<K,V>> listOfMaps)
          Combine the list of maps into a single map
static List<String> combineStrings(List<String> list1, List<String> list2)
          Return a new list containing all of the strings from both lists
static List<String> combineStrings(List<String> list1, List<String> list2, List<String> list3)
           
static List<String> combineStrings(List<String> list1, String string, List<String> list2)
          Return a new list containing all of the strings from both lists with string added in between the strings from both lists
static List<String> combineStringsUniquely(List<String> list1, List<String> list2)
          Return a new list containing the unique set of strings contained in both lists
static boolean containsAny(String s, List<String> strings)
          Return true if s contains any of the strings from strings
static String getCSV(List<String> strings)
           
static int[] getDivideEvenly(int number, int howManyWays)
          Return an array of int's that represents as even of a split as possible For example: passing in 100,7 returns 15, 15, 14, 14, 14, 14, 14
static List<String> getLines(String s)
           
static
<T> List<T>
getList(List<Boolean> includes, List<T> list)
          Return a list containing only the elements where the corresponding index in the includes list is true.
protected static
<T> T
getNewInstance(Class<T> c)
           
static
<T> List<T>
getNewList(Class<T> c, int size)
          Create a new list containing new instances of c
static
<T> List<T>
getPreFilledList(int size, T value)
           
static List<String> getSequencedStrings(List<String> strings)
          Prefix the strings passed in with their position in the list (left padded with zero's).
static List<String> getSequencedStrings(List<String> strings, int initialSequenceNumber)
          Prefix the strings passed in with their position in the list (left padded with zero's).
static String getSpaceSeparatedString(List<?> list)
           
static List<String> getTrimmedListFromCSV(String csv)
           
static List<File> getUniqueFiles(List<File> files)
           
static List<String> getUniqueStrings(List<String> strings)
          Return a new List containing the unique set of strings from strings
static boolean isEmpty(Collection<?> c)
           
static
<T> void
nullSafeAdd(List<T> list1, List<T> list2)
           
static List<String> sortedMerge(List<String> list, String csv)
           
static
<T> List<List<T>>
splitEvenly(List<T> elements, int howManyWays)
          Split elements evenly into separate lists divided up howManyWays
static
<T> List<T>
toEmptyList(List<T> list)
          If list==null return an empty list otherwise return list
static
<T> List<T>
toEmptyList(T o)
          If o==null return an empty list otherwise return a singleton list.
static
<T> Collection<T>
toNullIfEmpty(Collection<T> c)
           
static
<T> List<T>
toNullIfEmpty(List<T> list)
           
static Object[] toObjectArray(List<Object> objects)
           
static String[] toStringArray(List<String> strings)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionUtils

public CollectionUtils()
Method Detail

asList

public static List<Class<?>> asList(Class<?>... classes)
Null safe method for converting an untyped array of classes into a list. Never returns null.


getDivideEvenly

public static int[] getDivideEvenly(int number,
                                    int howManyWays)
Return an array of int's that represents as even of a split as possible For example: passing in 100,7 returns 15, 15, 14, 14, 14, 14, 14

Parameters:
numerator -
denominator -
Returns:

splitEvenly

public static final <T> List<List<T>> splitEvenly(List<T> elements,
                                                  int howManyWays)
Split elements evenly into separate lists divided up howManyWays


getSequencedStrings

public static final List<String> getSequencedStrings(List<String> strings,
                                                     int initialSequenceNumber)
Prefix the strings passed in with their position in the list (left padded with zero's). The padding is the number of digits in the size of the list. A list with 100 elements will return strings prefixed with 000, 001, etc.


getSequencedStrings

public static final List<String> getSequencedStrings(List<String> strings)
Prefix the strings passed in with their position in the list (left padded with zero's). The padding is the number of digits in the size of the list. A list with 100 elements will return strings prefixed with 000, 001, etc.


getUniqueStrings

public static final List<String> getUniqueStrings(List<String> strings)
Return a new List containing the unique set of strings from strings


getUniqueFiles

public static final List<File> getUniqueFiles(List<File> files)

getLines

public static final List<String> getLines(String s)

combineStringsUniquely

public static final List<String> combineStringsUniquely(List<String> list1,
                                                        List<String> list2)
Return a new list containing the unique set of strings contained in both lists


getNewInstance

protected static final <T> T getNewInstance(Class<T> c)

getNewList

public static final <T> List<T> getNewList(Class<T> c,
                                           int size)
Create a new list containing new instances of c


getList

public static final <T> List<T> getList(List<Boolean> includes,
                                        List<T> list)
Return a list containing only the elements where the corresponding index in the includes list is true. includes and list must be the same size.


combineLists

public static final <T> List<T> combineLists(List<List<T>> listOfLists)
Combine the list of lists into a single list


combineMaps

public static final <K,V> Map<K,V> combineMaps(List<Map<K,V>> listOfMaps)
Combine the list of maps into a single map


combine

public static final <T> List<T> combine(T element,
                                        List<T> list)
Return a combined list where required is always the first element in the list


toEmptyList

public static final <T> List<T> toEmptyList(T o)
If o==null return an empty list otherwise return a singleton list.


toEmptyList

public static final <T> List<T> toEmptyList(List<T> list)
If list==null return an empty list otherwise return list


toNullIfEmpty

public static final <T> List<T> toNullIfEmpty(List<T> list)

toNullIfEmpty

public static final <T> Collection<T> toNullIfEmpty(Collection<T> c)

getPreFilledList

public static final <T> List<T> getPreFilledList(int size,
                                                 T value)

getCSV

public static final String getCSV(List<String> strings)

getSpaceSeparatedString

public static final String getSpaceSeparatedString(List<?> list)

toObjectArray

public static final Object[] toObjectArray(List<Object> objects)

toStringArray

public static final String[] toStringArray(List<String> strings)

isEmpty

public static final boolean isEmpty(Collection<?> c)

sortedMerge

public static final List<String> sortedMerge(List<String> list,
                                             String csv)

getTrimmedListFromCSV

public static final List<String> getTrimmedListFromCSV(String csv)

combineStrings

public static final List<String> combineStrings(List<String> list1,
                                                List<String> list2,
                                                List<String> list3)

combineStrings

public static final List<String> combineStrings(List<String> list1,
                                                String string,
                                                List<String> list2)
Return a new list containing all of the strings from both lists with string added in between the strings from both lists


combineStrings

public static final List<String> combineStrings(List<String> list1,
                                                List<String> list2)
Return a new list containing all of the strings from both lists


nullSafeAdd

public static final <T> void nullSafeAdd(List<T> list1,
                                         List<T> list2)

containsAny

public static final boolean containsAny(String s,
                                        List<String> strings)
Return true if s contains any of the strings from strings



Copyright © 2010-2013 The Kuali Foundation. All Rights Reserved.