uk.co.jezuk.mango
Class Mango

java.lang.Object
  extended byuk.co.jezuk.mango.Mango

Deprecated. see Algorithms, Iterators, Predicates

public class Mango
extends java.lang.Object

The Mango Library.

Version:
$Id: Mango.java 97 2004-05-26 08:35:52Z jez $
Author:
Jez Higgins, jez@jezuk.co.uk

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 UnaryFunction 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

forEach

public static void forEach(java.util.Collection collection,
                           UnaryFunction fn)
Deprecated. 
The algorithm ForEach applies the function fn to each element in the iterator sequence.


forEach

public static void forEach(java.util.Collection collection,
                           int start,
                           int end,
                           UnaryFunction fn)
Deprecated. 

forEach

public static void forEach(java.util.List list,
                           int start,
                           int end,
                           UnaryFunction fn)
Deprecated. 

forEach

public static void forEach(java.util.Iterator iterator,
                           UnaryFunction fn)
Deprecated. 

transform

public 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. 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.


transform

public static void transform(java.util.Collection collection,
                             int start,
                             int end,
                             UnaryFunction fn,
                             java.util.Collection results)
Deprecated. 

transform

public static void transform(java.util.List list,
                             int start,
                             int end,
                             UnaryFunction fn,
                             java.util.Collection results)
Deprecated. 

transform

public static void transform(java.util.Iterator iterator,
                             UnaryFunction fn,
                             java.util.Collection results)
Deprecated. 

count

public 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.
value may be null.
The objects in the sequence and value must be comparable using Object.equals (unless value is null).


count

public static int count(java.util.Collection collection,
                        int start,
                        int end,
                        java.lang.Object value)
Deprecated. 

count

public static int count(java.util.List list,
                        int start,
                        int end,
                        java.lang.Object value)
Deprecated. 

count

public static int count(java.util.Iterator iterator,
                        java.lang.Object value)
Deprecated. 

countIf

public static int countIf(java.util.Collection collection,
                          Predicate test)
Deprecated. 
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.


countIf

public static int countIf(java.util.Collection collection,
                          int start,
                          int end,
                          Predicate test)
Deprecated. 

countIf

public static int countIf(java.util.List list,
                          int start,
                          int end,
                          Predicate test)
Deprecated. 

countIf

public static int countIf(java.util.Iterator iterator,
                          Predicate test)
Deprecated. 

find

public 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. Returns the 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).


find

public static java.lang.Object find(java.util.Collection collection,
                                    int start,
                                    int end,
                                    java.lang.Object value)
Deprecated. 

find

public static java.lang.Object find(java.util.List list,
                                    int start,
                                    int end,
                                    java.lang.Object value)
Deprecated. 

find

public static java.lang.Object find(java.util.Iterator iterator,
                                    java.lang.Object value)
Deprecated. 

findIf

public 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. Returns the Object, or null if the value is not found. The iterator will have been advanced to the next object in the sequence.


findIf

public static java.lang.Object findIf(java.util.Collection collection,
                                      int start,
                                      int end,
                                      Predicate test)
Deprecated. 

findIf

public static java.lang.Object findIf(java.util.List list,
                                      int start,
                                      int end,
                                      Predicate test)
Deprecated. 

findIf

public static java.lang.Object findIf(java.util.Iterator iterator,
                                      Predicate test)
Deprecated. 

remove

public static void remove(java.util.Collection collection,
                          java.lang.Object value)
Deprecated. 
Removes objects equal to value from the sequence.


remove

public static void remove(java.util.Collection collection,
                          int start,
                          int end,
                          java.lang.Object value)
Deprecated. 

remove

public static void remove(java.util.List list,
                          int start,
                          int end,
                          java.lang.Object value)
Deprecated. 

remove

public static void remove(java.util.Iterator iterator,
                          java.lang.Object value)
Deprecated. 

removeIf

public static void removeIf(java.util.Collection collection,
                            Predicate pred)
Deprecated. 
Removes objects which match test from the sequence.


removeIf

public static void removeIf(java.util.Collection collection,
                            int start,
                            int end,
                            Predicate pred)
Deprecated. 

removeIf

public static void removeIf(java.util.List list,
                            int start,
                            int end,
                            Predicate pred)
Deprecated. 

removeIf

public static void removeIf(java.util.Iterator iterator,
                            Predicate pred)
Deprecated. 

BoundedIterator

public 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).

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.


BoundedIterator

public static java.util.Iterator BoundedIterator(java.util.List list,
                                                 int start,
                                                 int end)
Deprecated. 

PredicatedIterator

public 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.

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.


ArrayIterator

public static java.util.Iterator ArrayIterator(java.lang.Object[] array)
Deprecated. 
Iterates over an array of objects.

An ArrayIterator puts a java.util.Iterator face on an object array, allowing it be treated as you would a java.util.Collection.


SingletonIterator

public static java.util.Iterator SingletonIterator(java.lang.Object object)
Deprecated. 
Iterates over a single 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.


TransformIterator

public static java.util.Iterator TransformIterator(java.util.Iterator iterator,
                                                   UnaryFunction transform)
Deprecated. 
A 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 
       ...
     


True

public static Predicate True()
Deprecated. 
A Predicate which always returns true


False

public static Predicate False()
Deprecated. 
A Predicate which always returns false


Not

public static Predicate Not(Predicate pred)
Deprecated. 
A 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).


And

public static Predicate And(Predicate pred1,
                            Predicate pred2)
Deprecated. 
A 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)


Or

public static Predicate Or(Predicate pred1,
                           Predicate pred2)
Deprecated. 
A 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)


EqualTo

public static BinaryPredicate EqualTo()
Deprecated. 
BinaryPredicate testing for equality. true if x.equals(y) or (x == null && y == null)


GreaterThan

public static BinaryPredicate GreaterThan()
Deprecated. 
BinaryPredicate that returns true if x is greater than y. x and y must implement the java.lang.Comparable interface.


GreaterThanEquals

public static BinaryPredicate GreaterThanEquals()
Deprecated. 
BinaryPredicate that returns true if x is greater than or equal to y. x and y must implement the java.lang.Comparable interface.


LessThan

public static BinaryPredicate LessThan()
Deprecated. 
BinaryPredicate that returns true if x is less than y. x and y must implement the java.lang.Comparable interface.


LessThanEquals

public static BinaryPredicate LessThanEquals()
Deprecated. 
BinaryPredicate that returns true if x is less than or equal to y. x and y must implement the java.lang.Comparable interface.


NotEqualTo

public static BinaryPredicate NotEqualTo()
Deprecated. 
true if not(x.equals(y)), (x == null) && not(y == null) or not(x == null) && (y == null)


Not

public static BinaryPredicate Not(BinaryPredicate pred)
Deprecated. 
A 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).


And

public static BinaryPredicate And(BinaryPredicate pred1,
                                  BinaryPredicate pred2)
Deprecated. 
A 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)


Or

public static BinaryPredicate Or(BinaryPredicate pred1,
                                 BinaryPredicate pred2)
Deprecated. 
A 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)



Copyright © 2002-2006 JezUK Ltd.