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

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

public class ReplaceAll<T>
extends UnaryFunctor<java.util.Iterator<? extends T>,TransformIterator<T,T>>

Replaces all instances in an iteration that pass the given test with the given value.

To Serialize a ReplaceAll, the generic parameter T must be serializable.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface ReplaceAll.Visitor
          Interface for classes that may interpret an ReplaceAll functor.
 
Constructor Summary
ReplaceAll(UnaryFunctor<T,java.lang.Boolean> test, T value)
          Builds an ReplaceAll functor that will apply the given test to elements in an iteration, and replace those elements that pass with the given value.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(ReplaceAll) method, if it implements the nested Visitor interface.
 TransformIterator<T,T> fn(java.util.Iterator<? extends T> iterator)
          Apply the functor to each element in the iteration and return an iterator over the results
 UnaryFunctor<T,T> getFunction()
          Returns the functor used to process elements in an iteration.
 T getValue()
          Returns the replacement value
 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

ReplaceAll

public ReplaceAll(UnaryFunctor<T,java.lang.Boolean> test,
                  T value)
Builds an ReplaceAll functor that will apply the given test to elements in an iteration, and replace those elements that pass with the given value.

Throws:
java.lang.IllegalArgumentException - if the test is null
Method Detail

getFunction

public UnaryFunctor<T,T> getFunction()
Returns the functor used to process elements in an iteration.


getValue

public T getValue()
Returns the replacement value


fn

public TransformIterator<T,T> fn(java.util.Iterator<? extends T> iterator)
Apply the functor to each element in the iteration and return an iterator over the results

Specified by:
fn in class UnaryFunctor<java.util.Iterator<? extends T>,TransformIterator<T,T>>
Returns:
an iterator over the results of the transformation

accept

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

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

toString

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


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