|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javautils.collections.Algs
Utility methods for manipulating sequences of elements.
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
filter
find
fold
foldRight
forAll
forEach
forEach
genForEach
forEachInProduct
map
mapMorphism
mapMorphismTo
mapTransform
select
sort
sorted
transform
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.
collect(Iterator)
collectMap(Iterator)
collectSet(Iterator)
addAll(Iterator,Collection)
putAll(Iterator,Map)
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 Iterator
s are very
transparently imperative, which can make their use more difficult.
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
.
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.
String
in a list that
begins with "prefix"
String firstWithPrefix = (String)find
(listOfStrings, newFunction
() { public boolean with(String some) { return some.startsWith("prefix"); }});
public static List allClassesImplementing(List listOfClasses, final Class anInterfaceClass) { returncollect
(filter
(listOfClasses, newFunction
() { public boolean with(Class someClass) { return null != someClass && (someClass.equals(anInterfaceClass) || with(someClass.getSuperclass()) ||exists
(someClass.getInterfaces(), newFunction
(this, "with", Object.class))); }})); }
Integer
sInteger sum = (Integer)fold
(new Integer(0), listOfIntegers, newFunction
() { public int with(int sum, int some) { return sum + some; }});
Integer
s in a list
are positiveboolean allPositive =forAll
(listOfIntegers, newFunction
() { public boolean with(int some) { return some > 0; }});
forEach
(iterator
(points, 0),iterator
(points, 1), newFunction
() { public void with(Point x0, Point x1) { g.drawLine(x0.x, x0.y, x1.x, x1.y); }});
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 |
public static final java.util.List EMPTY_LIST
Empty, unmodifiable list.
public static final java.util.Map EMPTY_MAP
Empty, unmodifiable map.
public static final java.lang.Object[] EMPTY_ARRAY
Empty, unmodifiable array.
public static final java.util.Iterator EMPTY_SEQUENCE
Empty, unmodifiable sequences.
public static final java.util.Set EMPTY_SET
Empty, unmodifiable set.
Constructor Detail |
public Algs()
Method Detail |
public static void addAll(java.util.Iterator from, java.util.Collection to)
Adds all elements from the sequence to the collection.
public static java.util.Iterator allSuperInterfaces(java.lang.Class cls)
An iterator over all super interfaces of the specified class.
public static int[] asArray(java.util.Collection from, int[] to)
Converts a collection of Integer
-objects to an
int
-array.
public static int[] asArray(java.lang.Integer[] from, int[] to)
Converts an array of Integer
-objects to an
int
-array.
public static java.util.Comparator asComparator(Function lessPred)
Converts the binary predicate to a Comparator
.
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.
public static java.util.List collect(java.util.Iterator from)
Collects all elements from the sequence to a new list.
public static java.util.Map collectMap(java.util.Iterator mapEntries)
Collects a sequence of Map.Entry
-objects into a new
map.
public static java.util.Set collectSet(java.util.Iterator from)
Collects all elements from the sequence to a new set.
public static java.util.List collectUnmodifiable(java.util.Iterator from)
Collects all elements into a new unmodifiable list.
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.
public static java.util.Iterator concat(java.util.Collection lhs, java.util.Collection rhs)
public static java.util.Iterator concat(java.lang.Object[] lhs, java.lang.Object[] rhs)
public static java.lang.Object[] copyOf(java.lang.Object[] array)
public static boolean[] copyOf(boolean[] array)
public static byte[] copyOf(byte[] array)
public static char[] copyOf(char[] array)
public static double[] copyOf(double[] array)
public static float[] copyOf(float[] array)
public static int[] copyOf(int[] array)
public static long[] copyOf(long[] array)
public static short[] copyOf(short[] array)
public static java.lang.Object copyOfArray(java.lang.Object array)
A new copy of the given array.
public static java.util.Iterator drop(java.util.Iterator in, int n)
Drops the first n
elements from the sequence.
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.
public static boolean exists(java.util.Iterator in, Function pred)
while (in.hasNext()) if (pred.with(in.next())) return true; return false;
public static boolean exists(java.util.Collection in, Function pred)
public static boolean exists(java.lang.Object[] in, Function pred)
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.
public static java.util.Iterator filter(java.util.Collection from, Function pred)
public static java.util.Iterator filter(java.lang.Object[] from, Function pred)
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;
public static java.lang.Object find(java.util.Collection in, Function pred)
public static java.lang.Object find(java.lang.Object[] in, Function pred)
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.
public static java.util.Iterator flatten(java.util.Collection c)
public static java.util.Iterator flatten(java.lang.Object[] a)
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;
public static java.lang.Object fold(java.lang.Object lhs, java.util.Collection rhs, Function fun)
public static java.lang.Object fold(java.lang.Object lhs, java.lang.Object[] rhs, Function fun)
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;
public static java.lang.Object foldRight(java.util.List lhs, java.lang.Object rhs, Function fun)
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;
public static boolean forAll(java.util.Iterator in, Function pred)
while (in.hasNext()) if (!pred.with(in.next())) return false; return true;
public static boolean forAll(java.util.Collection in, Function pred)
public static boolean forAll(java.lang.Object[] in, Function pred)
public static void forEach(java.util.Iterator in, Function proc)
while (in.hasNext()) proc.with(in.next());
public static void forEach(java.util.Collection in, Function proc)
public static void forEach(java.lang.Object[] in, Function proc)
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());
public static void forEach(java.util.Collection lhs, java.util.Collection rhs, Function proc)
public static void forEach(java.lang.Object[] lhs, java.lang.Object[] rhs, Function proc)
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]);
public static void forEachInProduct(java.util.Iterator lhs, java.util.Iterator rhs, Function proc)
public static void forEachInProduct(java.lang.Object[] lhs, java.lang.Object[] rhs, Function proc)
public static void forEachInProduct(java.util.Iterator lhsI, java.lang.Object[] rhs, Function proc)
public static java.util.Collection genAddAll(java.util.Iterator[] is, java.util.Collection to)
public static java.util.List genConcat(java.util.Collection[] cs)
public static java.util.List genConcat(java.lang.Object[][] cs)
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()]});
public static void genForEach(java.util.Iterator[] is, Function proc)
public static java.lang.Object getOrIfNull(java.util.Map map, java.lang.Object key, java.lang.Object alternative)
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]
public static java.util.Iterator iterator(java.util.Collection c)
public static java.util.Iterator iterator(java.lang.Object[] array)
public static java.util.Iterator iterator(java.lang.Object[] array, int begin)
public static java.util.Iterator iterator(java.lang.Object[] array, int begin, int end)
public static java.util.Iterator iterator(boolean[] array)
public static java.util.Iterator iterator(boolean[] array, int begin)
public static java.util.Iterator iterator(boolean[] array, int begin, int end)
public static java.util.Iterator iterator(byte[] array)
public static java.util.Iterator iterator(byte[] array, int begin)
public static java.util.Iterator iterator(byte[] array, int begin, int end)
public static java.util.Iterator iterator(char[] array)
public static java.util.Iterator iterator(char[] array, int begin)
public static java.util.Iterator iterator(char[] array, int begin, int end)
public static java.util.Iterator iterator(double[] array)
public static java.util.Iterator iterator(double[] array, int begin)
public static java.util.Iterator iterator(double[] array, int begin, int end)
public static java.util.Iterator iterator(float[] array)
public static java.util.Iterator iterator(float[] array, int begin)
public static java.util.Iterator iterator(float[] array, int begin, int end)
public static java.util.Iterator iterator(int[] array)
public static java.util.Iterator iterator(int[] array, int begin)
public static java.util.Iterator iterator(int[] array, int begin, int end)
public static java.util.Iterator iterator(long[] array)
public static java.util.Iterator iterator(long[] array, int begin)
public static java.util.Iterator iterator(long[] array, int begin, int end)
public static java.util.Iterator iterator(short[] array)
public static java.util.Iterator iterator(short[] array, int begin)
public static java.util.Iterator iterator(short[] array, int begin, int end)
public static java.util.Iterator iteratorOverArray(java.lang.Object array, int begin, int end)
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.
public static java.util.Iterator map(java.util.Collection from, Function fun)
public static java.util.Iterator map(java.lang.Object[] from, Function fun)
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.
public static java.util.Iterator map(java.util.Collection lhs, java.util.Collection rhs, Function fun)
public static java.util.Iterator map(java.lang.Object[] lhs, java.lang.Object[] rhs, Function fun)
public static java.util.Map mapMorphism(java.util.Map map, Function fun)
public static void mapMorphismTo(java.util.Map from, Function fun, java.util.Map to)
public static void mapTransform(java.util.Map map, Function fun)
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.
public static java.lang.Comparable max(java.lang.Comparable initial, java.util.Collection s)
public static java.lang.Comparable max(java.lang.Comparable initial, java.lang.Object[] s)
public static double max(double initial, java.util.Collection s)
public static double max(double initial, java.util.Iterator s)
public static int max(int initial, java.util.Collection s)
public static int max(int initial, java.util.Iterator s)
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.
public static java.lang.Comparable min(java.lang.Comparable initial, java.util.Collection s)
public static java.lang.Comparable min(java.lang.Comparable initial, java.lang.Object[] s)
public static double min(double initial, java.util.Collection s)
public static double min(double initial, java.util.Iterator s)
public static int min(int initial, java.util.Collection s)
public static int min(int initial, java.util.Iterator s)
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.
public static java.lang.Object[] newShapedArray(int[] shape, java.lang.Class componentType)
A new 2D-array with the specified shape.
public static java.util.List newUnmodifiableList(java.util.Collection c)
A new unmodifiable list that contains the same elements as the given collection.
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.
public static void putAll(java.util.Iterator mapEntries, java.util.Map to)
Puts a sequence of Map.Entry
-objects to the map.
public static java.util.ListIterator reverseIterator(java.util.List l)
return reverse(l.listIterator(l.size()));
public static java.util.ListIterator reverseIterator(java.util.ListIterator original)
An iterator whose previous
is the next
of the original iterator.
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;
public static java.lang.Object select(java.lang.Object lhs, java.util.Collection rhs, Function pred)
public static java.lang.Object select(java.lang.Object lhs, java.lang.Object[] rhs, Function pred)
public static int sign(int x)
The sign, -1
or 1
of x
or
0
.
public static java.util.Iterator singletonIterator(java.lang.Object o)
public static void sort(java.util.List l, Function lessPred)
Sorts the collection in-place according to the ordering imposed by the predicate.
public static void sort(java.lang.Object[] a, Function lessPred)
Sorts the array in-place according to the ordering imposed by the predicate.
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.
public static java.util.List sorted(java.util.Iterator i, Function lessPred)
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.
public static void transform(java.util.ListIterator i, Function fun)
while (i.hasNext()) i.set(fun.with(i.next()));
public static void transform(java.util.List l, Function fun)
public static void transform(java.lang.Object[] a, Function fun)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |