com.hp.hpl.jena.util.iterator
Class NiceIterator<T>

java.lang.Object
  extended by com.hp.hpl.jena.util.iterator.NiceIterator<T>
All Implemented Interfaces:
ClosableIterator<T>, ExtendedIterator<T>, java.util.Iterator<T>
Direct Known Subclasses:
Map1Iterator, MapFilterIterator, NullIterator, SingletonIterator, WrappedIterator

public class NiceIterator<T>
extends java.lang.Object
implements ExtendedIterator<T>

NiceIterator is the standard base class implementing ExtendedIterator. It provides the static methods for andThen, filterKeep and filterDrop; these can be reused from any other class. It defines equivalent instance methods for descendants and to satisfy ExtendedIterator.

Author:
kers

Constructor Summary
NiceIterator()
           
 
Method Summary
static
<T> ExtendedIterator<T>
andThen(java.util.Iterator<T> a, java.util.Iterator<? extends T> b)
          concatenate two closable iterators.
<X extends T>
ExtendedIterator<T>
andThen(java.util.Iterator<X> other)
          make a new iterator, which is us then the other chap.
static
<T> java.util.List<T>
asList(ExtendedIterator<T> it)
          Answer a list of the elements from it, in order, consuming that iterator.
static
<T> java.util.Set<T>
asSet(ExtendedIterator<T> it)
          Answer a list of the elements of it in order, consuming this iterator.
 void close()
          default close: don't need to do anything.
static void close(java.util.Iterator<?> it)
          If it is a Closableiterator, close it.
static
<T> ExtendedIterator<T>
emptyIterator()
          An iterator over no elements.
 ExtendedIterator<T> filterDrop(Filter<T> f)
          make a new iterator, which is our elements that do not pass the filter
 ExtendedIterator<T> filterKeep(Filter<T> f)
          make a new iterator, which is our elements that pass the filter
 boolean hasNext()
          default hasNext: no elements, return false.
<U> ExtendedIterator<U>
mapWith(Map1<T,U> map1)
          make a new iterator which is the elementwise _map1_ of the base iterator.
 T next()
          default next: throw an exception.
 void remove()
          default remove: we have no elements, so we can't remove any.
 T removeNext()
          Answer the next object, and remove it.
 java.util.List<T> toList()
          Answer a list of the elements in order, consuming this iterator.
 java.util.Set<T> toSet()
          Answer a list of the elements in order, consuming this iterator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NiceIterator

public NiceIterator()
Method Detail

close

public void close()
default close: don't need to do anything.

Specified by:
close in interface ClosableIterator<T>

hasNext

public boolean hasNext()
default hasNext: no elements, return false.

Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()
default next: throw an exception.

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

remove

public void remove()
default remove: we have no elements, so we can't remove any.

Specified by:
remove in interface java.util.Iterator<T>

removeNext

public T removeNext()
Answer the next object, and remove it.

Specified by:
removeNext in interface ExtendedIterator<T>

andThen

public static <T> ExtendedIterator<T> andThen(java.util.Iterator<T> a,
                                              java.util.Iterator<? extends T> b)
concatenate two closable iterators.


andThen

public <X extends T> ExtendedIterator<T> andThen(java.util.Iterator<X> other)
make a new iterator, which is us then the other chap.

Specified by:
andThen in interface ExtendedIterator<T>

filterKeep

public ExtendedIterator<T> filterKeep(Filter<T> f)
make a new iterator, which is our elements that pass the filter

Specified by:
filterKeep in interface ExtendedIterator<T>

filterDrop

public ExtendedIterator<T> filterDrop(Filter<T> f)
make a new iterator, which is our elements that do not pass the filter

Specified by:
filterDrop in interface ExtendedIterator<T>

mapWith

public <U> ExtendedIterator<U> mapWith(Map1<T,U> map1)
make a new iterator which is the elementwise _map1_ of the base iterator.

Specified by:
mapWith in interface ExtendedIterator<T>

close

public static void close(java.util.Iterator<?> it)
If it is a Closableiterator, close it. Abstracts away from tests [that were] scattered through the code.


emptyIterator

public static <T> ExtendedIterator<T> emptyIterator()
An iterator over no elements.

Returns:
A class singleton which doesn't iterate.

toList

public java.util.List<T> toList()
Answer a list of the elements in order, consuming this iterator.

Specified by:
toList in interface ExtendedIterator<T>

toSet

public java.util.Set<T> toSet()
Answer a list of the elements in order, consuming this iterator.

Specified by:
toSet in interface ExtendedIterator<T>

asSet

public static <T> java.util.Set<T> asSet(ExtendedIterator<T> it)
Answer a list of the elements of it in order, consuming this iterator. Canonical implementation of toSet().


asList

public static <T> java.util.List<T> asList(ExtendedIterator<T> it)
Answer a list of the elements from it, in order, consuming that iterator. Canonical implementation of toList().



Copyright ? 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP