uk.co.jezuk.mango
Class Algorithms

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

public class Algorithms
extends java.lang.Object

The Mango Algorithms Library.

Version:
$Id: Algorithms.java 115 2006-09-28 21:18:09Z jez $
Author:
Jez Higgins, jez@jezuk.co.uk

Method Summary
static int count(java.util.Collection collection, int start, int end, java.lang.Object value)
           
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.
static int count(java.util.Iterator iterator, java.lang.Object value)
           
static int count(java.util.List list, int start, int end, java.lang.Object value)
           
static int countIf(java.util.Collection collection, int start, int end, Predicate test)
           
static int countIf(java.util.Collection collection, Predicate test)
          CountIf is similar to Count, but more general.
static int countIf(java.util.Iterator iterator, Predicate test)
           
static int countIf(java.util.List list, int start, int end, Predicate test)
           
static int countIfNot(java.util.Collection collection, int start, int end, Predicate test)
           
static int countIfNot(java.util.Collection collection, Predicate test)
          CountIfNot is the complement of CountIf.
static int countIfNot(java.util.Iterator iterator, Predicate test)
           
static int countIfNot(java.util.List list, int start, int end, Predicate test)
           
static java.lang.Object find(java.util.Collection collection, int start, int end, java.lang.Object value)
           
static java.lang.Object find(java.util.Collection collection, java.lang.Object value)
          Searchs the sequence travesed by the Iterator for the given value.
static java.lang.Object find(java.util.Iterator iterator, java.lang.Object value)
           
static java.lang.Object find(java.util.List list, int start, int end, java.lang.Object value)
           
static java.lang.Object findIf(java.util.Collection collection, int start, int end, Predicate test)
           
static java.lang.Object findIf(java.util.Collection collection, Predicate test)
          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)
           
static java.lang.Object findIf(java.util.List list, int start, int end, Predicate test)
           
static java.lang.Object findIfNot(java.util.Collection collection, int start, int end, Predicate test)
           
static java.lang.Object findIfNot(java.util.Collection collection, Predicate test)
          Searchs the sequence traversed by the Iterator and returns the first object encountered for which the Predicate returns false.
static java.lang.Object findIfNot(java.util.Iterator iterator, Predicate test)
           
static java.lang.Object findIfNot(java.util.List list, int start, int end, Predicate test)
           
static int findPosition(java.util.Collection collection, int start, int end, java.lang.Object value)
           
static int findPosition(java.util.Collection collection, java.lang.Object value)
          Searchs the sequence travesed by the Iterator for the given value.
static int findPosition(java.util.Iterator iterator, java.lang.Object value)
           
static int findPosition(java.util.List list, int start, int end, java.lang.Object value)
           
static int findPositionIf(java.util.Collection collection, int start, int end, Predicate pred)
           
static int findPositionIf(java.util.Collection collection, Predicate pred)
           
static int findPositionIf(java.util.Iterator iterator, Predicate pred)
           
static int findPositionIf(java.util.List list, int start, int end, Predicate pred)
           
static void forEach(java.util.Collection collection, int start, int end, UnaryFunction fn)
           
static void forEach(java.util.Collection collection, UnaryFunction fn)
          The algorithm ForEach applies the function fn to each element in the iterator sequence.
static void forEach(java.util.Iterator iterator, UnaryFunction fn)
           
static void forEach(java.util.List list, int start, int end, UnaryFunction fn)
           
static java.util.Collection intersection(java.util.Collection coll1, java.util.Collection coll2, java.util.Collection results)
          Algorithm intersection finds the common elements in both collections See http://en.wikipedia.org/wiki/Intersection_(set_theory)
static java.util.Collection intersection(java.util.Iterator iter1, java.util.Collection coll2, java.util.Collection results)
           
static java.util.Collection intersection(java.util.Iterator iter1, java.util.Iterator iter2, java.util.Collection results)
           
static java.util.Collection partition(java.util.Collection collection, int start, int end, Predicate pred, java.util.Collection results)
           
static java.util.Collection partition(java.util.Collection collection, Predicate pred, java.util.Collection results)
          Partitions the supplied collections into two.
static java.util.Collection partition(java.util.Iterator iterator, Predicate pred, java.util.Collection results)
           
static java.util.Collection partition(java.util.List list, int start, int end, Predicate pred, java.util.Collection results)
           
static void remove(java.util.Collection collection, int start, int end, java.lang.Object value)
           
static void remove(java.util.Collection collection, java.lang.Object value)
          Removes objects equal to value from the sequence.
static void remove(java.util.Iterator iterator, java.lang.Object value)
           
static void remove(java.util.List list, int start, int end, java.lang.Object value)
           
static void removeIf(java.util.Collection collection, int start, int end, Predicate pred)
           
static void removeIf(java.util.Collection collection, Predicate pred)
          Removes objects which match test from the sequence.
static void removeIf(java.util.Iterator iterator, Predicate pred)
           
static void removeIf(java.util.List list, int start, int end, Predicate pred)
           
static java.util.Collection symmetricDifference(java.util.Collection coll1, java.util.Collection coll2, java.util.Collection results)
          Algorithm symmetricDifference returns the elements that are on coll1 and not in coll2, and those elements in coll2 that are not in coll1.
static java.util.Collection symmetricDifference(java.util.Iterator iter1, java.util.Collection coll2, java.util.Collection results)
           
static java.util.Collection symmetricDifference(java.util.Iterator iter1, java.util.Iterator iter2, java.util.Collection results)
           
static java.util.Collection transform(java.util.Collection collection, int start, int end, UnaryFunction fn, java.util.Collection results)
           
static java.util.Collection transform(java.util.Collection collection, UnaryFunction fn, java.util.Collection results)
          The algorithm Transform applies the function fn to each element in the iterator sequence.
static java.util.Collection transform(java.util.Iterator iterator, UnaryFunction fn, java.util.Collection results)
           
static java.util.Collection transform(java.util.List list, int start, int end, UnaryFunction fn, java.util.Collection results)
           
static void unique(java.util.Collection collection)
          Removes duplicate elements.
static void unique(java.util.Collection collection, java.util.Comparator comparator)
           
static void unique(java.util.Collection collection, int start, int end)
           
static void unique(java.util.Collection collection, int start, int end, java.util.Comparator comparator)
           
static void unique(java.util.Iterator iterator)
           
static void unique(java.util.Iterator iterator, java.util.Comparator comparator)
           
static void unique(java.util.List list, int start, int end)
           
static void unique(java.util.List list, int start, int end, java.util.Comparator comparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

intersection

public static java.util.Collection intersection(java.util.Collection coll1,
                                                java.util.Collection coll2,
                                                java.util.Collection results)
Algorithm intersection finds the common elements in both collections See http://en.wikipedia.org/wiki/Intersection_(set_theory)


intersection

public static java.util.Collection intersection(java.util.Iterator iter1,
                                                java.util.Collection coll2,
                                                java.util.Collection results)

intersection

public static java.util.Collection intersection(java.util.Iterator iter1,
                                                java.util.Iterator iter2,
                                                java.util.Collection results)

symmetricDifference

public static java.util.Collection symmetricDifference(java.util.Collection coll1,
                                                       java.util.Collection coll2,
                                                       java.util.Collection results)
Algorithm symmetricDifference returns the elements that are on coll1 and not in coll2, and those elements in coll2 that are not in coll1. See http://en.wikipedia.org/wiki/Symmetric_difference


symmetricDifference

public static java.util.Collection symmetricDifference(java.util.Iterator iter1,
                                                       java.util.Collection coll2,
                                                       java.util.Collection results)

symmetricDifference

public static java.util.Collection symmetricDifference(java.util.Iterator iter1,
                                                       java.util.Iterator iter2,
                                                       java.util.Collection results)

forEach

public static void forEach(java.util.Collection collection,
                           UnaryFunction fn)
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)

forEach

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

forEach

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

transform

public static java.util.Collection transform(java.util.Collection collection,
                                             UnaryFunction fn,
                                             java.util.Collection results)
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 java.util.Collection transform(java.util.Collection collection,
                                             int start,
                                             int end,
                                             UnaryFunction fn,
                                             java.util.Collection results)

transform

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

transform

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

count

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

count

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

count

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

countIf

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.


countIf

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

countIf

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

countIf

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

countIfNot

public static int countIfNot(java.util.Collection collection,
                             Predicate test)
CountIfNot is the complement of CountIf. It counts the number of elements in the sequence which fail some condition. The condition is a described in the user-supplied test object, and CountIfNot computes the number of objects such that test.test(o) is false.


countIfNot

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

countIfNot

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

countIfNot

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

find

public static java.lang.Object find(java.util.Collection collection,
                                    java.lang.Object value)
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)

find

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

find

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

findPosition

public static int findPosition(java.util.Collection collection,
                               java.lang.Object value)
Searchs the sequence travesed by the Iterator for the given value. Returns the index of the value in the collection, or -1 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).


findPosition

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

findPosition

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

findPosition

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

findPositionIf

public static int findPositionIf(java.util.Collection collection,
                                 Predicate pred)

findPositionIf

public static int findPositionIf(java.util.Collection collection,
                                 int start,
                                 int end,
                                 Predicate pred)

findPositionIf

public static int findPositionIf(java.util.List list,
                                 int start,
                                 int end,
                                 Predicate pred)

findPositionIf

public static int findPositionIf(java.util.Iterator iterator,
                                 Predicate pred)

findIf

public static java.lang.Object findIf(java.util.Collection collection,
                                      Predicate test)
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)

findIf

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

findIf

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

findIfNot

public static java.lang.Object findIfNot(java.util.Collection collection,
                                         Predicate test)
Searchs the sequence traversed by the Iterator and returns the first object encountered for which the Predicate returns false. The iterator will have been advanced to the next object in the sequence.


findIfNot

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

findIfNot

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

findIfNot

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

remove

public static void remove(java.util.Collection collection,
                          java.lang.Object value)
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)

remove

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

remove

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

removeIf

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


removeIf

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

removeIf

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

removeIf

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

partition

public static java.util.Collection partition(java.util.Collection collection,
                                             Predicate pred,
                                             java.util.Collection results)
Partitions the supplied collections into two. Objects matching the Predicate are removed from the collection and added to the results Collection. Returns the result collection.


partition

public static java.util.Collection partition(java.util.Collection collection,
                                             int start,
                                             int end,
                                             Predicate pred,
                                             java.util.Collection results)

partition

public static java.util.Collection partition(java.util.List list,
                                             int start,
                                             int end,
                                             Predicate pred,
                                             java.util.Collection results)

partition

public static java.util.Collection partition(java.util.Iterator iterator,
                                             Predicate pred,
                                             java.util.Collection results)

unique

public static void unique(java.util.Collection collection)
Removes duplicate elements. Whenever a consecutive groups of duplicate objects occur in the sequence, unique removes all but the first objects in each group. iterator must support the remove method.

See Also:
Iterator, Comparator

unique

public static void unique(java.util.Collection collection,
                          int start,
                          int end)

unique

public static void unique(java.util.List list,
                          int start,
                          int end)

unique

public static void unique(java.util.Iterator iterator)

unique

public static void unique(java.util.Collection collection,
                          java.util.Comparator comparator)

unique

public static void unique(java.util.Collection collection,
                          int start,
                          int end,
                          java.util.Comparator comparator)

unique

public static void unique(java.util.List list,
                          int start,
                          int end,
                          java.util.Comparator comparator)

unique

public static void unique(java.util.Iterator iterator,
                          java.util.Comparator comparator)


Copyright © 2002-2006 JezUK Ltd.