net.sf.jga.util
Class Algorithms

java.lang.Object
  extended by net.sf.jga.util.Algorithms

Deprecated. everything likely to be of value has been moved to static classes in the net.sf.jga.algorithms package

public class Algorithms
extends java.lang.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-2005 David A. Hall

Author:
David A. Hall

Constructor Summary
Algorithms()
          Deprecated.  
 
Method Summary
static
<T> boolean
equal(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2)
          Deprecated. use c1.equals(c2) instead
static
<T> boolean
equal(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2, BinaryFunctor<T,T,java.lang.Boolean> eq)
          Deprecated. use Compare.equal(Iterable,Iterable,BinaryFunctor) instead
static
<T> boolean
equal(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2, java.util.Comparator<T> comp)
          Deprecated. use Compare.equal(Iterable,Iterable,Comparator) instead
static
<T,R> UnaryFunctor<T,R>
forEach(java.util.Collection<? extends T> c, UnaryFunctor<T,R> fn)
          Deprecated. use Summarize.forEach(Iterable,UnaryFunctor)
static
<T extends java.lang.Comparable<? super T>>
boolean
lessThan(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2)
          Deprecated. use Compare.lessThan(Iterable,Iterable) instead
static
<T> boolean
lessThan(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2, BinaryFunctor<T,T,java.lang.Boolean> lt)
          Deprecated. use Compare.lessThan(Iterable,Iterable,BinaryFunctor) instead
static
<T> boolean
lessThan(java.util.Collection<? extends T> c1, java.util.Collection<? extends T> c2, java.util.Comparator<T> comp)
          Deprecated. use Compare.lessThan(Iterable,Iterable,Comparator) instead
static
<T extends java.lang.Comparable<? super T>>
java.util.Iterator<T>
maximum(java.util.Collection<? extends T> c)
          Deprecated. Finds the position of the maximum value in a collection using the natural ordering of the collection's elements.
static
<T> java.util.Iterator<T>
maximum(java.util.Collection<? extends T> c, BinaryFunctor<T,T,T> bf)
          Deprecated. Finds the position of the maximum value in a collection using the given functor to compare elements.
static
<T> java.util.Iterator<T>
maximum(java.util.Collection<? extends T> c, java.util.Comparator<T> comp)
          Deprecated. Finds the position of the maximum value in a collection using the given comparator.
static
<T extends java.lang.Comparable<? super T>>
java.util.Iterator<T>
minimum(java.util.Collection<? extends T> c)
          Deprecated. Finds the position of the minimum value in a collection using the natural ordering of the collection's elements.
static
<T> java.util.Iterator<T>
minimum(java.util.Collection<? extends T> c, BinaryFunctor<T,T,T> bf)
          Deprecated. Finds the position of the minimum value in a collection using the given functor to compare elements.
static
<T> java.util.Iterator<T>
minimum(java.util.Collection<? extends T> c, java.util.Comparator<T> comp)
          Deprecated. Finds the position of the minimum value in a collection using the given comparator.
static
<T,LT extends java.util.List<? extends T>>
LT
removeAll(LT lin, T value)
          Deprecated. use ListAlgorithms.remove(List,Object)
static
<T,LT extends java.util.List<? extends T>>
LT
removeAll(LT lin, T value, Equality<T> eq)
          Deprecated. use ListAlgorithms.remove(List,Object)
static
<T,LT extends java.util.List<? extends T>>
LT
removeAll(LT lin, UnaryFunctor<T,java.lang.Boolean> uf)
          Deprecated. use ListAlgorithms.remove(List,UnaryFunctor)
static
<T> java.util.List<T>
replaceAll(java.util.List<T> lin, UnaryFunctor<T,java.lang.Boolean> uf, T value)
          Deprecated. use ListAlgorithms.replace(List,UnaryFunctor,Object)
static
<T> java.util.List<T>
transform(java.util.List<T> lin, UnaryFunctor<T,T> uf)
          Deprecated. use ListAlgorithms.transform(List,UnaryFunctor)
static
<T,LT extends java.util.List<? extends T>>
LT
unique(LT lin)
          Deprecated. use ListAlgorithms.unique(List)
static
<T,LT extends java.util.List<? extends T>>
LT
unique(LT lin, BinaryFunctor<T,T,java.lang.Boolean> eq)
          Deprecated. use ListAlgorithms.unique(List,BinaryFunctor)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Algorithms

public Algorithms()
Deprecated. 
Method Detail

forEach

public static <T,R> UnaryFunctor<T,R> forEach(java.util.Collection<? extends T> c,
                                              UnaryFunctor<T,R> fn)
Deprecated. use Summarize.forEach(Iterable,UnaryFunctor)

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

equal

public static <T> boolean equal(java.util.Collection<? extends T> c1,
                                java.util.Collection<? extends T> c2)
Deprecated. use c1.equals(c2) instead

Returns true if the two collections are equal.

Returns:
true if the two collections are equal

equal

public static <T> boolean equal(java.util.Collection<? extends T> c1,
                                java.util.Collection<? extends T> c2,
                                java.util.Comparator<T> comp)
Deprecated. use Compare.equal(Iterable,Iterable,Comparator) instead

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(java.util.Collection<? extends T> c1,
                                java.util.Collection<? extends T> c2,
                                BinaryFunctor<T,T,java.lang.Boolean> eq)
Deprecated. use Compare.equal(Iterable,Iterable,BinaryFunctor) instead

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

lessThan

public static <T extends java.lang.Comparable<? super T>> boolean lessThan(java.util.Collection<? extends T> c1,
                                                                           java.util.Collection<? extends T> c2)
Deprecated. use Compare.lessThan(Iterable,Iterable) instead

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(java.util.Collection<? extends T> c1,
                                   java.util.Collection<? extends T> c2,
                                   java.util.Comparator<T> comp)
Deprecated. use Compare.lessThan(Iterable,Iterable,Comparator) instead

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(java.util.Collection<? extends T> c1,
                                   java.util.Collection<? extends T> c2,
                                   BinaryFunctor<T,T,java.lang.Boolean> lt)
Deprecated. use Compare.lessThan(Iterable,Iterable,BinaryFunctor) instead

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

minimum

public static <T extends java.lang.Comparable<? super T>> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c)
Deprecated. 
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> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c,
                                                java.util.Comparator<T> comp)
Deprecated. 
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> java.util.Iterator<T> minimum(java.util.Collection<? extends T> c,
                                                BinaryFunctor<T,T,T> bf)
Deprecated. 
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.

maximum

public static <T extends java.lang.Comparable<? super T>> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c)
Deprecated. 
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> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c,
                                                java.util.Comparator<T> comp)
Deprecated. 
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> java.util.Iterator<T> maximum(java.util.Collection<? extends T> c,
                                                BinaryFunctor<T,T,T> bf)
Deprecated. 
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.

transform

public static <T> java.util.List<T> transform(java.util.List<T> lin,
                                              UnaryFunctor<T,T> uf)
Deprecated. use ListAlgorithms.transform(List,UnaryFunctor)

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.

Returns:
the modified list

replaceAll

public static <T> java.util.List<T> replaceAll(java.util.List<T> lin,
                                               UnaryFunctor<T,java.lang.Boolean> uf,
                                               T value)
Deprecated. use ListAlgorithms.replace(List,UnaryFunctor,Object)

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.

Returns:
the modified list

removeAll

public static <T,LT extends java.util.List<? extends T>> LT removeAll(LT lin,
                                                                      T value)
Deprecated. use ListAlgorithms.remove(List,Object)

removes all instances of the given element from the list

Returns:
the modified list

removeAll

public static <T,LT extends java.util.List<? extends T>> LT removeAll(LT lin,
                                                                      T value,
                                                                      Equality<T> eq)
Deprecated. use ListAlgorithms.remove(List,Object)

removes all instances of the given element from the list

Returns:
the modified list

removeAll

public static <T,LT extends java.util.List<? extends T>> LT removeAll(LT lin,
                                                                      UnaryFunctor<T,java.lang.Boolean> uf)
Deprecated. use ListAlgorithms.remove(List,UnaryFunctor)

removes all elements from the list for which the functor returns TRUE

Returns:
the modified list

unique

public static <T,LT extends java.util.List<? extends T>> LT unique(LT lin)
Deprecated. use ListAlgorithms.unique(List)

removes all adjacent duplicate values in the given list, using equals() to compare adjacent elements

Returns:
the modified list

unique

public static <T,LT extends java.util.List<? extends T>> LT unique(LT lin,
                                                                   BinaryFunctor<T,T,java.lang.Boolean> eq)
Deprecated. use ListAlgorithms.unique(List,BinaryFunctor)

removes all adjacent duplicate values in the given list, using the given functor to compare adjacent elements

Returns:
the modified list


Copyright © 2002-2006 David A. Hall. All Rights Reserved.