randoop.util
Class CollectionsExt

Object
  extended by CollectionsExt

public final class CollectionsExt
extends Object


Method Summary
Modifier and Type Method and Description
static
<T> T[]
addToArray(T[] array, T el)
          Creates and returns an array that contains all elements of the array parameter and has the el parameter appened.
static
<T> List<List<T>>
allCombinations(List<List<T>> inputs)
          For a given list of list of objects, create and return the (exponential in size) list of list of objects that comes from combining the every element from the first list with every element from the second list etc.
static boolean allInstancesOf(Class<?> clazz, Object[] objs)
          Returns whether all objects are instances of a given class.
static boolean areDisjoint(Set<?>... ss)
          Returns whether the sets are disjoint.
static
<T> List<List<T>>
chunkUp(List<T> list, int maxLength)
          Divides the argument into chunks of at most the given length.
static
<T> List<T>
concat(List<? extends T>... lists)
          Returns an ArrayList that is a concatenation of the arguments.
static
<T> List<T>
concatAll(Collection<? extends List<? extends T>> lists)
          Returns an ArrayList that is a concatenation of the arguments.
static
<T> boolean
containsEquivalent(Collection<T> c, Object o, Hasher h)
          Returns true iff the collection contains an element equivalent to the given one, as decided by the hasher.
static
<T> boolean
containsIdentical(Collection<T> c, Object o)
          Returns true iff the collection contains the element.
static Map<Integer,Set<Object[]>> createPerArityGroups(Object[] objects, int max)
          Creates a set of all sequences of length max of objects.
static
<T> Set<T>
diff(Set<? extends T> s1, Set<? extends T> s2)
           
static SortedSet<Integer> findAll(List<?> list, Object elem)
           
static
<T> Set<T>
getAll(Enumeration<T> e)
           
static
<T> T
getNthIteratedElement(Collection<? extends T> s, int index)
           
static
<T> T
getNthIteratedElement(Iterator<? extends T> iter, int index)
           
static
<T> Set<T>
intersection(Set<? extends T>... sets)
           
static String join(String separator, List<String> strings)
          Reverse of String.split.
static
<T> List<T>
map(List<T> values, Map<T,T> map)
          Maps all values to new values.
static List<String> prefix(String prefix, List<String> lines)
          Adds prefix to each line.
static
<T extends Collection<String>>
T
removeMatching(String pattern, T strings)
          Removed from the collection all strings that match the given pattern.
static
<T> List<T>
roCopyList(Collection<T> l)
          Return a unmodifiable list that has all elements of the given collection.
static List<String> sort(List<String> strings)
          Sort and return the list.
static String toStringInLines(Collection<?> c)
          Prints out the String.valueOf() of all elements of the collection, inserting a new line after each element.
static String toStringInSortedLines(Collection<?> c)
          Prints out the elements of the collection in lines, in lexicographic order of String.valueOf called on each element.
static List<String> toStringLines(Collection<?> c)
          List of String.valueOf() of all elements of the collection.
static
<T> Set<T>
union(Set<? extends T>... sets)
           
static
<T> List<T>
unique(List<T> lst)
          Make a copy of the list with duplicates removed.
static
<T> Set<T>
xor(Set<? extends T> s1, Set<? extends T> s2)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unique

public static <T> List<T> unique(List<T> lst)
Make a copy of the list with duplicates removed. The first elements of each equivalence class will be retained (and in the original order)


roCopyList

public static <T> List<T> roCopyList(Collection<T> l)
Return a unmodifiable list that has all elements of the given collection.


intersection

public static <T> Set<T> intersection(Set<? extends T>... sets)

xor

public static <T> Set<T> xor(Set<? extends T> s1,
                             Set<? extends T> s2)

diff

public static <T> Set<T> diff(Set<? extends T> s1,
                              Set<? extends T> s2)

union

public static <T> Set<T> union(Set<? extends T>... sets)

concat

public static <T> List<T> concat(List<? extends T>... lists)
Returns an ArrayList that is a concatenation of the arguments. Elements of arguments are copied, the argument lists are NOT shared.


concatAll

public static <T> List<T> concatAll(Collection<? extends List<? extends T>> lists)
Returns an ArrayList that is a concatenation of the arguments. Elements of arguments are copied, the argument lists are NOT shared.


getNthIteratedElement

public static <T> T getNthIteratedElement(Collection<? extends T> s,
                                          int index)

getNthIteratedElement

public static <T> T getNthIteratedElement(Iterator<? extends T> iter,
                                          int index)

findAll

public static SortedSet<Integer> findAll(List<?> list,
                                         Object elem)

toStringInLines

public static String toStringInLines(Collection<?> c)
Prints out the String.valueOf() of all elements of the collection, inserting a new line after each element. The order is specified by the collection's iterator.


toStringInSortedLines

public static String toStringInSortedLines(Collection<?> c)
Prints out the elements of the collection in lines, in lexicographic order of String.valueOf called on each element.


toStringLines

public static List<String> toStringLines(Collection<?> c)
List of String.valueOf() of all elements of the collection. The order is specified by the collection's iterator.


sort

public static List<String> sort(List<String> strings)
Sort and return the list. Useful for chaining the call.


chunkUp

public static <T> List<List<T>> chunkUp(List<T> list,
                                        int maxLength)
Divides the argument into chunks of at most the given length. All chunks except at most one will have length exactly maxLength. No chunks are empty. The result list is unmodifiable. It does not copy the list and simply shares it.


getAll

public static <T> Set<T> getAll(Enumeration<T> e)

removeMatching

public static <T extends Collection<String>> T removeMatching(String pattern,
                                                              T strings)
Removed from the collection all strings that match the given pattern. Returns the modified collection, for easier chaining.


join

public static String join(String separator,
                          List<String> strings)
Reverse of String.split. Glues together the strings and inserts the separator between each consecutive pair.


prefix

public static List<String> prefix(String prefix,
                                  List<String> lines)
Adds prefix to each line.


areDisjoint

public static boolean areDisjoint(Set<?>... ss)
Returns whether the sets are disjoint. XXX bogus for empty sets


createPerArityGroups

public static Map<Integer,Set<Object[]>> createPerArityGroups(Object[] objects,
                                                              int max)
Creates a set of all sequences of length max of objects. The order matters and elements may be repeated. The set is grouped by the number of objects in the array. The result is a map from arities to object sequences. NOTE: This is done with arrays rather than lists because in JOE we don't want to execute any code of the objects.


addToArray

public static <T> T[] addToArray(T[] array,
                                 T el)
Creates and returns an array that contains all elements of the array parameter and has the el parameter appened. The runtime type of the resulting array is the same as the type of the argument array.


allInstancesOf

public static boolean allInstancesOf(Class<?> clazz,
                                     Object[] objs)
Returns whether all objects are instances of a given class.


allCombinations

public static <T> List<List<T>> allCombinations(List<List<T>> inputs)
For a given list of list of objects, create and return the (exponential in size) list of list of objects that comes from combining the every element from the first list with every element from the second list etc. Eg for input [[1,2],[a,b]] this returns [[1,a][1,b],[2,a],[2,b]] For empty input, returns a list with one element: empty list. Requires: all lists non-empty


containsIdentical

public static <T> boolean containsIdentical(Collection<T> c,
                                            Object o)
Returns true iff the collection contains the element. Objects are compared by identity (==).


containsEquivalent

public static <T> boolean containsEquivalent(Collection<T> c,
                                             Object o,
                                             Hasher h)
Returns true iff the collection contains an element equivalent to the given one, as decided by the hasher.


map

public static <T> List<T> map(List<T> values,
                              Map<T,T> map)
Maps all values to new values. Returns a new list.