|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.neoworks.util.CollectionUtils
Static methods for working with Collections and function blocks.
Method Summary | |
static java.util.Collection |
arrayCollection(java.lang.Object[] array,
java.lang.Class collectionType)
Return a Collection from an array |
static java.util.Collection |
collect(java.util.Collection collection,
OneBlock block)
return a collection containing only the elements from the collection passed which generated the result true when passed to the block. |
static boolean |
detect(java.util.Collection collection,
OneBlock block)
Detect if a collection meets some test. |
static java.util.Collection |
Enumeration2Collection(java.util.Enumeration e)
Put an Enumeration into something useful (a Collection, implemented as an ArrayList) |
static java.util.Collection |
Enumeration2Collection(java.util.Enumeration e,
java.util.Collection c)
Put an Enumeration into a Collection of your choice |
static java.lang.Object |
findFirst(java.util.Collection collection,
OneBlock block)
Find the first value in a collection that meets some test. |
static java.lang.Object |
fold(java.util.Collection collection,
java.lang.Object defaultValue,
TwoBlock block)
This provides a fold function for collections. |
static java.util.Set |
getIntersection(java.util.Collection a,
java.util.Collection b)
Get the intersection of two sets of homogeneous objects |
static java.util.Collection |
map(java.util.Collection collection,
OneBlock block)
Return a collection which is each element in the original collection mapped through the one argument function in the block The one argument block must take an element from the collection as an argument and must return an Object type. |
static java.util.Collection |
quickSort(java.util.Collection collection,
TwoBlock block)
An implementation of Quicksort using medians of 3 for partitions. |
static void |
quickSort(java.lang.Object[] s,
int lo,
int hi,
TwoBlock block)
An implementation of Quicksort using medians of 3 for partitions. |
static boolean |
reject(java.util.Collection collection,
OneBlock block)
Detect if a collection fails some test. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static java.util.Collection Enumeration2Collection(java.util.Enumeration e)
e
- The Enumeration
public static java.util.Collection Enumeration2Collection(java.util.Enumeration e, java.util.Collection c)
e
- The Enumerationc
- The Collection to put the contents of the Enumeration into
public static java.util.Set getIntersection(java.util.Collection a, java.util.Collection b)
a
- The first Collectionb
- The second Collection
Set
A set containing the intersection of the Collectionspublic static java.util.Collection collect(java.util.Collection collection, OneBlock block)
collection
- The input data collectionblock
- The predicate block
public static java.lang.Object fold(java.util.Collection collection, java.lang.Object defaultValue, TwoBlock block)
collection
- The input data collectiondefaultValue
- The initial value to pass to the first call to the blockblock
- The two argument block that folds the input data
public static boolean detect(java.util.Collection collection, OneBlock block)
collection
- The input data collectionblock
- The predicate block
public static boolean reject(java.util.Collection collection, OneBlock block)
collection
- The input data collectionblock
- The predicate block
public static java.lang.Object findFirst(java.util.Collection collection, OneBlock block)
collection
- The input data collectionblock
- The predicate block
public static java.util.Collection map(java.util.Collection collection, OneBlock block)
collection
- The input data collectionblock
- The remapping block
public static java.util.Collection arrayCollection(java.lang.Object[] array, java.lang.Class collectionType)
array
- The input data arraycollectionType
- The type of Collection sub class to create
public static java.util.Collection quickSort(java.util.Collection collection, TwoBlock block)
Collection data = ... ; Collection sorted = Utils.quickSort(data ,new TwoBlock() { public Object value(Object fst, Object snd) {return new Integer(((String)fst).compareTo((String)snd));}});
block
- A two argument block returning an Integer object that compares the two arguments.
It should have the same symantics as the java.lang.Comparable.compareTo() method.collection
- the collection to sort
TwoBlock
public static void quickSort(java.lang.Object[] s, int lo, int hi, TwoBlock block)
String s[] = {"hello","sports","fans"}; Utils.quickSort(s,0,s.length-1,new TwoBlock() { public Object value(Object fst, Object snd) {return new Integer(((String)fst).compareTo((String)snd));}});
s
- the array to sortlo
- the least index to sort fromhi
- the greatest indexblock
- A two argument block returning an Integer object that compares the two arguments.
It should have the same symantics as the java.lang.Comparable.compareTo() method.TwoBlock
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |