net.sf.jga.algorithms
Class Summarize

java.lang.Object
  extended by net.sf.jga.algorithms.Summarize

public class Summarize
extends java.lang.Object

Algorithms that consume input and produce a single value. The input may be an array, collection, or iteration.

Copyright © 2006 David A. Hall


Constructor Summary
Summarize()
           
 
Method Summary
static
<T> T
accumulate(java.lang.Iterable<? extends T> values, BinaryFunctor<T,T,T> fn)
           
static
<T> T
accumulate(java.lang.Iterable<? extends T> values, T init, BinaryFunctor<T,T,T> fn)
           
static
<T> T
accumulate(java.util.Iterator<? extends T> iterator, BinaryFunctor<T,T,T> fn)
           
static
<T> T
accumulate(java.util.Iterator<? extends T> iterator, T init, BinaryFunctor<T,T,T> fn)
           
static
<T> T
accumulate(T[] ts, BinaryFunctor<T,T,T> fn)
           
static
<T> T
accumulate(T[] ts, T initial, BinaryFunctor<T,T,T> fn)
           
static
<T extends java.lang.Number>
T
average(java.lang.Class<T> type, java.lang.Iterable<T> ts)
          Returns the average of the values
static
<T extends java.lang.Number>
T
average(java.lang.Class<T> type, java.util.Iterator<T> ts)
          Returns the average of the values.
static
<T extends java.lang.Number>
T
average(java.lang.Class<T> type, T[] ts)
          Returns the average of the values
static
<T extends java.lang.Number>
T
average(T[] ts)
          Returns the average of the values
static
<T> long
count(java.lang.Iterable<? extends T> input)
          Returns the number of elements in the input.
static
<T> long
count(java.lang.Iterable<? extends T> input, Equality<T> eq, T value)
          Deprecated. - switching the order of arguments to be consistent with Find
static
<T> long
count(java.lang.Iterable<? extends T> input, T value)
          Returns the number of times that the given value appears in the input.
static
<T> long
count(java.lang.Iterable<? extends T> input, T value, java.util.Comparator<? super T> comp)
          Returns the number of times that the given value appears in the input, using the given Comparator.
static
<T> long
count(java.lang.Iterable<? extends T> input, T value, Equality<T> eq)
          Returns the number of times that the given value appears in the input, using the given equality operator.
static
<T> long
count(java.lang.Iterable<? extends T> input, UnaryFunctor<T,java.lang.Boolean> pred)
          Returns the number of elements in the input for which the predicate is true.
static
<T> long
count(java.util.Iterator<? extends T> iter)
          Returns the number of elements in the iterator.
static
<T> long
count(java.util.Iterator<? extends T> iter, Equality<T> eq, T value)
          Deprecated. - switching the order of arguments to be consistent with Find
static
<T> long
count(java.util.Iterator<? extends T> iter, T value)
          Returns the number of times that the given value appears in the iterator.
static
<T> long
count(java.util.Iterator<? extends T> iter, T value, java.util.Comparator<? super T> comp)
          Returns the number of times that the given value appears in the iterator, using the given equality operator.
static
<T> long
count(java.util.Iterator<? extends T> iter, T value, Equality<T> eq)
          Returns the number of times that the given value appears in the iterator, using the given equality operator.
static
<T> long
count(java.util.Iterator<? extends T> iter, UnaryFunctor<T,java.lang.Boolean> pred)
          Returns the number of elements in the iterator for which the predicate is true.
static
<T> long
count(T[] ts, Equality<T> eq, T value)
          Deprecated. - switching the order of arguments to be consistent with Find
static
<T> long
count(T[] ts, T value)
          Returns the number of times that the given value appears in the array
static
<T> long
count(T[] ts, T value, java.util.Comparator<? super T> comp)
          Returns the number of times that the given value appears in the array, using the given Comparator
static
<T> long
count(T[] ts, T value, Equality<T> eq)
          Returns the number of times that the given value appears in the array, using the given equality operator
static
<T> long
count(T[] ts, UnaryFunctor<T,java.lang.Boolean> pred)
          Returns the number of elements in the array for which the predicate is true
static
<T,R> UnaryFunctor<T,R>
forEach(java.lang.Iterable<? extends T> c, UnaryFunctor<T,R> fn)
           
static
<T,R> UnaryFunctor<T,R>
forEach(java.util.Iterator<? extends T> iter, UnaryFunctor<T,R> fn)
           
static
<T,R> UnaryFunctor<T,R>
forEach(T[] ts, UnaryFunctor<T,R> fn)
           
static
<T> T
lookup(java.lang.Iterable<? extends T> ts, T value)
          Returns the first item in the input that equals the given value using the equals() method or null if no such item exists
static
<T> T
lookup(java.lang.Iterable<? extends T> ts, T value, java.util.Comparator<? super T> comp)
          Returns the first item in the input that equals the given value using the given comparator or null if no such item exists
static
<T> T
lookup(java.lang.Iterable<? extends T> ts, T value, Equality<T> eq)
          Returns the first item in the input that equals the given value using the given Equality operator or null if no such item exists
static
<T> T
lookup(java.lang.Iterable<? extends T> ts, UnaryFunctor<T,java.lang.Boolean> fn)
          Returns the first item that in the input for which the given functor returns TRUE, or null if no such item exists
static
<T> T
lookup(java.util.Iterator<? extends T> ts, T value)
          Returns the first item in the input that equals the given value using the equals() method or null if no such item exists
static
<T> T
lookup(java.util.Iterator<? extends T> ts, T value, java.util.Comparator<? super T> comp)
          Returns the first item in the input that equals the given value using the given comparator or null if no such item exists
static
<T> T
lookup(java.util.Iterator<? extends T> ts, T value, Equality<T> eq)
          Returns the first item in the input that equals the given value using the given Equality operator or null if no such item exists
static
<T> T
lookup(java.util.Iterator<? extends T> ts, UnaryFunctor<T,java.lang.Boolean> fn)
          Returns the first value that meets the selection criteria, or null
static
<T> T
lookup(T[] ts, T value)
          Returns the first item in the array that equals the given value using the equals() method or null if no such item exists
static
<T> T
lookup(T[] ts, T value, java.util.Comparator<? super T> comp)
          Returns the first item in the array that equals the given value using the given comparator or null if no such item exists
static
<T> T
lookup(T[] ts, T value, Equality<T> eq)
          Returns the first item in the array that equals the given value using the given Equality operator or null if no such item exists
static
<T> T
lookup(T[] ts, UnaryFunctor<T,java.lang.Boolean> fn)
          Returns the first item that in the array for which the given functor returns TRUE, or null if no such item exists
static
<T extends java.lang.Comparable<? super T>>
T
max(java.lang.Iterable<? extends T> ts)
          Returns the largest T value in the input.
static
<T> T
max(java.lang.Iterable<? extends T> ts, BinaryFunctor<T,T,T> fn)
          Returns the largest T value in the input, as determined by the given functor.
static
<T> T
max(java.lang.Iterable<? extends T> ts, java.util.Comparator<? super T> comp)
          Returns the largest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Comparable<? super T>>
T
max(java.util.Iterator<? extends T> ts)
          Returns the largest T value in the input.
static
<T> T
max(java.util.Iterator<? extends T> ts, BinaryFunctor<T,T,T> fn)
          Returns the largest T value in the input, as determined by the given functor.
static
<T> T
max(java.util.Iterator<? extends T> ts, java.util.Comparator<? super T> comp)
          Returns the largest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Comparable<? super T>>
T
max(T[] ts)
          Returns the largest T value in the input.
static
<T> T
max(T[] ts, BinaryFunctor<T,T,T> fn)
          Returns the largest T value in the input, as determined by the given functor.
static
<T> T
max(T[] ts, java.util.Comparator<? super T> comp)
          Returns the largest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Comparable<? super T>>
T
min(java.lang.Iterable<? extends T> ts)
          Returns the smallest T value in the input.
static
<T> T
min(java.lang.Iterable<? extends T> ts, BinaryFunctor<T,T,T> fn)
          Returns the smallest T value in the input, as determined by the given functor.
static
<T> T
min(java.lang.Iterable<? extends T> ts, java.util.Comparator<? super T> comp)
          Returns the smallest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Comparable<? super T>>
T
min(java.util.Iterator<? extends T> ts)
          Returns the smallest T value in the input.
static
<T> T
min(java.util.Iterator<? extends T> ts, BinaryFunctor<T,T,T> fn)
          Returns the smallest T value in the input, as determined by the given functor.
static
<T> T
min(java.util.Iterator<? extends T> ts, java.util.Comparator<? super T> comp)
          Returns the smallest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Comparable<? super T>>
T
min(T[] ts)
          Returns the smallest T value in the input.
static
<T> T
min(T[] ts, BinaryFunctor<T,T,T> fn)
          Returns the smallest T value in the input, as determined by the given functor.
static
<T> T
min(T[] ts, java.util.Comparator<? super T> comp)
          Returns the smallest T value in the input, as determined by the given comparator.
static
<T extends java.lang.Number>
T
sum(java.lang.Class<T> type, java.lang.Iterable<? extends T> ts)
          Returns the sum of the values
static
<T extends java.lang.Number>
T
sum(java.lang.Class<T> type, java.util.Iterator<? extends T> ts)
          Returns the sum of the values.
static
<T extends java.lang.Number>
T
sum(java.lang.Class<T> type, T[] ts)
          Returns the sum of the values
static
<T extends java.lang.Number>
T
sum(T[] ts)
          Returns the sum of the values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Summarize

public Summarize()
Method Detail

count

public static <T> long count(T[] ts,
                             T value)
Returns the number of times that the given value appears in the array


count

public static <T> long count(T[] ts,
                             T value,
                             java.util.Comparator<? super T> comp)
Returns the number of times that the given value appears in the array, using the given Comparator


count

public static <T> long count(T[] ts,
                             Equality<T> eq,
                             T value)
Deprecated. - switching the order of arguments to be consistent with Find

Returns the number of times that the given value appears in the array, using the given equality operator


count

public static <T> long count(T[] ts,
                             T value,
                             Equality<T> eq)
Returns the number of times that the given value appears in the array, using the given equality operator


count

public static <T> long count(T[] ts,
                             UnaryFunctor<T,java.lang.Boolean> pred)
Returns the number of elements in the array for which the predicate is true


count

public static <T> long count(java.lang.Iterable<? extends T> input)
Returns the number of elements in the input.


count

public static <T> long count(java.lang.Iterable<? extends T> input,
                             T value)
Returns the number of times that the given value appears in the input.


count

public static <T> long count(java.lang.Iterable<? extends T> input,
                             T value,
                             java.util.Comparator<? super T> comp)
Returns the number of times that the given value appears in the input, using the given Comparator.


count

public static <T> long count(java.lang.Iterable<? extends T> input,
                             Equality<T> eq,
                             T value)
Deprecated. - switching the order of arguments to be consistent with Find

Returns the number of times that the given value appears in the input, using the given equality operator.


count

public static <T> long count(java.lang.Iterable<? extends T> input,
                             T value,
                             Equality<T> eq)
Returns the number of times that the given value appears in the input, using the given equality operator.


count

public static <T> long count(java.lang.Iterable<? extends T> input,
                             UnaryFunctor<T,java.lang.Boolean> pred)
Returns the number of elements in the input for which the predicate is true.


count

public static <T> long count(java.util.Iterator<? extends T> iter)
Returns the number of elements in the iterator. The iterator is consumed entirely by this function.


count

public static <T> long count(java.util.Iterator<? extends T> iter,
                             T value)
Returns the number of times that the given value appears in the iterator. The iterator is consumed entirely by this function.


count

public static <T> long count(java.util.Iterator<? extends T> iter,
                             T value,
                             java.util.Comparator<? super T> comp)
Returns the number of times that the given value appears in the iterator, using the given equality operator. The iterator is consumed entirely by this function.


count

public static <T> long count(java.util.Iterator<? extends T> iter,
                             Equality<T> eq,
                             T value)
Deprecated. - switching the order of arguments to be consistent with Find

Returns the number of times that the given value appears in the iterator, using the given equality operator. The iterator is consumed entirely by this function.


count

public static <T> long count(java.util.Iterator<? extends T> iter,
                             T value,
                             Equality<T> eq)
Returns the number of times that the given value appears in the iterator, using the given equality operator. The iterator is consumed entirely by this function.


count

public static <T> long count(java.util.Iterator<? extends T> iter,
                             UnaryFunctor<T,java.lang.Boolean> pred)
Returns the number of elements in the iterator for which the predicate is true. The iterator is consumed entirely by this function.


min

public static <T> T min(T[] ts,
                        java.util.Comparator<? super T> comp)
Returns the smallest T value in the input, as determined by the given comparator.


min

public static <T extends java.lang.Comparable<? super T>> T min(T[] ts)
Returns the smallest T value in the input.


min

public static <T> T min(T[] ts,
                        BinaryFunctor<T,T,T> fn)
Returns the smallest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments.


min

public static <T> T min(java.lang.Iterable<? extends T> ts,
                        java.util.Comparator<? super T> comp)
Returns the smallest T value in the input, as determined by the given comparator.


min

public static <T extends java.lang.Comparable<? super T>> T min(java.lang.Iterable<? extends T> ts)
Returns the smallest T value in the input.


min

public static <T> T min(java.lang.Iterable<? extends T> ts,
                        BinaryFunctor<T,T,T> fn)
Returns the smallest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments.


min

public static <T> T min(java.util.Iterator<? extends T> ts,
                        java.util.Comparator<? super T> comp)
Returns the smallest T value in the input, as determined by the given comparator. The input iterator is consumed.


min

public static <T extends java.lang.Comparable<? super T>> T min(java.util.Iterator<? extends T> ts)
Returns the smallest T value in the input. The input iterator is consumed.


min

public static <T> T min(java.util.Iterator<? extends T> ts,
                        BinaryFunctor<T,T,T> fn)
Returns the smallest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments. The input iterator is consumed.


max

public static <T> T max(T[] ts,
                        java.util.Comparator<? super T> comp)
Returns the largest T value in the input, as determined by the given comparator.


max

public static <T extends java.lang.Comparable<? super T>> T max(T[] ts)
Returns the largest T value in the input.


max

public static <T> T max(T[] ts,
                        BinaryFunctor<T,T,T> fn)
Returns the largest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments.


max

public static <T> T max(java.lang.Iterable<? extends T> ts,
                        java.util.Comparator<? super T> comp)
Returns the largest T value in the input, as determined by the given comparator.


max

public static <T extends java.lang.Comparable<? super T>> T max(java.lang.Iterable<? extends T> ts)
Returns the largest T value in the input.


max

public static <T> T max(java.lang.Iterable<? extends T> ts,
                        BinaryFunctor<T,T,T> fn)
Returns the largest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments.


max

public static <T> T max(java.util.Iterator<? extends T> ts,
                        java.util.Comparator<? super T> comp)
Returns the largest T value in the input, as determined by the given comparator. The input iterator is consumed.


max

public static <T extends java.lang.Comparable<? super T>> T max(java.util.Iterator<? extends T> ts)
Returns the largest T value in the input. The input iterator is consumed.


max

public static <T> T max(java.util.Iterator<? extends T> ts,
                        BinaryFunctor<T,T,T> fn)
Returns the largest T value in the input, as determined by the given functor. The functor is expected to return the smaller of its two arguments. The input iterator is consumed.


sum

public static <T extends java.lang.Number> T sum(T[] ts)
Returns the sum of the values


sum

public static <T extends java.lang.Number> T sum(java.lang.Class<T> type,
                                                 T[] ts)
Returns the sum of the values


sum

public static <T extends java.lang.Number> T sum(java.lang.Class<T> type,
                                                 java.lang.Iterable<? extends T> ts)
Returns the sum of the values


sum

public static <T extends java.lang.Number> T sum(java.lang.Class<T> type,
                                                 java.util.Iterator<? extends T> ts)
Returns the sum of the values. The iterator is entirely consumed.


accumulate

public static <T> T accumulate(T[] ts,
                               BinaryFunctor<T,T,T> fn)

accumulate

public static <T> T accumulate(T[] ts,
                               T initial,
                               BinaryFunctor<T,T,T> fn)

accumulate

public static <T> T accumulate(java.lang.Iterable<? extends T> values,
                               BinaryFunctor<T,T,T> fn)

accumulate

public static <T> T accumulate(java.lang.Iterable<? extends T> values,
                               T init,
                               BinaryFunctor<T,T,T> fn)

accumulate

public static <T> T accumulate(java.util.Iterator<? extends T> iterator,
                               BinaryFunctor<T,T,T> fn)

accumulate

public static <T> T accumulate(java.util.Iterator<? extends T> iterator,
                               T init,
                               BinaryFunctor<T,T,T> fn)

forEach

public static <T,R> UnaryFunctor<T,R> forEach(T[] ts,
                                              UnaryFunctor<T,R> fn)

forEach

public static <T,R> UnaryFunctor<T,R> forEach(java.lang.Iterable<? extends T> c,
                                              UnaryFunctor<T,R> fn)

forEach

public static <T,R> UnaryFunctor<T,R> forEach(java.util.Iterator<? extends T> iter,
                                              UnaryFunctor<T,R> fn)

average

public static <T extends java.lang.Number> T average(T[] ts)
Returns the average of the values


average

public static <T extends java.lang.Number> T average(java.lang.Class<T> type,
                                                     T[] ts)
Returns the average of the values


average

public static <T extends java.lang.Number> T average(java.lang.Class<T> type,
                                                     java.lang.Iterable<T> ts)
Returns the average of the values


average

public static <T extends java.lang.Number> T average(java.lang.Class<T> type,
                                                     java.util.Iterator<T> ts)
Returns the average of the values. The iterator is entirely consumed.


lookup

public static <T> T lookup(T[] ts,
                           T value)
Returns the first item in the array that equals the given value using the equals() method or null if no such item exists


lookup

public static <T> T lookup(T[] ts,
                           T value,
                           java.util.Comparator<? super T> comp)
Returns the first item in the array that equals the given value using the given comparator or null if no such item exists


lookup

public static <T> T lookup(T[] ts,
                           T value,
                           Equality<T> eq)
Returns the first item in the array that equals the given value using the given Equality operator or null if no such item exists


lookup

public static <T> T lookup(T[] ts,
                           UnaryFunctor<T,java.lang.Boolean> fn)
Returns the first item that in the array for which the given functor returns TRUE, or null if no such item exists


lookup

public static <T> T lookup(java.lang.Iterable<? extends T> ts,
                           T value)
Returns the first item in the input that equals the given value using the equals() method or null if no such item exists


lookup

public static <T> T lookup(java.lang.Iterable<? extends T> ts,
                           T value,
                           java.util.Comparator<? super T> comp)
Returns the first item in the input that equals the given value using the given comparator or null if no such item exists


lookup

public static <T> T lookup(java.lang.Iterable<? extends T> ts,
                           T value,
                           Equality<T> eq)
Returns the first item in the input that equals the given value using the given Equality operator or null if no such item exists


lookup

public static <T> T lookup(java.lang.Iterable<? extends T> ts,
                           UnaryFunctor<T,java.lang.Boolean> fn)
Returns the first item that in the input for which the given functor returns TRUE, or null if no such item exists


lookup

public static <T> T lookup(java.util.Iterator<? extends T> ts,
                           T value)
Returns the first item in the input that equals the given value using the equals() method or null if no such item exists


lookup

public static <T> T lookup(java.util.Iterator<? extends T> ts,
                           T value,
                           java.util.Comparator<? super T> comp)
Returns the first item in the input that equals the given value using the given comparator or null if no such item exists


lookup

public static <T> T lookup(java.util.Iterator<? extends T> ts,
                           T value,
                           Equality<T> eq)
Returns the first item in the input that equals the given value using the given Equality operator or null if no such item exists


lookup

public static <T> T lookup(java.util.Iterator<? extends T> ts,
                           UnaryFunctor<T,java.lang.Boolean> fn)
Returns the first value that meets the selection criteria, or null



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