javautils.collections
Class Algs

java.lang.Object
  |
  +--javautils.collections.Algs
Direct Known Subclasses:
BasicGraph, Graphs, JDBC

public class Algs
extends java.lang.Object

Utility methods for manipulating sequences of elements.

Higher-order methods

Many of the methods in this class are higher-order methods. The intention of higher-order methods is to capture common computational patterns into concrete implementations that are parameterized by anonymous functional objects. Careful use of higher-order order methods can raise the abstraction level of a program significantly. Among many other things, [Abelson1995] discusses a number of higher-order functions in the context of Scheme.

Higher-order methods of the following kind are defined:

exists
Tests whether a predicate holds for at least one element of a sequence.
filter
Filters elements from a sequence to form a new sequence.
find
Finds an element from a sequence.
fold
Perform an arbitrary primitive recursive computation on the elements of a sequence.
foldRight
Perform an arbitrary primitive recursive computation on the elements of a sequence considering values in reverse order.
forAll
Tests whether a predicate holds for all elements of a sequence.
forEach
Perform a procedure for each element of a sequence.
forEach
Perform a procedure simultaneously for each element of two collections.
genForEach
Generalized version of forEach that handles arbitrarily many collections.
forEachInProduct
Perform a procedure for each member (ordered pair) of the cartesian product of two collections.
map
Map each element of a collection to form a new collection.
mapMorphism
Make a morphic copy of the map, with keys and values transformed.
mapMorphismTo
Make a morphic copy of the map, with keys and values transformed, to another map.
mapTransform
Transform each value of a map in place. (The keys are left untouched.)
select
Select an element from a collection.
sort
Sort a list in place.
sorted
Produce a sorted copy of a sequence.
transform
Transform each element of a list in place.

Laziness

Many of the methods in this class are designed to be lazy. For example, the map-method does not immediately call the specified function on every element of the given sequence, but it instead returns a new sequence, as an Iterator, whose traversal performs the operations. The intention behind the laziness is to avoid instantiating collections until it is actually necessary. In many cases it isn't necessary to instantiate a collection at all.

To actually instantiate a sequence into a collection, you can use one of the following methods.

Laziness also makes it possible to manipulate infinite sequences of elements. The lazy iterators used here are similar to lazy streams described in [Abelson1995]. The main difference is that Java Iterators are very transparently imperative, which can make their use more difficult.

Side-effects

Most of the higher-order methods in this class are designed to work with side-effect free functions (?->Object) and predicates (?->Boolean). The higher-order methods that are designed to work with side-effecting procedures (?->Void) are easy to spot, because their result type is void and the functional argument is named proc.

Why should I use higher-order methods instead of loops?

Because the name of the higher-order method immediately communicates the intention of the code at a higher level. For example, the name filter immediately tells that the intention is to select elements from a sequence based on a predicate. Similarly, the name exists immediately tells that the intention is to test whether some property holds for at least one element of a sequence. A loop tells that the code performs iteration, but it does not immediately communicate the intention behind the loop.

Example: Finding the first String in a list that begins with "prefix"

 String firstWithPrefix = (String)
   find(listOfStrings,
        new Function() {
          public boolean with(String some) {
            return some.startsWith("prefix");
          }});
 

Example: A method for filtering all classes from a list that implement the given interface

 public static List allClassesImplementing(List listOfClasses, final Class anInterfaceClass) {
   return collect(filter(listOfClasses,
                         new Function() {
                           public boolean with(Class someClass) {
                             return null != someClass &&
                               (someClass.equals(anInterfaceClass) ||
                                with(someClass.getSuperclass()) ||
                                exists(someClass.getInterfaces(),
                                       new Function(this, "with", Object.class)));
                           }}));
 }
 

Example: Summing a list of Integers

 Integer sum = (Integer)
   fold(new Integer(0),
        listOfIntegers,
        new Function() {
          public int with(int sum, int some) {
            return sum + some;
          }});
 

Example: Testing whether all Integers in a list are positive

 boolean allPositive = forAll(listOfIntegers,
                              new Function() {
                                public boolean with(int some) {
                                  return some > 0;
                                }});
 

Example: Rendering lines between all consecutive pairs of points in an array

 forEach(iterator(points, 0),
         iterator(points, 1),
         new Function() {
           public void with(Point x0, Point x1) {
             g.drawLine(x0.x, x0.y, x1.x, x1.y);
           }});
 

See Also:
Function

Field Summary
static java.lang.Object[] EMPTY_ARRAY
          Empty, unmodifiable array.
static java.util.List EMPTY_LIST
          Empty, unmodifiable list.
static java.util.Map EMPTY_MAP
          Empty, unmodifiable map.
static java.util.Iterator EMPTY_SEQUENCE
          Empty, unmodifiable sequences.
static java.util.Set EMPTY_SET
          Empty, unmodifiable set.
 
Constructor Summary
Algs()
           
 
Method Summary
static void addAll(java.util.Iterator from, java.util.Collection to)
          Adds all elements from the sequence to the collection.
static java.util.Iterator allSuperInterfaces(java.lang.Class cls)
          An iterator over all super interfaces of the specified class.
static int[] asArray(java.util.Collection from, int[] to)
          Converts a collection of Integer-objects to an int-array.
static int[] asArray(java.lang.Integer[] from, int[] to)
          Converts an array of Integer-objects to an int-array.
static java.util.Comparator asComparator(Function lessPred)
          Converts the binary predicate to a Comparator.
static java.util.List asUnmodifiableList(java.lang.Object[] array)
          An unmodifiable list that references the specified arrays.
static java.util.List collect(java.util.Iterator from)
          Collects all elements from the sequence to a new list.
static java.util.Map collectMap(java.util.Iterator mapEntries)
          Collects a sequence of Map.Entry-objects into a new map.
static java.util.Set collectSet(java.util.Iterator from)
          Collects all elements from the sequence to a new set.
static java.util.List collectUnmodifiable(java.util.Iterator from)
          Collects all elements into a new unmodifiable list.
static java.util.Iterator concat(java.util.Collection lhs, java.util.Collection rhs)
           
static java.util.Iterator concat(java.util.Iterator lhs, java.util.Iterator rhs)
          A sequences that first iterates over the lhs sequence and then over the rhs sequence.
static java.util.Iterator concat(java.lang.Object[] lhs, java.lang.Object[] rhs)
           
static boolean[] copyOf(boolean[] array)
           
static byte[] copyOf(byte[] array)
           
static char[] copyOf(char[] array)
           
static double[] copyOf(double[] array)
           
static float[] copyOf(float[] array)
           
static int[] copyOf(int[] array)
           
static long[] copyOf(long[] array)
           
static java.lang.Object[] copyOf(java.lang.Object[] array)
           
static short[] copyOf(short[] array)
           
static java.lang.Object copyOfArray(java.lang.Object array)
          A new copy of the given array.
static java.util.Iterator drop(java.util.Iterator in, int n)
          Drops the first n elements from the sequence.
static java.lang.Object[] ensureLength(java.lang.Object[] a, int length)
          A new array that has the same type as the given array and whose length is exactly the given length or the given array if it has the given length.
static boolean exists(java.util.Collection in, Function pred)
           
static boolean exists(java.util.Iterator in, Function pred)
           while (in.hasNext()) if (pred.with(in.next())) return true; return false;
static boolean exists(java.lang.Object[] in, Function pred)
           
static java.util.Iterator filter(java.util.Collection from, Function pred)
           
static java.util.Iterator filter(java.util.Iterator from, Function pred)
          A sequence of elements that contains the elements from the given sequence for which pred.with(element) is true.
static java.util.Iterator filter(java.lang.Object[] from, Function pred)
           
static java.lang.Object find(java.util.Collection in, Function pred)
           
static java.lang.Object find(java.util.Iterator in, Function pred)
           while (in.hasNext()) { Object o = in.next(); if (pred.with(o)) return o; } return null;
static java.lang.Object find(java.lang.Object[] in, Function pred)
           
static java.util.Iterator flatten(java.util.Collection c)
           
static java.util.Iterator flatten(java.util.Iterator i)
          Flattens the sequence by recursively flattening all collections (of type Collection), arrays (including arrays of primitive types) and sequences (of type Iterator).
static java.util.Iterator flatten(java.lang.Object[] a)
           
static java.lang.Object fold(java.lang.Object lhs, java.util.Collection rhs, Function fun)
           
static java.lang.Object fold(java.lang.Object lhs, java.util.Iterator rhs, Function fun)
           while (rhs.hasNext()) lhs = fun.with(lhs, rhs.next()); return lhs;
static java.lang.Object fold(java.lang.Object lhs, java.lang.Object[] rhs, Function fun)
           
static java.lang.Object foldRight(java.util.ListIterator lhs, java.lang.Object rhs, Function fun)
           while (lhs.hasPrevious()) rhs = fun.with(lhs.previous(), rhs); return rhs;
static java.lang.Object foldRight(java.util.List lhs, java.lang.Object rhs, Function fun)
           
static java.lang.Object foldRight(java.lang.Object[] lhs, java.lang.Object rhs, Function fun)
           for (int i=lhs.length-1; 0<=i; --i) rhs = fun.with(lhs[i], rhs); return rhs;
static boolean forAll(java.util.Collection in, Function pred)
           
static boolean forAll(java.util.Iterator in, Function pred)
           while (in.hasNext()) if (!pred.with(in.next())) return false; return true;
static boolean forAll(java.lang.Object[] in, Function pred)
           
static void forEach(java.util.Collection lhs, java.util.Collection rhs, Function proc)
           
static void forEach(java.util.Collection in, Function proc)
           
static void forEach(java.util.Iterator in, Function proc)
           while (in.hasNext()) proc.with(in.next());
static void forEach(java.util.Iterator lhs, java.util.Iterator rhs, Function proc)
           while (lhs.hasNext() && rhs.hasNext()) proc.with(lhs.next(), rhs.next());
static void forEach(java.lang.Object[] in, Function proc)
           
static void forEach(java.lang.Object[] lhs, java.lang.Object[] rhs, Function proc)
           
static void forEachInProduct(java.util.Collection lhs, java.util.Collection rhs, Function proc)
           proc.with(lhs[0], rhs[0]); proc.with(lhs[0], rhs[1]); ... proc.with(lhs[0], rhs[rhs.size()-1]); proc.with(lhs[1], rhs[0]); proc.with(lhs[1], rhs[1]); ... proc.with(lhs[1], rhs[rhs.size()-1]); ...
static void forEachInProduct(java.util.Iterator lhs, java.util.Iterator rhs, Function proc)
           
static void forEachInProduct(java.util.Iterator lhsI, java.lang.Object[] rhs, Function proc)
           
static void forEachInProduct(java.lang.Object[] lhs, java.lang.Object[] rhs, Function proc)
           
static java.util.Collection genAddAll(java.util.Iterator[] is, java.util.Collection to)
           
static java.util.List genConcat(java.util.Collection[] cs)
           
static java.util.List genConcat(java.lang.Object[][] cs)
           
static void genForEach(java.util.Collection[] cs, Function proc)
           proc.invoke(new Object[]{cs[0][0], cs[1][0], ..., cs[cs.length-1][0]}); proc.invoke(new Object[]{cs[0][1], cs[1][1], ..., cs[cs.length-1][1]}); ...
static void genForEach(java.util.Iterator[] is, Function proc)
           
static java.lang.Object getOrIfNull(java.util.Map map, java.lang.Object key, java.lang.Object alternative)
           
static java.util.Iterator integersInRange(int from, int to)
          Sequence of consecutive integers that starts at from and ends just short of to.
static java.util.Iterator iterator(boolean[] array)
           
static java.util.Iterator iterator(boolean[] array, int begin)
           
static java.util.Iterator iterator(boolean[] array, int begin, int end)
           
static java.util.Iterator iterator(byte[] array)
           
static java.util.Iterator iterator(byte[] array, int begin)
           
static java.util.Iterator iterator(byte[] array, int begin, int end)
           
static java.util.Iterator iterator(char[] array)
           
static java.util.Iterator iterator(char[] array, int begin)
           
static java.util.Iterator iterator(char[] array, int begin, int end)
           
static java.util.Iterator iterator(java.util.Collection c)
           
static java.util.Iterator iterator(double[] array)
           
static java.util.Iterator iterator(double[] array, int begin)
           
static java.util.Iterator iterator(double[] array, int begin, int end)
           
static java.util.Iterator iterator(float[] array)
           
static java.util.Iterator iterator(float[] array, int begin)
           
static java.util.Iterator iterator(float[] array, int begin, int end)
           
static java.util.Iterator iterator(int[] array)
           
static java.util.Iterator iterator(int[] array, int begin)
           
static java.util.Iterator iterator(int[] array, int begin, int end)
           
static java.util.Iterator iterator(long[] array)
           
static java.util.Iterator iterator(long[] array, int begin)
           
static java.util.Iterator iterator(long[] array, int begin, int end)
           
static java.util.Iterator iterator(java.lang.Object[] array)
           
static java.util.Iterator iterator(java.lang.Object[] array, int begin)
           
static java.util.Iterator iterator(java.lang.Object[] array, int begin, int end)
           
static java.util.Iterator iterator(short[] array)
           
static java.util.Iterator iterator(short[] array, int begin)
           
static java.util.Iterator iterator(short[] array, int begin, int end)
           
static java.util.Iterator iteratorOverArray(java.lang.Object array, int begin, int end)
           
static java.util.Iterator map(java.util.Collection lhs, java.util.Collection rhs, Function fun)
           
static java.util.Iterator map(java.util.Collection from, Function fun)
           
static java.util.Iterator map(java.util.Iterator from, Function fun)
          Maps the function to each element of the sequence producing a new sequence.
static java.util.Iterator map(java.util.Iterator lhs, java.util.Iterator rhs, Function fun)
          Maps the function in parallel to elements from the given sequences producing a new sequence.
static java.util.Iterator map(java.lang.Object[] from, Function fun)
           
static java.util.Iterator map(java.lang.Object[] lhs, java.lang.Object[] rhs, Function fun)
           
static java.util.Map mapMorphism(java.util.Map map, Function fun)
           
static void mapMorphismTo(java.util.Map from, Function fun, java.util.Map to)
           
static void mapTransform(java.util.Map map, Function fun)
           
static java.lang.Comparable max(java.lang.Comparable initial, java.util.Collection s)
           
static java.lang.Comparable max(java.lang.Comparable initial, java.util.Iterator s)
          The largest value of a sequence of Comparable-objects larger than the given initial value or the initial value if the collection does not contain larger values.
static java.lang.Comparable max(java.lang.Comparable initial, java.lang.Object[] s)
           
static double max(double initial, java.util.Collection s)
           
static double max(double initial, java.util.Iterator s)
           
static int max(int initial, java.util.Collection s)
           
static int max(int initial, java.util.Iterator s)
           
static java.lang.Comparable min(java.lang.Comparable initial, java.util.Collection s)
           
static java.lang.Comparable min(java.lang.Comparable initial, java.util.Iterator s)
          The smallest value of a sequence of Comparable-objects smaller than the given initial value or the initial value if the collection does not contain smaller values.
static java.lang.Comparable min(java.lang.Comparable initial, java.lang.Object[] s)
           
static double min(double initial, java.util.Collection s)
           
static double min(double initial, java.util.Iterator s)
           
static int min(int initial, java.util.Collection s)
           
static int min(int initial, java.util.Iterator s)
           
static java.util.Map newMap(java.lang.Object[][] table)
          A new map with all bindings of the association table.
static java.lang.Object[] newShapedArray(int[] shape, java.lang.Class componentType)
          A new 2D-array with the specified shape.
static java.util.List newUnmodifiableList(java.util.Collection c)
          A new unmodifiable list that contains the same elements as the given collection.
static void putAll(java.util.Iterator mapEntries, java.util.Map to)
          Puts a sequence of Map.Entry-objects to the map.
static void putAll(java.lang.Object[][] table, java.util.Map to)
          Puts all key-value bindings from the association table to the map.
static java.util.ListIterator reverseIterator(java.util.List l)
           return reverse(l.listIterator(l.size()));
static java.util.ListIterator reverseIterator(java.util.ListIterator original)
          An iterator whose previous is the next of the original iterator.
static java.lang.Object select(java.lang.Object lhs, java.util.Collection rhs, Function pred)
           
static java.lang.Object select(java.lang.Object lhs, java.util.Iterator rhs, Function pred)
           while (rhs.hasNext()) { Object o = rhs.next(); if (pred.with(lhs,o)) lhs = o; } return lhs;
static java.lang.Object select(java.lang.Object lhs, java.lang.Object[] rhs, Function pred)
           
static int sign(int x)
          The sign, -1 or 1 of x or 0.
static java.util.Iterator singletonIterator(java.lang.Object o)
           
static void sort(java.util.List l, Function lessPred)
          Sorts the collection in-place according to the ordering imposed by the predicate.
static void sort(java.lang.Object[] a, Function lessPred)
          Sorts the array in-place according to the ordering imposed by the predicate.
static java.util.List sorted(java.util.Collection c, Function lessPred)
          A sorted copy of the collection according to the ordering imposed by the predicate.
static java.util.List sorted(java.util.Iterator i, Function lessPred)
           
static java.util.Iterator take(java.util.Iterator in, int n)
          A new sequence that only has the first min(n,length(in)) elements of the given sequence.
static void transform(java.util.List l, Function fun)
           
static void transform(java.util.ListIterator i, Function fun)
           while (i.hasNext()) i.set(fun.with(i.next()));
static void transform(java.lang.Object[] a, Function fun)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_LIST

public static final java.util.List EMPTY_LIST

Empty, unmodifiable list.


EMPTY_MAP

public static final java.util.Map EMPTY_MAP

Empty, unmodifiable map.


EMPTY_ARRAY

public static final java.lang.Object[] EMPTY_ARRAY

Empty, unmodifiable array.


EMPTY_SEQUENCE

public static final java.util.Iterator EMPTY_SEQUENCE

Empty, unmodifiable sequences.


EMPTY_SET

public static final java.util.Set EMPTY_SET

Empty, unmodifiable set.

Constructor Detail

Algs

public Algs()
Method Detail

addAll

public static void addAll(java.util.Iterator from,
                          java.util.Collection to)

Adds all elements from the sequence to the collection.


allSuperInterfaces

public static java.util.Iterator allSuperInterfaces(java.lang.Class cls)

An iterator over all super interfaces of the specified class.


asArray

public static int[] asArray(java.util.Collection from,
                            int[] to)

Converts a collection of Integer-objects to an int-array.


asArray

public static int[] asArray(java.lang.Integer[] from,
                            int[] to)

Converts an array of Integer-objects to an int-array.


asComparator

public static java.util.Comparator asComparator(Function lessPred)

Converts the binary predicate to a Comparator.


asUnmodifiableList

public static java.util.List asUnmodifiableList(java.lang.Object[] array)

An unmodifiable list that references the specified arrays. Modifications to the given array will be visible through the list.


collect

public static java.util.List collect(java.util.Iterator from)

Collects all elements from the sequence to a new list.


collectMap

public static java.util.Map collectMap(java.util.Iterator mapEntries)

Collects a sequence of Map.Entry-objects into a new map.


collectSet

public static java.util.Set collectSet(java.util.Iterator from)

Collects all elements from the sequence to a new set.


collectUnmodifiable

public static java.util.List collectUnmodifiable(java.util.Iterator from)

Collects all elements into a new unmodifiable list.


concat

public static java.util.Iterator concat(java.util.Iterator lhs,
                                        java.util.Iterator rhs)

A sequences that first iterates over the lhs sequence and then over the rhs sequence.


concat

public static java.util.Iterator concat(java.util.Collection lhs,
                                        java.util.Collection rhs)

concat

public static java.util.Iterator concat(java.lang.Object[] lhs,
                                        java.lang.Object[] rhs)

copyOf

public static java.lang.Object[] copyOf(java.lang.Object[] array)

copyOf

public static boolean[] copyOf(boolean[] array)

copyOf

public static byte[] copyOf(byte[] array)

copyOf

public static char[] copyOf(char[] array)

copyOf

public static double[] copyOf(double[] array)

copyOf

public static float[] copyOf(float[] array)

copyOf

public static int[] copyOf(int[] array)

copyOf

public static long[] copyOf(long[] array)

copyOf

public static short[] copyOf(short[] array)

copyOfArray

public static java.lang.Object copyOfArray(java.lang.Object array)

A new copy of the given array.


drop

public static java.util.Iterator drop(java.util.Iterator in,
                                      int n)

Drops the first n elements from the sequence.


ensureLength

public static java.lang.Object[] ensureLength(java.lang.Object[] a,
                                              int length)

A new array that has the same type as the given array and whose length is exactly the given length or the given array if it has the given length.


exists

public static boolean exists(java.util.Iterator in,
                             Function pred)
 while (in.hasNext())
   if (pred.with(in.next()))
     return true;
 return false;
 


exists

public static boolean exists(java.util.Collection in,
                             Function pred)

exists

public static boolean exists(java.lang.Object[] in,
                             Function pred)

filter

public static java.util.Iterator filter(java.util.Iterator from,
                                        Function pred)

A sequence of elements that contains the elements from the given sequence for which pred.with(element) is true.


filter

public static java.util.Iterator filter(java.util.Collection from,
                                        Function pred)

filter

public static java.util.Iterator filter(java.lang.Object[] from,
                                        Function pred)

find

public static java.lang.Object find(java.util.Iterator in,
                                    Function pred)
 while (in.hasNext()) {
   Object o = in.next();
   if (pred.with(o))
     return o;
 }
 return null;
 


find

public static java.lang.Object find(java.util.Collection in,
                                    Function pred)

find

public static java.lang.Object find(java.lang.Object[] in,
                                    Function pred)

flatten

public static java.util.Iterator flatten(java.util.Iterator i)

Flattens the sequence by recursively flattening all collections (of type Collection), arrays (including arrays of primitive types) and sequences (of type Iterator).

Note: This method will not work if the given sequence structure contains a cycle. Cycle detection would make this method significantly slower.


flatten

public static java.util.Iterator flatten(java.util.Collection c)

flatten

public static java.util.Iterator flatten(java.lang.Object[] a)

fold

public static java.lang.Object fold(java.lang.Object lhs,
                                    java.util.Iterator rhs,
                                    Function fun)
 while (rhs.hasNext())
   lhs = fun.with(lhs, rhs.next());
 return lhs;
 


fold

public static java.lang.Object fold(java.lang.Object lhs,
                                    java.util.Collection rhs,
                                    Function fun)

fold

public static java.lang.Object fold(java.lang.Object lhs,
                                    java.lang.Object[] rhs,
                                    Function fun)

foldRight

public static java.lang.Object foldRight(java.util.ListIterator lhs,
                                         java.lang.Object rhs,
                                         Function fun)
 while (lhs.hasPrevious())
   rhs = fun.with(lhs.previous(), rhs);
 return rhs;
 


foldRight

public static java.lang.Object foldRight(java.util.List lhs,
                                         java.lang.Object rhs,
                                         Function fun)

foldRight

public static java.lang.Object foldRight(java.lang.Object[] lhs,
                                         java.lang.Object rhs,
                                         Function fun)
 for (int i=lhs.length-1; 0<=i; --i)
   rhs = fun.with(lhs[i], rhs);
 return rhs;
 


forAll

public static boolean forAll(java.util.Iterator in,
                             Function pred)
 while (in.hasNext())
   if (!pred.with(in.next()))
     return false;
 return true;
 


forAll

public static boolean forAll(java.util.Collection in,
                             Function pred)

forAll

public static boolean forAll(java.lang.Object[] in,
                             Function pred)

forEach

public static void forEach(java.util.Iterator in,
                           Function proc)
 while (in.hasNext())
   proc.with(in.next());
 


forEach

public static void forEach(java.util.Collection in,
                           Function proc)

forEach

public static void forEach(java.lang.Object[] in,
                           Function proc)

forEach

public static void forEach(java.util.Iterator lhs,
                           java.util.Iterator rhs,
                           Function proc)
 while (lhs.hasNext() && rhs.hasNext())
   proc.with(lhs.next(), rhs.next());
 


forEach

public static void forEach(java.util.Collection lhs,
                           java.util.Collection rhs,
                           Function proc)

forEach

public static void forEach(java.lang.Object[] lhs,
                           java.lang.Object[] rhs,
                           Function proc)

forEachInProduct

public static void forEachInProduct(java.util.Collection lhs,
                                    java.util.Collection rhs,
                                    Function proc)
 proc.with(lhs[0], rhs[0]);            proc.with(lhs[0], rhs[1]);            ... proc.with(lhs[0], rhs[rhs.size()-1]);
 proc.with(lhs[1], rhs[0]);            proc.with(lhs[1], rhs[1]);            ... proc.with(lhs[1], rhs[rhs.size()-1]);
 ...
 proc.with(lhs[lhs.size()-1], rhs[0]); proc.with(lhs[lhs.size()-1], rhs[1]); ... proc.with(lhs[lhs.size()-1], rhs[rhs.size()-1]);
 


forEachInProduct

public static void forEachInProduct(java.util.Iterator lhs,
                                    java.util.Iterator rhs,
                                    Function proc)

forEachInProduct

public static void forEachInProduct(java.lang.Object[] lhs,
                                    java.lang.Object[] rhs,
                                    Function proc)

forEachInProduct

public static void forEachInProduct(java.util.Iterator lhsI,
                                    java.lang.Object[] rhs,
                                    Function proc)

genAddAll

public static java.util.Collection genAddAll(java.util.Iterator[] is,
                                             java.util.Collection to)

genConcat

public static java.util.List genConcat(java.util.Collection[] cs)

genConcat

public static java.util.List genConcat(java.lang.Object[][] cs)

genForEach

public static void genForEach(java.util.Collection[] cs,
                              Function proc)
 proc.invoke(new Object[]{cs[0][0],              cs[1][0],              ..., cs[cs.length-1][0]});
 proc.invoke(new Object[]{cs[0][1],              cs[1][1],              ..., cs[cs.length-1][1]});
 ...
 proc.invoke(new Object[]{cs[0][cs[min].size()], cs[1][cs[min].size()], ..., cs[cs.length-1][cs[min].size()]});
 


genForEach

public static void genForEach(java.util.Iterator[] is,
                              Function proc)

getOrIfNull

public static java.lang.Object getOrIfNull(java.util.Map map,
                                           java.lang.Object key,
                                           java.lang.Object alternative)

integersInRange

public static java.util.Iterator integersInRange(int from,
                                                 int to)

Sequence of consecutive integers that starts at from and ends just short of to. For example:

 integersInRange(75,75) => []
 integersInRange(3,7) => [3,4,5,6]
 integersInRange(1,-3) => [1,0,-1,-2]
 


iterator

public static java.util.Iterator iterator(java.util.Collection c)

iterator

public static java.util.Iterator iterator(java.lang.Object[] array)

iterator

public static java.util.Iterator iterator(java.lang.Object[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(java.lang.Object[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(boolean[] array)

iterator

public static java.util.Iterator iterator(boolean[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(boolean[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(byte[] array)

iterator

public static java.util.Iterator iterator(byte[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(byte[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(char[] array)

iterator

public static java.util.Iterator iterator(char[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(char[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(double[] array)

iterator

public static java.util.Iterator iterator(double[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(double[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(float[] array)

iterator

public static java.util.Iterator iterator(float[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(float[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(int[] array)

iterator

public static java.util.Iterator iterator(int[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(int[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(long[] array)

iterator

public static java.util.Iterator iterator(long[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(long[] array,
                                          int begin,
                                          int end)

iterator

public static java.util.Iterator iterator(short[] array)

iterator

public static java.util.Iterator iterator(short[] array,
                                          int begin)

iterator

public static java.util.Iterator iterator(short[] array,
                                          int begin,
                                          int end)

iteratorOverArray

public static java.util.Iterator iteratorOverArray(java.lang.Object array,
                                                   int begin,
                                                   int end)

map

public static java.util.Iterator map(java.util.Iterator from,
                                     Function fun)

Maps the function to each element of the sequence producing a new sequence.


map

public static java.util.Iterator map(java.util.Collection from,
                                     Function fun)

map

public static java.util.Iterator map(java.lang.Object[] from,
                                     Function fun)

map

public static java.util.Iterator map(java.util.Iterator lhs,
                                     java.util.Iterator rhs,
                                     Function fun)

Maps the function in parallel to elements from the given sequences producing a new sequence.


map

public static java.util.Iterator map(java.util.Collection lhs,
                                     java.util.Collection rhs,
                                     Function fun)

map

public static java.util.Iterator map(java.lang.Object[] lhs,
                                     java.lang.Object[] rhs,
                                     Function fun)

mapMorphism

public static java.util.Map mapMorphism(java.util.Map map,
                                        Function fun)

mapMorphismTo

public static void mapMorphismTo(java.util.Map from,
                                 Function fun,
                                 java.util.Map to)

mapTransform

public static void mapTransform(java.util.Map map,
                                Function fun)

max

public static java.lang.Comparable max(java.lang.Comparable initial,
                                       java.util.Iterator s)

The largest value of a sequence of Comparable-objects larger than the given initial value or the initial value if the collection does not contain larger values.


max

public static java.lang.Comparable max(java.lang.Comparable initial,
                                       java.util.Collection s)

max

public static java.lang.Comparable max(java.lang.Comparable initial,
                                       java.lang.Object[] s)

max

public static double max(double initial,
                         java.util.Collection s)

max

public static double max(double initial,
                         java.util.Iterator s)

max

public static int max(int initial,
                      java.util.Collection s)

max

public static int max(int initial,
                      java.util.Iterator s)

min

public static java.lang.Comparable min(java.lang.Comparable initial,
                                       java.util.Iterator s)

The smallest value of a sequence of Comparable-objects smaller than the given initial value or the initial value if the collection does not contain smaller values.


min

public static java.lang.Comparable min(java.lang.Comparable initial,
                                       java.util.Collection s)

min

public static java.lang.Comparable min(java.lang.Comparable initial,
                                       java.lang.Object[] s)

min

public static double min(double initial,
                         java.util.Collection s)

min

public static double min(double initial,
                         java.util.Iterator s)

min

public static int min(int initial,
                      java.util.Collection s)

min

public static int min(int initial,
                      java.util.Iterator s)

newMap

public static java.util.Map newMap(java.lang.Object[][] table)

A new map with all bindings of the association table.

The last element of each row of the association table is the value to which all the other elements on the row are mapped to.


newShapedArray

public static java.lang.Object[] newShapedArray(int[] shape,
                                                java.lang.Class componentType)

A new 2D-array with the specified shape.


newUnmodifiableList

public static java.util.List newUnmodifiableList(java.util.Collection c)

A new unmodifiable list that contains the same elements as the given collection.


putAll

public static void putAll(java.lang.Object[][] table,
                          java.util.Map to)

Puts all key-value bindings from the association table to the map.

The last element of each row of the association table is the value to which all the other elements on the row are mapped to.


putAll

public static void putAll(java.util.Iterator mapEntries,
                          java.util.Map to)

Puts a sequence of Map.Entry-objects to the map.


reverseIterator

public static java.util.ListIterator reverseIterator(java.util.List l)
 return reverse(l.listIterator(l.size()));
 


reverseIterator

public static java.util.ListIterator reverseIterator(java.util.ListIterator original)

An iterator whose previous is the next of the original iterator.


select

public static java.lang.Object select(java.lang.Object lhs,
                                      java.util.Iterator rhs,
                                      Function pred)
 while (rhs.hasNext()) {
   Object o = rhs.next();
   if (pred.with(lhs,o))
     lhs = o;
 }
 return lhs;
 


select

public static java.lang.Object select(java.lang.Object lhs,
                                      java.util.Collection rhs,
                                      Function pred)

select

public static java.lang.Object select(java.lang.Object lhs,
                                      java.lang.Object[] rhs,
                                      Function pred)

sign

public static int sign(int x)

The sign, -1 or 1 of x or 0.


singletonIterator

public static java.util.Iterator singletonIterator(java.lang.Object o)

sort

public static void sort(java.util.List l,
                        Function lessPred)

Sorts the collection in-place according to the ordering imposed by the predicate.


sort

public static void sort(java.lang.Object[] a,
                        Function lessPred)

Sorts the array in-place according to the ordering imposed by the predicate.


sorted

public static java.util.List sorted(java.util.Collection c,
                                    Function lessPred)

A sorted copy of the collection according to the ordering imposed by the predicate.


sorted

public static java.util.List sorted(java.util.Iterator i,
                                    Function lessPred)

take

public static java.util.Iterator take(java.util.Iterator in,
                                      int n)

A new sequence that only has the first min(n,length(in)) elements of the given sequence.


transform

public static void transform(java.util.ListIterator i,
                             Function fun)
 while (i.hasNext())
   i.set(fun.with(i.next()));
 


transform

public static void transform(java.util.List l,
                             Function fun)

transform

public static void transform(java.lang.Object[] a,
                             Function fun)