net.sf.jga.fn.algorithm
Class Count<T>

java.lang.Object
  extended by net.sf.jga.fn.UnaryFunctor<java.util.Iterator<? extends T>,java.lang.Long>
      extended by net.sf.jga.fn.algorithm.Count<T>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class Count<T>
extends UnaryFunctor<java.util.Iterator<? extends T>,java.lang.Long>

Counts values in an iteration.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface Count.Visitor
          Interface for classes that may interpret an Count functor.
 
Constructor Summary
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(T value)
          Builds a Count functor that counts instances of a specific value in an iteration, using the value's equals() method.
Count(UnaryFunctor<T,java.lang.Boolean> eq)
          Builds a Count functor that counts instances in an iteration for which the given predicate is true
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(Count) method, if it implements the nested Visitor interface.
 java.lang.Long fn(java.util.Iterator<? extends T> iterator)
          Returns the number of elements in the iteration that meet the given criteria.
 UnaryFunctor<T,java.lang.Boolean> getComparisonFn()
          Returns the predicate used to determine if an element should be counted.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, compose, compose, generate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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,java.lang.Boolean> eq)
Builds a Count functor that counts instances in an iteration for which the given predicate is true

Method Detail

getComparisonFn

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


fn

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

Specified by:
fn in class UnaryFunctor<java.util.Iterator<? extends T>,java.lang.Long>

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class UnaryFunctor<java.util.Iterator<? extends T>,java.lang.Long>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


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