uk.co.jezuk.mango
Class Algorithms

java.lang.Object
  extended by uk.co.jezuk.mango.Algorithms

public class Algorithms
extends java.lang.Object

The Mango Library Algorithms

Author:
Jez Higgins, jez@jezuk.co.uk

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

Method Detail

intersection

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


intersection

public static <T,C extends java.util.Collection<? super T>> C intersection(java.util.Collection<? extends T> coll1,
                                                                           java.util.Collection<? extends T> coll2,
                                                                           C results)

intersection

public static <T> java.util.List<T> intersection(java.util.Iterator<? extends T> iter1,
                                                 java.util.Collection<? extends T> coll2)

intersection

public static <T,C extends java.util.Collection<? super T>> C intersection(java.util.Iterator<? extends T> iter1,
                                                                           java.util.Collection<? extends T> coll2,
                                                                           C results)

intersection

public static <T> java.util.List<T> intersection(java.util.Iterator<? extends T> iter1,
                                                 java.util.Iterator<? extends T> iter2)

intersection

public static <T,C extends java.util.Collection<? super T>> C intersection(java.util.Iterator<? extends T> iter1,
                                                                           java.util.Iterator<? extends T> iter2,
                                                                           C results)

symmetricDifference

public static <T> java.util.List<T> symmetricDifference(java.util.Collection<? extends T> coll1,
                                                        java.util.Collection<? extends T> coll2)
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 <T,C extends java.util.Collection<? super T>> C symmetricDifference(java.util.Collection<? extends T> coll1,
                                                                                  java.util.Collection<? extends T> coll2,
                                                                                  C results)

symmetricDifference

public static <T> java.util.List<T> symmetricDifference(java.util.Iterator<? extends T> iter1,
                                                        java.util.Collection<? extends T> coll2)

symmetricDifference

public static <T,C extends java.util.Collection<? super T>> C symmetricDifference(java.util.Iterator<? extends T> iter1,
                                                                                  java.util.Collection<? extends T> coll2,
                                                                                  C results)

symmetricDifference

public static <T> java.util.List<T> symmetricDifference(java.util.Iterator<? extends T> iter1,
                                                        java.util.Iterator<? extends T> iter2)

forEach

public static <T,R> void forEach(java.util.Collection<T> collection,
                                 Function<? super T,R> fn)
The algorithm ForEach applies the function fn to each element in the iterator sequence.


forEach

public static <T,R> void forEach(java.util.Collection<T> collection,
                                 int start,
                                 int end,
                                 Function<? super T,R> fn)

forEach

public static <T,R> void forEach(java.util.List<T> list,
                                 int start,
                                 int end,
                                 Function<? super T,R> fn)

forEach

public static <T,R> void forEach(java.util.Iterator<T> iterator,
                                 Function<? super T,R> fn)

transform

public static <T,R> java.util.List<R> transform(java.util.Collection<T> collection,
                                                Function<? super T,R> fn)
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 <T,R,C extends java.util.Collection<? super R>> C transform(java.util.Collection<T> collection,
                                                                          Function<? super T,R> fn,
                                                                          C results)

transform

public static <T,R> java.util.List<R> transform(java.util.Collection<T> collection,
                                                int start,
                                                int end,
                                                Function<? super T,R> fn)

transform

public static <T,R,C extends java.util.Collection<? super R>> C transform(java.util.Collection<T> collection,
                                                                          int start,
                                                                          int end,
                                                                          Function<? super T,R> fn,
                                                                          C results)

transform

public static <T,R> java.util.List<R> transform(java.util.List<T> collection,
                                                int start,
                                                int end,
                                                Function<? super T,R> fn)

transform

public static <T,R,C extends java.util.Collection<? super R>> C transform(java.util.List<T> list,
                                                                          int start,
                                                                          int end,
                                                                          Function<? super T,R> fn,
                                                                          C results)

transform

public static <T,R> java.util.List<R> transform(java.util.Iterator<T> iterator,
                                                Function<? super T,R> fn)

transform

public static <T,R,C extends java.util.Collection<? super R>> C transform(java.util.Iterator<T> iterator,
                                                                          Function<? super T,R> fn,
                                                                          C results)

count

public static <T> int count(java.util.Collection<? extends T> collection,
                            T 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 <T> int count(java.util.Collection<? extends T> collection,
                            int start,
                            int end,
                            T value)

count

public static <T> int count(java.util.List<? extends T> list,
                            int start,
                            int end,
                            T value)

count

public static <T> int count(java.util.Iterator<? extends T> iterator,
                            T value)

countIf

public static <T> int countIf(java.util.Collection<T> collection,
                              Predicate<? super T> 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 <T> int countIf(java.util.Collection<T> collection,
                              int start,
                              int end,
                              Predicate<? super T> test)

countIf

public static <T> int countIf(java.util.List<T> list,
                              int start,
                              int end,
                              Predicate<? super T> test)

countIf

public static <T> int countIf(java.util.Iterator<T> iterator,
                              Predicate<? super T> test)

countIfNot

public static <T> int countIfNot(java.util.Collection<T> collection,
                                 Predicate<? super T> 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 <T> int countIfNot(java.util.Collection<T> collection,
                                 int start,
                                 int end,
                                 Predicate<? super T> test)

countIfNot

public static <T> int countIfNot(java.util.List<T> list,
                                 int start,
                                 int end,
                                 Predicate<? super T> test)

countIfNot

public static <T> int countIfNot(java.util.Iterator<T> iterator,
                                 Predicate<? super T> test)

find

public static <T> T find(java.util.Collection<? extends T> collection,
                         T 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 <T> T find(java.util.Collection<? extends T> collection,
                         int start,
                         int end,
                         T value)

find

public static <T> T find(java.util.List<? extends T> list,
                         int start,
                         int end,
                         T value)

find

public static <T> T find(java.util.Iterator<? extends T> iterator,
                         T value)

findPosition

public static <T> int findPosition(java.util.Collection<? extends T> collection,
                                   T 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 <T> int findPosition(java.util.Collection<? extends T> collection,
                                   int start,
                                   int end,
                                   T value)

findPosition

public static <T> int findPosition(java.util.List<? extends T> list,
                                   int start,
                                   int end,
                                   T value)

findPosition

public static <T> int findPosition(java.util.Iterator<? extends T> iterator,
                                   T value)

findPositionIf

public static <T> int findPositionIf(java.util.Collection<T> collection,
                                     Predicate<? super T> pred)

findPositionIf

public static <T> int findPositionIf(java.util.Collection<T> collection,
                                     int start,
                                     int end,
                                     Predicate<? super T> pred)

findPositionIf

public static <T> int findPositionIf(java.util.List<T> list,
                                     int start,
                                     int end,
                                     Predicate<? super T> pred)

findPositionIf

public static <T> int findPositionIf(java.util.Iterator<T> iterator,
                                     Predicate<? super T> pred)

findIf

public static <T> T findIf(java.util.Collection<T> collection,
                           Predicate<? super T> 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 <T> T findIf(java.util.Collection<T> collection,
                           int start,
                           int end,
                           Predicate<? super T> test)

findIf

public static <T> T findIf(java.util.List<T> list,
                           int start,
                           int end,
                           Predicate<? super T> test)

findIf

public static <T> T findIf(java.util.Iterator<T> iterator,
                           Predicate<? super T> test)

findIfNot

public static <T> T findIfNot(java.util.Collection<T> collection,
                              Predicate<? super T> 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 <T> T findIfNot(java.util.Collection<T> collection,
                              int start,
                              int end,
                              Predicate<? super T> test)

findIfNot

public static <T> T findIfNot(java.util.List<T> list,
                              int start,
                              int end,
                              Predicate<? super T> test)

findIfNot

public static <T> T findIfNot(java.util.Iterator<T> iterator,
                              Predicate<? super T> test)

remove

public static <T> void remove(java.util.Collection<? extends T> collection,
                              T value)
Removes objects equal to value from the sequence.


remove

public static <T> void remove(java.util.Collection<? extends T> collection,
                              int start,
                              int end,
                              T value)

remove

public static <T> void remove(java.util.List<? extends T> list,
                              int start,
                              int end,
                              T value)

remove

public static <T> void remove(java.util.Iterator<? extends T> iterator,
                              T value)

removeIf

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


removeIf

public static <T> void removeIf(java.util.Collection<T> collection,
                                int start,
                                int end,
                                Predicate<? super T> pred)

removeIf

public static <T> void removeIf(java.util.List<T> list,
                                int start,
                                int end,
                                Predicate<? super T> pred)

removeIf

public static <T> void removeIf(java.util.Iterator<T> iterator,
                                Predicate<? super T> pred)

partition

public static <T> java.util.List<T> partition(java.util.Collection<T> collection,
                                              Predicate<? super T> pred)
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 <T,C extends java.util.Collection<? super T>> C partition(java.util.Collection<T> collection,
                                                                        Predicate<? super T> pred,
                                                                        C results)

partition

public static <T> java.util.List<T> partition(java.util.Collection<T> collection,
                                              int start,
                                              int end,
                                              Predicate<? super T> pred)

partition

public static <T,C extends java.util.Collection<? super T>> C partition(java.util.Collection<T> collection,
                                                                        int start,
                                                                        int end,
                                                                        Predicate<? super T> pred,
                                                                        C results)

partition

public static <T> java.util.List<T> partition(java.util.List<T> list,
                                              int start,
                                              int end,
                                              Predicate<? super T> pred)

partition

public static <T,C extends java.util.Collection<? super T>> C partition(java.util.List<T> list,
                                                                        int start,
                                                                        int end,
                                                                        Predicate<? super T> pred,
                                                                        C results)

partition

public static <T> java.util.List<T> partition(java.util.Iterator<T> iterator,
                                              Predicate<? super T> pred)

partition

public static <T,C extends java.util.Collection<? super T>> C partition(java.util.Iterator<T> iterator,
                                                                        Predicate<? super T> pred,
                                                                        C results)

unique

public static <T> void unique(java.util.Collection<T> 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 <T> void unique(java.util.Collection<T> collection,
                              int start,
                              int end)

unique

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

unique

public static <T> void unique(java.util.Iterator<T> iterator)

unique

public static <T> void unique(java.util.Collection<T> collection,
                              java.util.Comparator<? super T> comparator)

unique

public static <T> void unique(java.util.Collection<T> collection,
                              int start,
                              int end,
                              java.util.Comparator<? super T> comparator)

unique

public static <T> void unique(java.util.List<T> list,
                              int start,
                              int end,
                              java.util.Comparator<? super T> comparator)

unique

public static <T> void unique(java.util.Iterator<T> iterator,
                              java.util.Comparator<? super T> comparator)


Copyright 2002-2010 JezUK Ltd.