net.sf.jga.fn.algorithm

Class Count<T>

public class Count<T> extends AbstractUnaryFunctor<Iterator<? extends T>,Long> implements Serializable

Counts values in an iteration.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceCount.Visitor
Interface for classes that may interpret an Count functor.
Constructor Summary
Count(T value)
Builds a Count functor that counts instances of a specific value in an iteration, using the value's equals() method.
Count(Equality<T> eq, T value)
Builds a Count functor that counts instances of a specific value in an iteration, using the given Equality predicate.
Count(UnaryFunctor<T,Boolean> eq)
Builds a Count functor that counts instances in an iteration for which the given predicate is true
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(Count) method, if it implements the nested Visitor interface.
Longfn(Iterator<? extends T> iterator)
Returns the number of elements in the iteration that meet the given criteria.
UnaryFunctor<T,Boolean>getComparisonFn()
Returns the predicate used to determine if an element should be counted.
StringtoString()

Constructor Detail

Count

public Count(T value)
Builds a Count functor that counts instances of a specific value in an iteration, using the value's equals() method.

Count

public Count(Equality<T> eq, T value)
Builds a Count functor that counts instances of a specific value in an iteration, using the given Equality predicate.

Count

public Count(UnaryFunctor<T,Boolean> eq)
Builds a Count functor that counts instances in an iteration for which the given predicate is true

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(Count) method, if it implements the nested Visitor interface.

fn

public Long fn(Iterator<? extends T> iterator)
Returns the number of elements in the iteration that meet the given criteria.

getComparisonFn

public UnaryFunctor<T,Boolean> getComparisonFn()
Returns the predicate used to determine if an element should be counted.

toString

public String toString()