|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.jga.util.Algorithms
public class Algorithms
Facade for the Algorithms adapted from STL, defined to work primarily with collections. These algorithms are adapted from STL, with modifications to be consistent with typical java practice. For example, typical STL algorithms are defined with pairs of iterators defining a half-open range over some implied collection. It works in C++ because the STL iterators can be compared for equality. Java iterators are not guaranteed to be comparable to each other by contract, so the same signatures wouldn't work.
Typically, where an STL algorithm would take a pair of iterators, we'll take a collection. Where an STL algorithm would return an iterator, we'll return an iterator. Note that it will always be java.lang.Iterator when using this class: for some of the more powerful uses, use the Iterators class, which will often return an implementation of Iterator that is tailored for the semantics of the algorithm that was called.
The algorithms in this class and the same set of algorithms in the Iterators class will always return the same results when called with identical arguments.
Copyright © 2003 David A. Hall
| Constructor Summary | |
|---|---|
Algorithms()
|
|
| Method Summary | ||
|---|---|---|
static
|
accumulate(java.lang.Class<T> numtype,
java.util.Collection<T> c)
Adds each number in the collection, returning the sum. |
|
static
|
accumulate(java.lang.Class<T> numtype,
java.util.Collection<T> c,
BinaryFunctor<T,T,T> bf)
Applies the binary functor to each number in the collection, returning the final result. |
|
static
|
accumulate(java.util.Collection<T> c,
T initial,
BinaryFunctor<T,T,T> bf)
Applies the binary functor to each element in the collection, returning the final result. |
|
static
|
addAll(java.util.Collection<? super T> c,
java.util.Iterator<T> iter)
Adds all of the elements of the iterator to the collection. |
|
static
|
count(java.util.Collection<? extends T> collection,
Equality<T> eq,
T value)
Counts the number of occurrences of value in the collection, using the given equality operator. |
|
static
|
count(java.util.Collection<? extends T> collection,
T value)
Counts the number of occurrences of value in the collection, using the equals() method of the value |
|
static
|
count(java.util.Collection<? extends T> collection,
UnaryFunctor<T,java.lang.Boolean> eq)
Counts the items in the collection for which the given function returns true. |
|
static
|
equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2)
Returns true if the two collections are equal. |
|
static
|
equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
BinaryFunctor<T,T,java.lang.Boolean> eq)
Returns true if the two collections are equal, using the given functor to compare the elements in each collection. |
|
static
|
equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
java.util.Comparator<T> comp)
Returns true if the two collections are equal, using the given comparator to compare the elements in each collection |
|
static
|
find(java.util.Collection<? extends T> collection,
T value)
Finds an arbitrary value in a collection using the equals() method. |
|
static
|
find(java.util.Collection<? extends T> collection,
T value,
Equality<T> eq)
Finds an arbitrary value in a collection using the given Equality operator. |
|
static
|
find(java.util.Collection<? extends T> collection,
UnaryFunctor<T,java.lang.Boolean> eq)
Finds a value in a collection for which the given function returns TRUE. |
|
static
|
findAdjacent(java.util.Collection<? extends T> collection)
Finds adjacent pairs of equivalent values in a collection using the equals() method. |
|
static
|
findAdjacent(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,java.lang.Boolean> bf)
Finds adjacent pairs of equivalent values in a collection for which the given function returns TRUE. |
|
static
|
findElement(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> desired)
Finds any value from the given collection using the collection's contains() method. |
|
static
|
findElement(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> desired,
BinaryFunctor<T,T,java.lang.Boolean> eq)
Finds any value from the given collection using the given functor to determine equivalence. |
|
static
|
findRepeated(java.util.Collection<? extends T> c,
int n,
T value)
Finds arbitrary length runs of a given value in a collection using the equals() method. |
|
static
|
findRepeated(java.util.Collection<? extends T> c,
int n,
T value,
Equality<T> eq)
Finds arbitrary length runs of a given value in a collection using the given Equality operator. |
|
static
|
findRepeated(java.util.Collection<? extends T> c,
int n,
UnaryFunctor<T,java.lang.Boolean> eq)
Finds arbitrary length runs of values in a collection for which the given functor returns TRUE. |
|
static
|
forEach(java.util.Collection<? extends T> c,
UnaryFunctor<T,R> fn)
Applies the given UnaryFunctor to every element in the collection, and returns the Functor. |
|
static
|
lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2)
Returns true if the first collection is lexically less than the second, using the default comparison operation to compare the elements in each collection. |
|
static
|
lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
BinaryFunctor<T,T,java.lang.Boolean> lt)
Returns true if the first collection is lexically less than the second, using the given operator to compare the elements in each collection. |
|
static
|
lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
java.util.Comparator<T> comp)
Returns true if the first collection is lexically less than the second, using the given comparator to compare the elements in each collection. |
|
static
|
match(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern)
Finds the given pattern in the collection using the equals method. |
|
static
|
match(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern,
BinaryFunctor<T,T,java.lang.Boolean> eq)
Finds the given pattern in the collection using the given functor to determine equivalence. |
|
static
|
maximum(java.util.Collection<? extends T> c)
Finds the position of the maximum value in a collection using the natural ordering of the collection's elements. |
|
static
|
maximum(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
Finds the position of the maximum value in a collection using the given functor to compare elements. |
|
static
|
maximum(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
Finds the position of the maximum value in a collection using the given comparator. |
|
static
|
maximumValue(java.util.Collection<? extends T> c)
Finds the maximum value in a collection using the natural ordering of the collection's elements. |
|
static
|
maximumValue(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> fn)
Finds the maximum value in a collection using the given functor to compare elements. |
|
static
|
maximumValue(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
Finds the minimum value in a collection using the given comparator. |
|
static
|
mergeCopy(java.util.Collection<? extends T> cin1,
java.util.Collection<? extends T> cin2,
java.util.Collection<? super T> cout)
merges two collections, appending values to the output collection |
|
static
|
mergeCopy(java.util.Collection<? extends T> cin1,
java.util.Collection<? extends T> cin2,
java.util.Collection<? super T> cout,
java.util.Comparator<T> comp)
merges two collections using the given comparator, appending values to the output collection |
|
static
|
minimum(java.util.Collection<? extends T> c)
Finds the position of the minimum value in a collection using the natural ordering of the collection's elements. |
|
static
|
minimum(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
Finds the position of the minimum value in a collection using the given functor to compare elements. |
|
static
|
minimum(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
Finds the position of the minimum value in a collection using the given comparator. |
|
static
|
minimumValue(java.util.Collection<? extends T> c)
Finds the minimum value in a collection using the natural ordering of the collection's elements. |
|
static
|
minimumValue(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
Finds the minimum value in a collection using the given functor to compare elements. |
|
static
|
minimumValue(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
Finds the minimum value in a collection using the given comparator. |
|
static
|
mismatch(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern)
Finds the point at which two collections differ, using NotEqualTo. |
|
static
|
mismatch(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern,
BinaryFunctor<T,T,java.lang.Boolean> neq)
Finds the point at which two collections differ, using the given functor |
|
static
|
removeAll(java.util.List<? extends T> lin,
T value)
removes all instances of the given element from the list |
|
static
|
removeAll(java.util.List<? extends T> lin,
T value,
Equality<T> eq)
removes all instances of the given element from the list |
|
static
|
removeAll(java.util.List<? extends T> lin,
UnaryFunctor<T,java.lang.Boolean> uf)
removes all elements from the list for which the functor returns TRUE |
|
static
|
removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
T value)
Copies each element in the input collection except those equal to the given value to the output collection, |
|
static
|
removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
T value,
Equality<T> eq)
Copies each element in the input collection except those equal to the given value (using the given Equality operator) to the output collection, |
|
static
|
removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
UnaryFunctor<T,java.lang.Boolean> eq)
Copies each element in the input collection except those for which the given function returns TRUE to the output collection. |
|
static
|
replaceAll(java.util.List<T> lin,
UnaryFunctor<T,java.lang.Boolean> uf,
T value)
Tests each element in the list, and replaces elements that pass with the given value. |
|
static
|
replaceAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
UnaryFunctor<T,java.lang.Boolean> test,
T value)
Copies each element in the input collection to the output collection, except that those elements that pass the given test are replaced with the constant value. |
|
static
|
transform(java.util.List<T> lin,
UnaryFunctor<T,T> uf)
Applies the UnaryFunctor to each element in the list, and replaces each element with the result. |
|
static
|
transformCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super R> cout,
UnaryFunctor<T,R> uf)
Applies the UnaryFunctor to each element in the input collection, and appends the result to the output collection. |
|
static
|
transformCopy(java.util.Collection<? extends T1> c1,
java.util.Collection<? extends T2> c2,
java.util.Collection<? super R> cout,
BinaryFunctor<T1,T2,R> bf)
Applies the BinaryFunctor to corresponding elements of the two input collections, and appends the result to the output collection. |
|
static
|
unique(java.util.List<? extends T> lin)
removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements |
|
static
|
unique(java.util.List<? extends T> lin,
BinaryFunctor<T,T,java.lang.Boolean> eq)
removes all adjacent duplicate values in the given list, using the given functor to compare adjacent elements |
|
static
|
uniqueCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements. |
|
static
|
uniqueCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
BinaryFunctor<T,T,java.lang.Boolean> eq)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Algorithms()
| Method Detail |
|---|
public static <T> java.util.Iterator<T> find(java.util.Collection<? extends T> collection,
T value)
public static <T> java.util.Iterator<T> find(java.util.Collection<? extends T> collection,
T value,
Equality<T> eq)
public static <T> java.util.Iterator<T> find(java.util.Collection<? extends T> collection,
UnaryFunctor<T,java.lang.Boolean> eq)
public static <T> long count(java.util.Collection<? extends T> collection,
T value)
public static <T> long count(java.util.Collection<? extends T> collection,
Equality<T> eq,
T value)
public static <T> long count(java.util.Collection<? extends T> collection,
UnaryFunctor<T,java.lang.Boolean> eq)
public static <T> java.util.Iterator<T> findAdjacent(java.util.Collection<? extends T> collection)
public static <T> java.util.Iterator<T> findAdjacent(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,java.lang.Boolean> bf)
public static <T> java.util.Iterator<T> findElement(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> desired)
public static <T> java.util.Iterator<T> findElement(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> desired,
BinaryFunctor<T,T,java.lang.Boolean> eq)
public static <T> java.util.Iterator<T> match(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern)
public static <T> java.util.Iterator<T> match(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern,
BinaryFunctor<T,T,java.lang.Boolean> eq)
public static <T> java.util.Iterator<T> mismatch(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern)
public static <T> java.util.Iterator<T> mismatch(java.util.Collection<? extends T> c,
java.util.Collection<? extends T> pattern,
BinaryFunctor<T,T,java.lang.Boolean> neq)
public static <T> java.util.Iterator<T> findRepeated(java.util.Collection<? extends T> c,
int n,
T value)
public static <T> java.util.Iterator<T> findRepeated(java.util.Collection<? extends T> c,
int n,
T value,
Equality<T> eq)
public static <T> java.util.Iterator<T> findRepeated(java.util.Collection<? extends T> c,
int n,
UnaryFunctor<T,java.lang.Boolean> eq)
public static <T,R> UnaryFunctor<T,R> forEach(java.util.Collection<? extends T> c,
UnaryFunctor<T,R> fn)
public static <T> boolean equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2)
public static <T> boolean equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
java.util.Comparator<T> comp)
public static <T> boolean equal(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
BinaryFunctor<T,T,java.lang.Boolean> eq)
public static <T extends java.lang.Comparable<? super T>> boolean lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2)
public static <T> boolean lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
java.util.Comparator<T> comp)
public static <T> boolean lessThan(java.util.Collection<? extends T> c1,
java.util.Collection<? extends T> c2,
BinaryFunctor<T,T,java.lang.Boolean> lt)
public static <T extends java.lang.Comparable<? super T>> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c)
public static <T> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
public static <T> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
public static <T extends java.lang.Comparable<? super T>> T minimumValue(java.util.Collection<? extends T> c)
public static <T> T minimumValue(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
public static <T> T minimumValue(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
public static <T extends java.lang.Comparable<? super T>> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c)
public static <T> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
public static <T> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> bf)
public static <T extends java.lang.Comparable<? super T>> T maximumValue(java.util.Collection<? extends T> c)
public static <T> T maximumValue(java.util.Collection<? extends T> c,
java.util.Comparator<T> comp)
public static <T> T maximumValue(java.util.Collection<? extends T> c,
BinaryFunctor<T,T,T> fn)
public static <T extends java.lang.Number> T accumulate(java.lang.Class<T> numtype,
java.util.Collection<T> c)
public static <T extends java.lang.Number> T accumulate(java.lang.Class<T> numtype,
java.util.Collection<T> c,
BinaryFunctor<T,T,T> bf)
public static <T> T accumulate(java.util.Collection<T> c,
T initial,
BinaryFunctor<T,T,T> bf)
public static <T> void transform(java.util.List<T> lin,
UnaryFunctor<T,T> uf)
public static <T,R> void transformCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super R> cout,
UnaryFunctor<T,R> uf)
public static <T1,T2,R> void transformCopy(java.util.Collection<? extends T1> c1,
java.util.Collection<? extends T2> c2,
java.util.Collection<? super R> cout,
BinaryFunctor<T1,T2,R> bf)
public static <T> void replaceAll(java.util.List<T> lin,
UnaryFunctor<T,java.lang.Boolean> uf,
T value)
public static <T,R> void replaceAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
UnaryFunctor<T,java.lang.Boolean> test,
T value)
public static <T> void removeAll(java.util.List<? extends T> lin,
T value)
public static <T> void removeAll(java.util.List<? extends T> lin,
T value,
Equality<T> eq)
public static <T> void removeAll(java.util.List<? extends T> lin,
UnaryFunctor<T,java.lang.Boolean> uf)
public static <T> void removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
T value)
public static <T> void removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
T value,
Equality<T> eq)
public static <T> void removeAllCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
UnaryFunctor<T,java.lang.Boolean> eq)
public static <T> void unique(java.util.List<? extends T> lin)
public static <T> void unique(java.util.List<? extends T> lin,
BinaryFunctor<T,T,java.lang.Boolean> eq)
public static <T> void uniqueCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout)
public static <T> void uniqueCopy(java.util.Collection<? extends T> cin,
java.util.Collection<? super T> cout,
BinaryFunctor<T,T,java.lang.Boolean> eq)
public static <T extends java.lang.Comparable<? super T>> void mergeCopy(java.util.Collection<? extends T> cin1,
java.util.Collection<? extends T> cin2,
java.util.Collection<? super T> cout)
public static <T> void mergeCopy(java.util.Collection<? extends T> cin1,
java.util.Collection<? extends T> cin2,
java.util.Collection<? super T> cout,
java.util.Comparator<T> comp)
public static <T> boolean addAll(java.util.Collection<? super T> c,
java.util.Iterator<T> iter)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||