|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectinfo.javelot.functionalj.tuple.Tuples
Contains static methods to zip and unzip tuples. These are:
Zipping consists of creating a list of tuples from a number of collections, creating each tuple by taking corresponding elements from the collections. For example:
zip([1,2,3,4],[5,6,7,8],[9,10,11,12])
returns
[(1,5,9),(2,6,10),(3,7,11),(4,8,12)]
where each element in the resulting list is a Triple.
Unzipping consists of returning a tuple of collections from a collection
of tuples, thus reversing the zipping operation. Unzipping the result of the
previous example would return a Triple containing the original
collections.
The zipWith methods provide a more general mechanism, where the
function used to zip corresponding elements from the collections can be
specified as a parameter. For example:
Function2 add = Operators.add;
List list1 = Lists.asList(new int[] {1, 2, 3, 4});
List list2 = Lists.asList(new int[] {5, 6, 7, 8});
List results = Tuples.zipWith(add, list1, list2);
//results contains [6, 8, 10, 12].
| Method Summary | |
static Pair |
unzipPairs(Collection p_coll)
Unzips a collection of Pairs into a Pair of lists, with the
first list containing all of the first elements of the pairs, and the second
list containing all of the second elements of the pairs. |
static Pair |
unzipPairs(Pair[] p_pairs)
Unzips an array of Pairs into a Pair of lists, similarily to
the unzipPairs(Collection) method. |
static Quadruple |
unzipQuadruples(Collection p_coll)
Unzips a collection of Quadruples into a Quadruple of lists,
similarily to the unzipPairs(Collection) method. |
static Quadruple |
unzipQuadruples(Quadruple[] p_quadruples)
Unzips an array of Quadruples into a Quadruple of lists,
similarily to the unzipPairs(Collection) method. |
static Triple |
unzipTriples(Collection p_coll)
Unzips a collection of Triples into a Triple of lists,
similarily to the unzipPairs(Collection) method. |
static Triple |
unzipTriples(Triple[] p_triples)
Unzips an array of Triples into a Triple of lists, similarily
to the unzipPairs(Collection) method. |
static List |
zip(Collection p_coll1,
Collection p_coll2)
Zips objects from the two collections to return a list of Pairs. |
static List |
zip(Collection p_coll1,
Collection p_coll2,
Collection p_coll3)
Zips objects from the three collections to return a list of Triples,
similarily to the zip(Collection, Collection) method. |
static List |
zip(Collection p_coll1,
Collection p_coll2,
Collection p_coll3,
Collection p_coll4)
Zips objects from the four collections to return a list of Quadruples,
similarily to the zip(Collection, Collection) method. |
static List |
zip(Object[] p_array1,
Object[] p_array2)
Zips objects from the two arrays to return a list of Pairs, similarily
to the zip(Collection,Collection) method. |
static List |
zip(Object[] p_array1,
Object[] p_array2,
Object[] p_array3)
Zips objects from the three arrays to return a list of Triples,
similarily to the zip(Collection,Collection) method. |
static List |
zip(Object[] p_array1,
Object[] p_array2,
Object[] p_array3,
Object[] p_array4)
Zips objects from the four arrays to return a list of Quadruples,
similarily to the zip(Collection, Collection) method. |
static List |
zipWith(Function1 p_function1,
Collection[] p_colls)
Zips objects from the collections to return a list of objects returned by the specified function. |
static List |
zipWith(Function2 p_function2,
Collection p_coll1,
Collection p_coll2)
Zips objects from the two collections to return a list of objects returned by the specified function. |
static List |
zipWith(Function2 p_function2,
Object[] p_array1,
Object[] p_array2)
Zips objects from the two arrays to return a list of objects returned by the specified function. |
static List |
zipWith(Function3 p_function3,
Collection p_coll1,
Collection p_coll2,
Collection p_coll3)
Zips objects from the three collections to return a list of objects returned by the specified function. |
static List |
zipWith(Function3 p_function3,
Object[] p_array1,
Object[] p_array2,
Object[] p_array3)
Zips objects from the three arrays to return a list of objects returned by the specified function. |
static List |
zipWith(Function4 p_function4,
Collection p_coll1,
Collection p_coll2,
Collection p_coll3,
Collection p_coll4)
Zips objects from the four collections to return a list of objects returned by the specified function. |
static List |
zipWith(Function4 p_function4,
Object[] p_array1,
Object[] p_array2,
Object[] p_array3,
Object[] p_array4)
Zips objects from the four arrays to return a list of objects returned by the specified function. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static List zip(Collection p_coll1,
Collection p_coll2)
Pairs.
This method calls zipWith(Function2, Collection, Collection), passing
the Pair.pair function and the two collections. If the collections
contain an unequal number of objects, the number of Pairs returned is
equal to the number of objects contained in the smaller of the two
collections.
p_coll1 - the first of the two collections of objects to zip.p_coll2 - the second of the two collections of objects to zip.
Pairs.
public static List zip(Collection p_coll1,
Collection p_coll2,
Collection p_coll3)
Triples,
similarily to the zip(Collection, Collection) method.
public static List zip(Collection p_coll1,
Collection p_coll2,
Collection p_coll3,
Collection p_coll4)
Quadruples,
similarily to the zip(Collection, Collection) method.
public static List zip(Object[] p_array1,
Object[] p_array2)
Pairs, similarily
to the zip(Collection,Collection) method.
public static List zip(Object[] p_array1,
Object[] p_array2,
Object[] p_array3)
Triples,
similarily to the zip(Collection,Collection) method.
public static List zip(Object[] p_array1,
Object[] p_array2,
Object[] p_array3,
Object[] p_array4)
Quadruples,
similarily to the zip(Collection, Collection) method.
public static List zipWith(Function2 p_function2,
Collection p_coll1,
Collection p_coll2)
zipWith(Function1, Collection[]) method
for more details.
zipWith(Function1, Collection[])
public static List zipWith(Function3 p_function3,
Collection p_coll1,
Collection p_coll2,
Collection p_coll3)
zipWith(Function1, Collection[])
method for more details.
zipWith(Function1, Collection[])
public static List zipWith(Function4 p_function4,
Collection p_coll1,
Collection p_coll2,
Collection p_coll3,
Collection p_coll4)
zipWith(Function1, Collection[]) method
for more details.
zipWith(Function1, Collection[])
public static List zipWith(Function1 p_function1,
Collection[] p_colls)
p_function1 - the function used to zip the objects.p_colls - the collections of objects to zip.
public static List zipWith(Function2 p_function2,
Object[] p_array1,
Object[] p_array2)
zipWith(Function1, Collection[]) method for
more details.
zipWith(Function1, Collection[])
public static List zipWith(Function3 p_function3,
Object[] p_array1,
Object[] p_array2,
Object[] p_array3)
zipWith(Function1, Collection[]) method for
more details.
zipWith(Function1, Collection[])
public static List zipWith(Function4 p_function4,
Object[] p_array1,
Object[] p_array2,
Object[] p_array3,
Object[] p_array4)
zipWith(Function1, Collection[]) method for
more details.
zipWith(Function1, Collection[])public static Pair unzipPairs(Collection p_coll)
Pairs into a Pair of lists, with the
first list containing all of the first elements of the pairs, and the second
list containing all of the second elements of the pairs.
p_coll - the collection of Pairs to be unzipped.
Pair containing two lists, one of the first elements of the
pairs, and one of the second elements of the pairs.public static Triple unzipTriples(Collection p_coll)
Triples into a Triple of lists,
similarily to the unzipPairs(Collection) method.
unzipPairs(Collection)public static Quadruple unzipQuadruples(Collection p_coll)
Quadruples into a Quadruple of lists,
similarily to the unzipPairs(Collection) method.
unzipPairs(Collection)public static Pair unzipPairs(Pair[] p_pairs)
Pairs into a Pair of lists, similarily to
the unzipPairs(Collection) method.
unzipPairs(Collection)public static Triple unzipTriples(Triple[] p_triples)
Triples into a Triple of lists, similarily
to the unzipPairs(Collection) method.
unzipPairs(Collection)public static Quadruple unzipQuadruples(Quadruple[] p_quadruples)
Quadruples into a Quadruple of lists,
similarily to the unzipPairs(Collection) method.
unzipPairs(Collection)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||