edu.mit.jmwe.util
Class LimitedIterator<T>

java.lang.Object
  extended by edu.mit.jmwe.util.LimitedIterator<T>
Type Parameters:
T - the type of objects that the iterator returns
All Implemented Interfaces:
Iterator<T>

public class LimitedIterator<T>
extends Object
implements Iterator<T>

Wrapper for a given iterator that will return a limited number of elements from that iterator.

Since:
jMWE 1.0.0
Version:
$Id: LimitedIterator.java 557 2011-05-05 19:22:32Z markaf $
Author:
M.A. Finlayson

Constructor Summary
LimitedIterator(Iterator<? extends T> backingItr, int limit)
          Constructs the limited iterator from a backing iterator and a limit that determines how many of the backing iterator's elements will be returned by the limited iterator.
 
Method Summary
 boolean hasNext()
           
 T next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LimitedIterator

public LimitedIterator(Iterator<? extends T> backingItr,
                       int limit)
Constructs the limited iterator from a backing iterator and a limit that determines how many of the backing iterator's elements will be returned by the limited iterator.

Parameters:
backingItr - the iterator that will be used to back this iterator. May not be null.
limit - the number of elements that will be returned by the limited iterator. If the limit is zero or negative, there is no limit on the number of items returned.
Throws:
NullPointerException - if the backing iterator is null.
Since:
jMWE 1.0.0
Method Detail

hasNext

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

next

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

remove

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


Copyright © 2011 Massachusetts Institute of Technology. All Rights Reserved.