net.sf.jga.util

Class Algorithms

public class Algorithms extends Object

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

Author: David A. Hall

Method Summary
static <T> Taccumulate(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 <T> booleanaddAll(Collection<? super T> c, Iterator<T> iter)
Adds all of the elements of the iterator to the collection.
static <T> longcount(Collection<? extends T> collection, T value)
Counts the number of occurrences of value in the collection, using the equals() method of the value
static <T> longcount(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 <T> longcount(Collection<? extends T> collection, UnaryFunctor<T,Boolean> eq)
Counts the items in the collection for which the given function returns true.
static <T> booleanequal(Collection<? extends T> c1, Collection<? extends T> c2)
Returns true if the two collections are equal.
static <T> booleanequal(Collection<? extends T> c1, Collection<? extends T> c2, Comparator<T> comp)
Returns true if the two collections are equal, using the given comparator to compare the elements in each collection
static <T> booleanequal(Collection<? extends T> c1, Collection<? extends T> c2, BinaryFunctor<T,T,Boolean> eq)
Returns true if the two collections are equal, using the given functor to compare the elements in each collection.
static <T> Iterator<T>find(Collection<? extends T> collection, T value)
Finds an arbitrary value in a collection using the equals() method.
static <T> Iterator<T>find(Collection<? extends T> collection, T value, Equality<T> eq)
Finds an arbitrary value in a collection using the given Equality operator.
static <T> Iterator<T>find(Collection<? extends T> collection, UnaryFunctor<T,Boolean> eq)
Finds a value in a collection for which the given function returns TRUE.
static <T> Iterator<T>findAdjacent(Collection<? extends T> collection)
Finds adjacent pairs of equivalent values in a collection using the equals() method.
static <T> Iterator<T>findAdjacent(Collection<? extends T> c, BinaryFunctor<T,T,Boolean> bf)
Finds adjacent pairs of equivalent values in a collection for which the given function returns TRUE.
static <T> Iterator<T>findElement(Collection<? extends T> c, Collection<? extends T> desired)
Finds any value from the given collection using the collection's contains() method.
static <T> Iterator<T>findElement(Collection<? extends T> c, Collection<? extends T> desired, BinaryFunctor<T,T,Boolean> eq)
Finds any value from the given collection using the given functor to determine equivalence.
static <T> Iterator<T>findRepeated(Collection<? extends T> c, int n, T value)
Finds arbitrary length runs of a given value in a collection using the equals() method.
static <T> Iterator<T>findRepeated(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 <T> Iterator<T>findRepeated(Collection<? extends T> c, int n, UnaryFunctor<T,Boolean> eq)
Finds arbitrary length runs of values in a collection for which the given functor returns TRUE.
static <T,R> UnaryFunctor<T,R>forEach(Collection<? extends T> c, UnaryFunctor<T,R> fn)
Applies the given UnaryFunctor to every element in the collection, and returns the Functor.
static <T extends Comparable> booleanlessThan(Collection<? extends T> c1, 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 <T> booleanlessThan(Collection<? extends T> c1, Collection<? extends T> c2, 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 <T> booleanlessThan(Collection<? extends T> c1, Collection<? extends T> c2, BinaryFunctor<T,T,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 <T> Iterator<T>match(Collection<? extends T> c, Collection<? extends T> pattern)
Finds the given pattern in the collection using the equals method.
static <T> Iterator<T>match(Collection<? extends T> c, Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> eq)
Finds the given pattern in the collection using the given functor to determine equivalence.
static <T extends Comparable> Iterator<T>maximum(Collection<? extends T> c)
Finds the position of the maximum value in a collection using the natural ordering of the collection's elements.
static <T> Iterator<T>maximum(Collection<? extends T> c, Comparator<T> comp)
Finds the position of the maximum value in a collection using the given comparator.
static <T> Iterator<T>maximum(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 <T extends Comparable> TmaximumValue(Collection<? extends T> c)
Finds the maximum value in a collection using the natural ordering of the collection's elements.
static <T> TmaximumValue(Collection<? extends T> c, Comparator<T> comp)
Finds the minimum value in a collection using the given comparator.
static <T> TmaximumValue(Collection<? extends T> c, BinaryFunctor<T,T,T> fn)
Finds the maximum value in a collection using the given functor to compare elements.
static <T extends Comparable<T>> Iterator<T>minimum(Collection<? extends T> c)
Finds the position of the minimum value in a collection using the natural ordering of the collection's elements.
static <T> Iterator<T>minimum(Collection<? extends T> c, Comparator<T> comp)
Finds the position of the minimum value in a collection using the given comparator.
static <T> Iterator<T>minimum(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 <T extends Comparable> TminimumValue(Collection<? extends T> c)
Finds the minimum value in a collection using the natural ordering of the collection's elements.
static <T> TminimumValue(Collection<? extends T> c, Comparator<T> comp)
Finds the minimum value in a collection using the given comparator.
static <T> TminimumValue(Collection<? extends T> c, BinaryFunctor<T,T,T> bf)
Finds the minimum value in a collection using the given functor to compare elements.
static <T> Iterator<T>mismatch(Collection<? extends T> c, Collection<? extends T> pattern)
Finds the point at which two collections differ, using NotEqualTo.
static <T> Iterator<T>mismatch(Collection<? extends T> c, Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> neq)
Finds the point at which two collections differ, using the given functor
static <T> voidremoveAll(List<? extends T> lin, T value)
removes all instances of the given element from the list
static <T> voidremoveAll(List<? extends T> lin, T value, Equality<T> eq)
removes all instances of the given element from the list
static <T> voidremoveAll(List<? extends T> lin, UnaryFunctor<T,Boolean> uf)
removes all elements from the list for which the functor returns TRUE
static <T> voidremoveAllCopy(Collection<? extends T> cin, 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 <T> voidremoveAllCopy(Collection<? extends T> cin, 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 <T> voidremoveAllCopy(Collection<? extends T> cin, Collection<? super T> cout, UnaryFunctor<T,Boolean> eq)
Copies each element in the input collection except those for which the given function returns TRUE to the output collection.
static <T> voidreplaceAll(List<T> lin, UnaryFunctor<T,Boolean> uf, T value)
Tests each element in the list, and replaces elements that pass with the given value.
static <T,R> voidreplaceAllCopy(Collection<? extends T> cin, Collection<? super T> cout, UnaryFunctor<T,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 <T> voidtransform(List<T> lin, UnaryFunctor<T,T> uf)
Applies the UnaryFunctor to each element in the list, and replaces each element with the result.
static <T,R> voidtransformCopy(Collection<? extends T> cin, 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 <T1,T2,R> voidtransformCopy(Collection<? extends T1> c1, Collection<? extends T2> c2, 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 <T> voidunique(List<? extends T> lin)
removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements
static <T> voidunique(List<? extends T> lin, BinaryFunctor<T,T,Boolean> eq)
removes all adjacent duplicate values in the given list, using the given functor to compare adjacent elements
static <T> voiduniqueCopy(Collection<? extends T> cin, Collection<? super T> cout)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements.
static <T> voiduniqueCopy(Collection<? extends T> cin, Collection<? super T> cout, BinaryFunctor<T,T,Boolean> eq)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements.

Method Detail

accumulate

public static <T> T accumulate(Collection<T> c, T initial, BinaryFunctor<T,T,T> bf)
Applies the binary functor to each element in the collection, returning the final result. Along with each element is passed the result of the previous call of the functor (or the initial value for the first call to the functor). The elements in the collection are always passed in the 2nd postion.

Returns: the final result. If the collection is empty, then the initial value is returned

addAll

public static <T> boolean addAll(Collection<? super T> c, Iterator<T> iter)
Adds all of the elements of the iterator to the collection. If necessary and possible, the collection will be enlarged: if enlarging the collection is not possible, then the runtime exception thrown. Augmentation of the Collection.addAll(Collection) API method.

count

public static <T> long count(Collection<? extends T> collection, T value)
Counts the number of occurrences of value in the collection, using the equals() method of the value

Returns: the number of instances found

count

public static <T> long count(Collection<? extends T> collection, Equality<T> eq, T value)
Counts the number of occurrences of value in the collection, using the given equality operator.

Returns: the number of instances found

count

public static <T> long count(Collection<? extends T> collection, UnaryFunctor<T,Boolean> eq)
Counts the items in the collection for which the given function returns true.

Returns: the number of instances found

equal

public static <T> boolean equal(Collection<? extends T> c1, Collection<? extends T> c2)
Returns true if the two collections are equal.

Returns: true if the two collections are equal

equal

public static <T> boolean equal(Collection<? extends T> c1, Collection<? extends T> c2, Comparator<T> comp)
Returns true if the two collections are equal, using the given comparator to compare the elements in each collection

Returns: true if the two collections are equal.

equal

public static <T> boolean equal(Collection<? extends T> c1, Collection<? extends T> c2, BinaryFunctor<T,T,Boolean> eq)
Returns true if the two collections are equal, using the given functor to compare the elements in each collection. The functor is expected to evaluate its two argments and return true if they are "equal", therefore this method returns true if the iterations contain the same number of elements and if the functor returns true for all pairs of elements.

Returns: true if the two collections are equal

find

public static <T> Iterator<T> find(Collection<? extends T> collection, T value)
Finds an arbitrary value in a collection using the equals() method.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the value. If the value is not in the collection, then the returned iterator's hasNext() will report false.

find

public static <T> Iterator<T> find(Collection<? extends T> collection, T value, Equality<T> eq)
Finds an arbitrary value in a collection using the given Equality operator.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the value. If the value is not in the collection, then the returned iterator's hasNext() will report false.

find

public static <T> Iterator<T> find(Collection<? extends T> collection, UnaryFunctor<T,Boolean> eq)
Finds a value in a collection for which the given function returns TRUE.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the value. If the value is not in the collection, then the returned iterator's hasNext() will report false.

findAdjacent

public static <T> Iterator<T> findAdjacent(Collection<? extends T> collection)
Finds adjacent pairs of equivalent values in a collection using the equals() method.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first of a pair of adjacent values. If no pair of values exists in the collection, then the returned iterator's hasNext() will report false.

findAdjacent

public static <T> Iterator<T> findAdjacent(Collection<? extends T> c, BinaryFunctor<T,T,Boolean> bf)
Finds adjacent pairs of equivalent values in a collection for which the given function returns TRUE.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first of a pair of adjacent values. If no pair of values exists in the collection, then the returned iterator's hasNext() will report false.

findElement

public static <T> Iterator<T> findElement(Collection<? extends T> c, Collection<? extends T> desired)
Finds any value from the given collection using the collection's contains() method.

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first instance of any value found in the second collection. If no such value is found in the first collection, then the returned iterator's hasNext() will report false.

findElement

public static <T> Iterator<T> findElement(Collection<? extends T> c, Collection<? extends T> desired, BinaryFunctor<T,T,Boolean> eq)
Finds any value from the given collection using the given functor to determine equivalence. Each item in the first collection will be compared to every item in the second collection using the given functor, stopping when the first collection is exhausted or when any pair returns TRUE.

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first instance of any value in the second collection, where equivelency is determined by the given functor. If no such value is found in the first collection, then the returned iterator's hasNext() will report false.

findRepeated

public static <T> Iterator<T> findRepeated(Collection<? extends T> c, int n, T value)
Finds arbitrary length runs of a given value in a collection using the equals() method. Runs of length zero are well-defined: every iteration begins with a run of length zero of all possible values.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first of n adjacent instances of value. If no run of values of the requested length exist in the collection, then the returned iterator's hasNext() will report false.

findRepeated

public static <T> Iterator<T> findRepeated(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. Runs of length zero are well-defined: every iteration begins with a run of length zero of all possible values.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first of n adjacent instances of value. If no run of values of the requested length exist in the collection, then the returned iterator's hasNext() will report false.

findRepeated

public static <T> Iterator<T> findRepeated(Collection<? extends T> c, int n, UnaryFunctor<T,Boolean> eq)
Finds arbitrary length runs of values in a collection for which the given functor returns TRUE. Runs of length zero are well-defined: every iteration begins with a run of length zero of all possible values.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first of n adjacent instances of value. If no run of values of the requested length exist in the collection, then the returned iterator's hasNext() will report false.

forEach

public static <T,R> UnaryFunctor<T,R> forEach(Collection<? extends T> c, UnaryFunctor<T,R> fn)
Applies the given UnaryFunctor to every element in the collection, and returns the Functor. This is useful when the Functor gathers information on each successive call.

Returns: the functor, after it has been called once for every element

lessThan

public static <T extends Comparable> boolean lessThan(Collection<? extends T> c1, 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.

Returns: true if c1 < c2

lessThan

public static <T> boolean lessThan(Collection<? extends T> c1, Collection<? extends T> c2, 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.

Returns: true if c1 < c2

lessThan

public static <T> boolean lessThan(Collection<? extends T> c1, Collection<? extends T> c2, BinaryFunctor<T,T,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. The first is less than the second if it is not longer than the second and if the first corresponding element that is not equal is less.

Returns: true if c1 < c2

match

public static <T> Iterator<T> match(Collection<? extends T> c, Collection<? extends T> pattern)
Finds the given pattern in the collection using the equals method.

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first element of a sequence that matches the entire contents of the second collection. If no such match is found in the first collection, then the returned iterator's hasNext() will report false. If the pattern is empty, then the iterator points to the first element in the collection.

match

public static <T> Iterator<T> match(Collection<? extends T> c, Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> eq)
Finds the given pattern in the collection using the given functor to determine equivalence.

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first element of a sequence that matches the entire contents of the second collection. If no such match is found in the first collection, then the returned iterator's hasNext() will report false. If the pattern is empty, then the iterator points to the first element in the collection.

maximum

public static <T extends Comparable> Iterator<T> maximum(Collection<? extends T> c)
Finds the position of the maximum value in a collection using the natural ordering of the collection's elements.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the maximum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

maximum

public static <T> Iterator<T> maximum(Collection<? extends T> c, Comparator<T> comp)
Finds the position of the maximum value in a collection using the given comparator.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the maximum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

maximum

public static <T> Iterator<T> maximum(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. The functor is presumed to return the greater of its two arguments.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the maximum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

maximumValue

public static <T extends Comparable> T maximumValue(Collection<? extends T> c)
Finds the maximum value in a collection using the natural ordering of the collection's elements.

Returns: the maximum value found in the collection

maximumValue

public static <T> T maximumValue(Collection<? extends T> c, Comparator<T> comp)
Finds the minimum value in a collection using the given comparator.

Returns: the maximum value found in the collection

maximumValue

public static <T> T maximumValue(Collection<? extends T> c, BinaryFunctor<T,T,T> fn)
Finds the maximum value in a collection using the given functor to compare elements. The functor is presumed to return the greater of its two arguments.

Returns: the maximum value found in the collection

minimum

public static <T extends Comparable<T>> Iterator<T> minimum(Collection<? extends T> c)
Finds the position of the minimum value in a collection using the natural ordering of the collection's elements.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the minimum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

minimum

public static <T> Iterator<T> minimum(Collection<? extends T> c, Comparator<T> comp)
Finds the position of the minimum value in a collection using the given comparator.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the minimum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

minimum

public static <T> Iterator<T> minimum(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. The functor is presumed to return the lesser of its two arguments.

Returns: an iterator from the collection whose next() [if it hasNext()] will return the first instance of the minimum value in the collection. If the collection is empty, then the returned iterator's hasNext() will report false.

minimumValue

public static <T extends Comparable> T minimumValue(Collection<? extends T> c)
Finds the minimum value in a collection using the natural ordering of the collection's elements.

Returns: the minimum value found in the collection

minimumValue

public static <T> T minimumValue(Collection<? extends T> c, Comparator<T> comp)
Finds the minimum value in a collection using the given comparator.

Returns: the minimum value found in the collection

minimumValue

public static <T> T minimumValue(Collection<? extends T> c, BinaryFunctor<T,T,T> bf)
Finds the minimum value in a collection using the given functor to compare elements. The functor is presumed to return the lesser of its two arguments.

Returns: the minimum value found in the collection

mismatch

public static <T> Iterator<T> mismatch(Collection<? extends T> c, Collection<? extends T> pattern)
Finds the point at which two collections differ, using NotEqualTo.

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first element in the collection that does not equal the corresponding element in the pattern. If the pattern matches the collection but is longer, than the returned iterator's hasNext() will report false. If the pattern is empty, then the iterator points to the first element in the collection.

mismatch

public static <T> Iterator<T> mismatch(Collection<? extends T> c, Collection<? extends T> pattern, BinaryFunctor<T,T,Boolean> neq)
Finds the point at which two collections differ, using the given functor

Returns: an iterator from the first collection whose next() [if it hasNext()] will return the first element in the collection for which the given function returns TRUE when given the element and the correspondind element in the pattern. If the pattern matches the collection but is longer, than the returned iterator's hasNext() will report false. If the pattern is empty, then the iterator points to the first element in the collection.

removeAll

public static <T> void removeAll(List<? extends T> lin, T value)
removes all instances of the given element from the list

removeAll

public static <T> void removeAll(List<? extends T> lin, T value, Equality<T> eq)
removes all instances of the given element from the list

removeAll

public static <T> void removeAll(List<? extends T> lin, UnaryFunctor<T,Boolean> uf)
removes all elements from the list for which the functor returns TRUE

removeAllCopy

public static <T> void removeAllCopy(Collection<? extends T> cin, Collection<? super T> cout, T value)
Copies each element in the input collection except those equal to the given value to the output collection,

removeAllCopy

public static <T> void removeAllCopy(Collection<? extends T> cin, 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,

removeAllCopy

public static <T> void removeAllCopy(Collection<? extends T> cin, Collection<? super T> cout, UnaryFunctor<T,Boolean> eq)
Copies each element in the input collection except those for which the given function returns TRUE to the output collection.

replaceAll

public static <T> void replaceAll(List<T> lin, UnaryFunctor<T,Boolean> uf, T value)
Tests each element in the list, and replaces elements that pass with the given value. This method would, in an ideal world, belong in the Collections class, as its signature is more like the algorithm methods in that class than in Algorithms.

replaceAllCopy

public static <T,R> void replaceAllCopy(Collection<? extends T> cin, Collection<? super T> cout, UnaryFunctor<T,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.

transform

public static <T> void transform(List<T> lin, UnaryFunctor<T,T> uf)
Applies the UnaryFunctor to each element in the list, and replaces each element with the result. This method would, in an ideal world, belong in the Collections class, as its signature is more like the algorithm methods in that class than in Algorithms.

transformCopy

public static <T,R> void transformCopy(Collection<? extends T> cin, 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. The output collection will generally grow as a result of this operation (in contrast with the STL transform operation, which will not by itself change the size of the output collection)

transformCopy

public static <T1,T2,R> void transformCopy(Collection<? extends T1> c1, Collection<? extends T2> c2, 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. The output collection will generally grow as a result of this operation (in contrast with the STL transform operation, which will not by itself change the size of the output collection)

unique

public static <T> void unique(List<? extends T> lin)
removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements

unique

public static <T> void unique(List<? extends T> lin, BinaryFunctor<T,T,Boolean> eq)
removes all adjacent duplicate values in the given list, using the given functor to compare adjacent elements

uniqueCopy

public static <T> void uniqueCopy(Collection<? extends T> cin, Collection<? super T> cout)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements.

uniqueCopy

public static <T> void uniqueCopy(Collection<? extends T> cin, Collection<? super T> cout, BinaryFunctor<T,T,Boolean> eq)
Copies the elements from the input collection to the output collection, skipping adjacent duplacate elements.