cz.cuni.amis.utils.collections
Class MyCollections

Package class diagram package MyCollections
java.lang.Object
  extended by cz.cuni.amis.utils.collections.MyCollections

public class MyCollections
extends Object


Nested Class Summary
static interface MyCollections.IToString
           
 
Field Summary
static MyCollections.IToString TO_STRING
           
 
Constructor Summary
MyCollections()
           
 
Method Summary
static
<T> List<T>
asList(Collection<T> objects)
           
static
<T> List<T>
asList(Collection<T> objects, IFilter filter)
           
static
<T> List<T>
asList(Collection<T> objects, ObjectFilter filter)
           
static
<T> List<T>
asList(T[] objects, IFilter filter)
           
static
<T> List<T>
asList(T[] objects, ObjectFilter filter)
           
static
<T> List<T>
getFiltered(Collection<T> col, IFilter filter)
          Returns new list that contains only objects from 'col' that are IFilter.isAccepted(Object).
static
<T> T[]
getFiltered(T[] array, IFilter filter)
          Returns new array that contains only objects from 'array' that are IFilter.isAccepted(Object).
static
<T> T
getRandom(Collection<T> col)
          Returns random element from the collection.
static
<T> T
getRandom(List<T> list)
          Returns random element from the list.
static
<T> T
getRandom(T[] array)
          Returns random element from the array.
static
<T> T
getRandomFiltered(Collection<T> col, IFilter filter)
          Returns random element from the collection that is IFilter.isAccepted(Object) by the 'filter'.
static
<T> T
getRandomFiltered(T[] array, IFilter filter)
          Returns random element from the array that is IFilter.isAccepted(Object) by the 'filter'.
static
<T> void
toCollection(T[] array, Collection<T> col)
          Moves data from 'array' to 'col'.
static
<T> List<T>
toList(T... objects)
           
static
<T> void
toList(T[] objects, List<T> list)
          Adds 'objects' to 'list'.
static
<T> void
toList(T[] objects, List<T> list, IFilter filter)
          Adds 'objects' that satisfies 'filter' to 'list'.
static
<T> void
toList(T[] objects, List<T> list, ObjectFilter filter)
          Adds 'objects' that satisfies 'filter' to 'list'.
static String toString(Object objToString, String[] prefixes, String[] postfixes, String[] separators, MyCollections.IToString toString)
           
static String toString(Object obj, String prefix, String postfix, String separator)
           
static String toString(Object obj, String prefix, String postfix, String separator, MyCollections.IToString toString)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO_STRING

public static final MyCollections.IToString TO_STRING
Constructor Detail

MyCollections

public MyCollections()
Method Detail

getFiltered

public static <T> List<T> getFiltered(Collection<T> col,
                                      IFilter filter)
Returns new list that contains only objects from 'col' that are IFilter.isAccepted(Object).

Type Parameters:
T -
Parameters:
col -
filter -
Returns:

getFiltered

public static <T> T[] getFiltered(T[] array,
                                  IFilter filter)
Returns new array that contains only objects from 'array' that are IFilter.isAccepted(Object).

Type Parameters:
T -
Parameters:
col -
filter -
Returns:

getRandom

public static <T> T getRandom(Collection<T> col)
Returns random element from the collection.

WARNING: O(n) time complexity in the worst case scenario!

Type Parameters:
T -
Parameters:
col -
Returns:

getRandom

public static <T> T getRandom(List<T> list)
Returns random element from the list.

O(1) time complexity.

Type Parameters:
T -
Parameters:
list -
Returns:

getRandom

public static <T> T getRandom(T[] array)
Returns random element from the array.

Type Parameters:
T -
Parameters:
array -
Returns:

getRandomFiltered

public static <T> T getRandomFiltered(Collection<T> col,
                                      IFilter filter)
Returns random element from the collection that is IFilter.isAccepted(Object) by the 'filter'.

WARNING: O(n) time complexity in the worst case scenario!

Type Parameters:
T -
Parameters:
col -
filter - if null, performs getRandom(Collection)
Returns:

getRandomFiltered

public static <T> T getRandomFiltered(T[] array,
                                      IFilter filter)
Returns random element from the array that is IFilter.isAccepted(Object) by the 'filter'.

Type Parameters:
T -
Parameters:
array -
Returns:

toList

public static <T> void toList(T[] objects,
                              List<T> list)
Adds 'objects' to 'list'.

Type Parameters:
T -
Parameters:
objects -
list -

toList

public static <T> void toList(T[] objects,
                              List<T> list,
                              ObjectFilter filter)
Adds 'objects' that satisfies 'filter' to 'list'.

Type Parameters:
T -
Parameters:
objects -
list -
filter -

toList

public static <T> void toList(T[] objects,
                              List<T> list,
                              IFilter filter)
Adds 'objects' that satisfies 'filter' to 'list'.

Type Parameters:
T -
Parameters:
objects -
list -
filter -

toList

public static <T> List<T> toList(T... objects)

asList

public static <T> List<T> asList(Collection<T> objects)

asList

public static <T> List<T> asList(T[] objects,
                                 ObjectFilter filter)

asList

public static <T> List<T> asList(Collection<T> objects,
                                 ObjectFilter filter)

asList

public static <T> List<T> asList(T[] objects,
                                 IFilter filter)

asList

public static <T> List<T> asList(Collection<T> objects,
                                 IFilter filter)

toString

public static String toString(Object objToString,
                              String[] prefixes,
                              String[] postfixes,
                              String[] separators,
                              MyCollections.IToString toString)

toString

public static String toString(Object obj,
                              String prefix,
                              String postfix,
                              String separator)

toString

public static String toString(Object obj,
                              String prefix,
                              String postfix,
                              String separator,
                              MyCollections.IToString toString)

toCollection

public static <T> void toCollection(T[] array,
                                    Collection<T> col)
Moves data from 'array' to 'col'. NPE shielded.

Parameters:
array -
col -


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.