net.sf.jga.util
Class MergeIterator<T>

java.lang.Object
  extended by net.sf.jga.util.MergeIterator<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Iterator<T>

public class MergeIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>, java.lang.Iterable<T>

Iterator that merges the contents of two input iterators.

Copyright © 2003 David A. Hall

Author:
David A. Hall

Constructor Summary
MergeIterator(java.util.Iterator<? extends T> base1, java.util.Iterator<? extends T> base2, BinaryFunctor<T,T,java.lang.Boolean> pred)
          Builds a MergeIterator for the given base iterators that uses the given predicate to compare corresponding elements.
MergeIterator(java.util.Iterator<? extends T> base1, java.util.Iterator<? extends T> base2, java.util.Comparator<T> comp)
          Builds a MergeIterator for the given base iterators that uses the given Comparator to compare corresponding elements.
 
Method Summary
 boolean hasNext()
           
 java.util.Iterator<T> iterator()
           
 T next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MergeIterator

public MergeIterator(java.util.Iterator<? extends T> base1,
                     java.util.Iterator<? extends T> base2,
                     java.util.Comparator<T> comp)
Builds a MergeIterator for the given base iterators that uses the given Comparator to compare corresponding elements. The Comparator will be used with a LessEqualComp predicate.

Throws:
java.lang.IllegalArgumentException - if either argument is null

MergeIterator

public MergeIterator(java.util.Iterator<? extends T> base1,
                     java.util.Iterator<? extends T> base2,
                     BinaryFunctor<T,T,java.lang.Boolean> pred)
Builds a MergeIterator for the given base iterators that uses the given predicate to compare corresponding elements. The predicate should return TRUE if its first argument is less than or equal to the second.

Throws:
java.lang.IllegalArgumentException - if either argument is null
Method Detail

iterator

public java.util.Iterator<T> iterator()
Specified by:
iterator in interface java.lang.Iterable<T>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()
Specified by:
next in interface java.util.Iterator<T>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<T>


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