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

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

public class Merge<T>
extends BinaryFunctor<java.util.Iterator<? extends T>,java.util.Iterator<? extends T>,MergeIterator<T>>

Returns an iterator based on the two input iterators that will merge their contents. If the contents of both input iterators are sorted, then the iterator returned will be sorted as well.

To serialize a Merge, the comparator passed at construction must be Serializable.

Copyright © 2003 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface Merge.Visitor
          Interface for classes that may interpret an Merge functor.
 
Constructor Summary
Merge(java.util.Comparator<T> comp)
          Builds an Merge functor that will use the given comparator to compare corresponding elements of two input iterators..
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(Merge) method, if it implements the nested Visitor interface.
 MergeIterator<T> fn(java.util.Iterator<? extends T> iter1, java.util.Iterator<? extends T> iter2)
          Apply the functor to each element in the iteration and return an iterator over the results
 java.util.Comparator<T> getComparator()
          Returns the functor used to process elements in an iteration.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.BinaryFunctor
bind, bind1st, bind2nd, compose, compose, distribute, generate, generate1st, generate2nd
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Merge

public Merge(java.util.Comparator<T> comp)
Builds an Merge functor that will use the given comparator to compare corresponding elements of two input iterators..

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

getComparator

public java.util.Comparator<T> getComparator()
Returns the functor used to process elements in an iteration.


fn

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

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

accept

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

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

toString

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


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