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 List<Object> asList(Object... objects)
          Null safe method for converting an array of objects into a list.
static
<T> List<T>
combine(List<T> list1, List<T> list2)
          Return a new list containing all of the elements from the lists passed in
static
<T> List<T>
combine(List<T> list1, List<T> list2, List<T> list3)
           
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 List<String> filter(Collection<String> strings, StringFilter filter)
          Remove any Strings from the collection that do not match the filter
static List<String> filterAndSort(List<String> strings, StringFilter filter)
          Remove any Strings from the list that do not match the filter and then sort the ones that remain
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 List<String> getNoneSensitiveListFromCSV(String csv)
          If the CSV value evaluates to null, "null", "none" or the empty string, return an empty list.
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 getSpaceSeparatedCSV(List<String> strings)
           
static String getSpaceSeparatedString(List<?> list)
           
static String getStringWithSeparator(List<?> list, String separator)
           
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
<T> List<T>
nullSafeCombine(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)
           
static
<T> List<T>
unmodifiableList(T... elements)
          Get an unmodifiable list from the single element.
static
<T> List<T>
unmodifiableList(T element)
          Get an unmodifiable list from the single element.
 
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

unmodifiableList

public static <T> List<T> unmodifiableList(T element)
Get an unmodifiable list from the single element. Return emptyList() if element is null.


unmodifiableList

public static <T> List<T> unmodifiableList(T... elements)
Get an unmodifiable list from the single element. Return emptyList() if element is null.


getNoneSensitiveListFromCSV

public static List<String> getNoneSensitiveListFromCSV(String csv)
If the CSV value evaluates to null, "null", "none" or the empty string, return an empty list.


filterAndSort

public static List<String> filterAndSort(List<String> strings,
                                         StringFilter filter)
Remove any Strings from the list that do not match the filter and then sort the ones that remain


filter

public static List<String> filter(Collection<String> strings,
                                  StringFilter filter)
Remove any Strings from the collection that do not match the filter


asList

public static List<Object> asList(Object... objects)
Null safe method for converting an array of objects into a list. Never returns null.


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)

getSpaceSeparatedCSV

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

getStringWithSeparator

public static final String getStringWithSeparator(List<?> list,
                                                  String separator)

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)

nullSafeCombine

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

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


combine

public static final <T> List<T> combine(List<T> list1,
                                        List<T> list2)
Return a new list containing all of the elements from the lists passed in


combine

public static final <T> List<T> combine(List<T> list1,
                                        List<T> list2,
                                        List<T> list3)

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.