|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuk.co.jezuk.mango.Mango
Algorithms, Iterators, Predicates
The Mango Library.
| Method Summary | |
static BinaryPredicate |
And(BinaryPredicate pred1,
BinaryPredicate pred2)
Deprecated. A BinaryPredicate which returns the logical AND of two other BinaryPredicate. |
static Predicate |
And(Predicate pred1,
Predicate pred2)
Deprecated. A Predicate which returns the logical AND of two other Predicate. |
static java.util.Iterator |
ArrayIterator(java.lang.Object[] array)
Deprecated. Iterates over an array of objects. |
static java.util.Iterator |
BoundedIterator(java.util.Iterator iterator,
int start,
int end)
Deprecated. A BoundedIterator enumerates of a subset of a collection, in the
range [start, end). |
static java.util.Iterator |
BoundedIterator(java.util.List list,
int start,
int end)
Deprecated. |
static int |
count(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
Deprecated. |
static int |
count(java.util.Collection collection,
java.lang.Object value)
Deprecated. Count computes the number of elements in the sequence that
are equal to value. |
static int |
count(java.util.Iterator iterator,
java.lang.Object value)
Deprecated. |
static int |
count(java.util.List list,
int start,
int end,
java.lang.Object value)
Deprecated. |
static int |
countIf(java.util.Collection collection,
int start,
int end,
Predicate test)
Deprecated. |
static int |
countIf(java.util.Collection collection,
Predicate test)
Deprecated. CountIf is similar to Count, but more general. |
static int |
countIf(java.util.Iterator iterator,
Predicate test)
Deprecated. |
static int |
countIf(java.util.List list,
int start,
int end,
Predicate test)
Deprecated. |
static BinaryPredicate |
EqualTo()
Deprecated. BinaryPredicate testing for equality. |
static Predicate |
False()
Deprecated. A Predicate which always returns false |
static java.lang.Object |
find(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
Deprecated. |
static java.lang.Object |
find(java.util.Collection collection,
java.lang.Object value)
Deprecated. Searchs the sequence travesed by the Iterator for the given value. |
static java.lang.Object |
find(java.util.Iterator iterator,
java.lang.Object value)
Deprecated. |
static java.lang.Object |
find(java.util.List list,
int start,
int end,
java.lang.Object value)
Deprecated. |
static java.lang.Object |
findIf(java.util.Collection collection,
int start,
int end,
Predicate test)
Deprecated. |
static java.lang.Object |
findIf(java.util.Collection collection,
Predicate test)
Deprecated. Searchs the sequence traversed by the Iterator and returns the first object encountered for which the Predicate returns true. |
static java.lang.Object |
findIf(java.util.Iterator iterator,
Predicate test)
Deprecated. |
static java.lang.Object |
findIf(java.util.List list,
int start,
int end,
Predicate test)
Deprecated. |
static void |
forEach(java.util.Collection collection,
int start,
int end,
UnaryFunction fn)
Deprecated. |
static void |
forEach(java.util.Collection collection,
UnaryFunction fn)
Deprecated. The algorithm ForEach applies the function fn to
each element in the iterator sequence. |
static void |
forEach(java.util.Iterator iterator,
UnaryFunction fn)
Deprecated. |
static void |
forEach(java.util.List list,
int start,
int end,
UnaryFunction fn)
Deprecated. |
static BinaryPredicate |
GreaterThan()
Deprecated. BinaryPredicate that returns true if x is greater than y. |
static BinaryPredicate |
GreaterThanEquals()
Deprecated. BinaryPredicate that returns true if x is greater than or equal to y. |
static BinaryPredicate |
LessThan()
Deprecated. BinaryPredicate that returns true if x is less than y. |
static BinaryPredicate |
LessThanEquals()
Deprecated. BinaryPredicate that returns true if x is less than or equal to y. |
static BinaryPredicate |
Not(BinaryPredicate pred)
Deprecated. A BinaryPredicate which is the logical negation of some other BinaryPredicate. |
static Predicate |
Not(Predicate pred)
Deprecated. A Predicate which is the logical negation of some other Predicate. |
static BinaryPredicate |
NotEqualTo()
Deprecated. true if not(x.equals(y)), (x == null) && not(y == null) or not(x == null) && (y == null) |
static BinaryPredicate |
Or(BinaryPredicate pred1,
BinaryPredicate pred2)
Deprecated. A BinaryPredicate which returns the logical OR of two other BinaryPredicate. |
static Predicate |
Or(Predicate pred1,
Predicate pred2)
Deprecated. A Predicate which returns the logical OR of two other Predicate. |
static java.util.Iterator |
PredicatedIterator(java.util.Iterator iterator,
Predicate predicate)
Deprecated. A PredicatedIterator enumerates only those elements of a collection
that match the supplied Predicate. |
static void |
remove(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
Deprecated. |
static void |
remove(java.util.Collection collection,
java.lang.Object value)
Deprecated. Removes objects equal to value from the sequence. |
static void |
remove(java.util.Iterator iterator,
java.lang.Object value)
Deprecated. |
static void |
remove(java.util.List list,
int start,
int end,
java.lang.Object value)
Deprecated. |
static void |
removeIf(java.util.Collection collection,
int start,
int end,
Predicate pred)
Deprecated. |
static void |
removeIf(java.util.Collection collection,
Predicate pred)
Deprecated. Removes objects which match test from the sequence. |
static void |
removeIf(java.util.Iterator iterator,
Predicate pred)
Deprecated. |
static void |
removeIf(java.util.List list,
int start,
int end,
Predicate pred)
Deprecated. |
static java.util.Iterator |
SingletonIterator(java.lang.Object object)
Deprecated. Iterates over a single object. |
static void |
transform(java.util.Collection collection,
int start,
int end,
UnaryFunction fn,
java.util.Collection results)
Deprecated. |
static void |
transform(java.util.Collection collection,
UnaryFunction fn,
java.util.Collection results)
Deprecated. The algorithm Transform applies the function fn to
each element in the iterator sequence. |
static void |
transform(java.util.Iterator iterator,
UnaryFunction fn,
java.util.Collection results)
Deprecated. |
static void |
transform(java.util.List list,
int start,
int end,
UnaryFunction fn,
java.util.Collection results)
Deprecated. |
static java.util.Iterator |
TransformIterator(java.util.Iterator iterator,
UnaryFunction transform)
Deprecated. A TransfromIterator applies a to
each element in the sequence, returning the the function result at each step. |
static Predicate |
True()
Deprecated. A Predicate which always returns true |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static void forEach(java.util.Collection collection,
UnaryFunction fn)
fn to
each element in the iterator sequence.
public static void forEach(java.util.Collection collection,
int start,
int end,
UnaryFunction fn)
public static void forEach(java.util.List list,
int start,
int end,
UnaryFunction fn)
public static void forEach(java.util.Iterator iterator,
UnaryFunction fn)
public static void transform(java.util.Collection collection,
UnaryFunction fn,
java.util.Collection results)
fn to
each element in the iterator sequence.
The return value of fn is added to the results
collection. If the return value of fn is itself a
collection, then each member of that collection is added to
results.
public static void transform(java.util.Collection collection,
int start,
int end,
UnaryFunction fn,
java.util.Collection results)
public static void transform(java.util.List list,
int start,
int end,
UnaryFunction fn,
java.util.Collection results)
public static void transform(java.util.Iterator iterator,
UnaryFunction fn,
java.util.Collection results)
public static int count(java.util.Collection collection,
java.lang.Object value)
Count computes the number of elements in the sequence that
are equal to value. value may be null.value must be comparable using
Object.equals (unless value is null).
public static int count(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
public static int count(java.util.List list,
int start,
int end,
java.lang.Object value)
public static int count(java.util.Iterator iterator,
java.lang.Object value)
public static int countIf(java.util.Collection collection,
Predicate test)
CountIf is similar to Count, but more general.
It computes the number of elements in the sequence which satisfy some condition.
The condition is a described in the user-supplied test object, and
CountIf computes the number of objects such that test.test(o)
is true.
public static int countIf(java.util.Collection collection,
int start,
int end,
Predicate test)
public static int countIf(java.util.List list,
int start,
int end,
Predicate test)
public static int countIf(java.util.Iterator iterator,
Predicate test)
public static java.lang.Object find(java.util.Collection collection,
java.lang.Object value)
Object, or null if the value
is not found. The iterator will have been advanced to the next object
in the sequence.
The objects in the sequence and value must be comparable using
Object.equals (unless value is null).
public static java.lang.Object find(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
public static java.lang.Object find(java.util.List list,
int start,
int end,
java.lang.Object value)
public static java.lang.Object find(java.util.Iterator iterator,
java.lang.Object value)
public static java.lang.Object findIf(java.util.Collection collection,
Predicate test)
true.
Returns the Object, or null if the value
is not found. The iterator will have been advanced to the next object
in the sequence.
public static java.lang.Object findIf(java.util.Collection collection,
int start,
int end,
Predicate test)
public static java.lang.Object findIf(java.util.List list,
int start,
int end,
Predicate test)
public static java.lang.Object findIf(java.util.Iterator iterator,
Predicate test)
public static void remove(java.util.Collection collection,
java.lang.Object value)
value from the sequence.
public static void remove(java.util.Collection collection,
int start,
int end,
java.lang.Object value)
public static void remove(java.util.List list,
int start,
int end,
java.lang.Object value)
public static void remove(java.util.Iterator iterator,
java.lang.Object value)
public static void removeIf(java.util.Collection collection,
Predicate pred)
test from the sequence.
public static void removeIf(java.util.Collection collection,
int start,
int end,
Predicate pred)
public static void removeIf(java.util.List list,
int start,
int end,
Predicate pred)
public static void removeIf(java.util.Iterator iterator,
Predicate pred)
public static java.util.Iterator BoundedIterator(java.util.Iterator iterator,
int start,
int end)
BoundedIterator enumerates of a subset of a collection, in the
range [start, end).
A conventional java.util.Iterator, obtained by a call to say
java.util.List.iterator(), travels the entire sequence of the
java.util.Collection it points to. It starts at the beginning
and keeps on going until you hit the end or get bored.
A BoundedIterator enumerates of a subset of a collection, in the range [start, end) -
a normal java.util.Iterator traverses [0, collection.size()). A
BoundedIterator therefore allows you to pick out a sub-set without
using list.subList() or equivalent.
public static java.util.Iterator BoundedIterator(java.util.List list,
int start,
int end)
public static java.util.Iterator PredicatedIterator(java.util.Iterator iterator,
Predicate predicate)
PredicatedIterator enumerates only those elements of a collection
that match the supplied Predicate.
It takes a Predicate which encapsulates some test, and only
returns those Objects in the sequence which pass the test.
Say you have a list of Strings, myStringList and you're only
interested in those that begin with 'S'. What you need is
Iterator iter = Mango.PredicatedIterator(myStringList.iterator(),
new Predicate() {
boolean test(Object o) {
String s = (String)o;
return s.charAt(0) == 'S';
}
});
A PredicatedIterator implements the java.util.Iterator interface,
and is constructed by wrapping around an existing iterator.
public static java.util.Iterator ArrayIterator(java.lang.Object[] array)
An ArrayIterator puts a java.util.Iterator face on an
object array, allowing it be treated as you would a java.util.Collection.
public static java.util.Iterator SingletonIterator(java.lang.Object object)
Usually an iterator moves over some sequence. A SingletonIterator treats a
single object as it if it were a list containing one object. Since SingletonIterator
implements the java.util.Iterator interface, it provides a convienent way of
passing a single object to an algorithm or other iterator consumer.
public static java.util.Iterator TransformIterator(java.util.Iterator iterator,
UnaryFunction transform)
TransfromIterator applies a UnaryFunction to
each element in the sequence, returning the the function result at each step.
Say you have a list of some complex type, and you want to find on by name. You could (caution! trivial example follows)
Iterator i = list.iterator();
while(i.hasNext()) {
MyComplexObject mco = (MyComplexObject)i.next();
if(mco.GetName().equals(theSearchName))
.. do something
}
// did I find it or not - do the right thing here
or you could
MyComplexObject mco = (MyComplexObject)Mango.find(
Mango.TransformIterator(list.iterator(),
Adapt.ArgumentMethod("GetName"),
theSearchName);
if(mco != null)
... found!
else
...
public static Predicate True()
Predicate which always returns true
public static Predicate False()
Predicate which always returns false
public static Predicate Not(Predicate pred)
Predicate which is the logical negation of some other Predicate. If n
is a Not object, and pred is the Predicate it was constructed with,
then n.test(x) returns !pred.test(x).
public static Predicate And(Predicate pred1,
Predicate pred2)
Predicate which returns the logical AND of two other Predicate. If a
is an And object, constructed with pred1 and pred2, then
a.test(x) returns pred1.test(x) && pred2.test(x)
public static Predicate Or(Predicate pred1,
Predicate pred2)
Predicate which returns the logical OR of two other Predicate. If a
is an Or object, constructed with pred1 and pred2, then
a.test(x) returns pred1.test(x) || pred2.test(x)
public static BinaryPredicate EqualTo()
BinaryPredicate testing for equality.
true if x.equals(y) or (x == null && y == null)
public static BinaryPredicate GreaterThan()
BinaryPredicate that returns true if x is greater than y.
x and y must implement the java.lang.Comparable interface.
public static BinaryPredicate GreaterThanEquals()
BinaryPredicate that returns true if x is greater than or equal to y.
x and y must implement the java.lang.Comparable interface.
public static BinaryPredicate LessThan()
BinaryPredicate that returns true if x is less than y.
x and y must implement the java.lang.Comparable interface.
public static BinaryPredicate LessThanEquals()
BinaryPredicate that returns true if x is less than or equal to y.
x and y must implement the java.lang.Comparable interface.
public static BinaryPredicate NotEqualTo()
true if not(x.equals(y)), (x == null) && not(y == null) or not(x == null) && (y == null)
public static BinaryPredicate Not(BinaryPredicate pred)
BinaryPredicate which is the logical negation of some other BinaryPredicate. If n
is a Not object, and pred is the Predicate it was constructed with,
then n.test(x,y) returns !pred.test(x,y).
public static BinaryPredicate And(BinaryPredicate pred1,
BinaryPredicate pred2)
BinaryPredicate which returns the logical AND of two other BinaryPredicate. If a
is an And object, constructed with pred1 and pred2, then
a.test(x,y) returns pred1.test(x,y) && pred2.test(x,y)
public static BinaryPredicate Or(BinaryPredicate pred1,
BinaryPredicate pred2)
BinaryPredicate which returns the logical OR of two other BinaryPredicate. If a
is an Or object, constructed with pred1 and pred2, then
a.test(x,y) returns pred1.test(x,y) || pred2.test(x,y)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||