Package org.apache.jena.util.iterator
Class NiceIterator<T>
- java.lang.Object
-
- org.apache.jena.util.iterator.NiceIterator<T>
-
- All Implemented Interfaces:
java.util.Iterator<T>
,IteratorCloseable<T>
,Closeable
,ClosableIterator<T>
,ExtendedIterator<T>
- Direct Known Subclasses:
ContNodeIteratorImpl
,LazyIterator
,Map1Iterator
,MapFilterIterator
,NullIterator
,ObjectIterator
,SeqNodeIteratorImpl
,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 forandThen
,filterKeep
andfilterDrop
; these can be reused from any other class. It defines equivalent instance methods for descendants and to satisfy ExtendedIterator.
-
-
Constructor Summary
Constructors Constructor Description NiceIterator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 fromit
, in order, consuming that iterator.static <T> java.util.Set<T>
asSet(ExtendedIterator<T> it)
Answer a list of the elements ofit
in order, consuming this iterator.void
close()
default close: don't need to do anything.static void
close(java.util.Iterator<?> it)
Ifit
isCloseable
, close it.static <T> ExtendedIterator<T>
emptyIterator()
An iterator over no elements.FilterIterator<T>
filterDrop(java.util.function.Predicate<T> f)
make a new iterator, which is our elements that do not pass the filterFilterIterator<T>
filterKeep(java.util.function.Predicate<T> f)
make a new iterator, which is our elements that pass the filterboolean
hasNext()
default hasNext: no elements, return false.<U> ExtendedIterator<U>
mapWith(java.util.function.Function<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
-
Methods inherited from interface org.apache.jena.util.iterator.ExtendedIterator
forEach, nextOptional
-
-
-
-
Method Detail
-
close
public void close()
default close: don't need to do anything.- Specified by:
close
in interfaceClosableIterator<T>
- Specified by:
close
in interfaceCloseable
-
hasNext
public boolean hasNext()
default hasNext: no elements, return false.- Specified by:
hasNext
in interfacejava.util.Iterator<T>
-
next
public T next()
default next: throw an exception.- Specified by:
next
in interfacejava.util.Iterator<T>
-
remove
public void remove()
default remove: we have no elements, so we can't remove any.- Specified by:
remove
in interfacejava.util.Iterator<T>
-
removeNext
public T removeNext()
Answer the next object, and remove it.- Specified by:
removeNext
in interfaceExtendedIterator<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 interfaceExtendedIterator<T>
-
filterKeep
public FilterIterator<T> filterKeep(java.util.function.Predicate<T> f)
make a new iterator, which is our elements that pass the filter- Specified by:
filterKeep
in interfaceExtendedIterator<T>
-
filterDrop
public FilterIterator<T> filterDrop(java.util.function.Predicate<T> f)
make a new iterator, which is our elements that do not pass the filter- Specified by:
filterDrop
in interfaceExtendedIterator<T>
-
mapWith
public <U> ExtendedIterator<U> mapWith(java.util.function.Function<T,U> map1)
make a new iterator which is the elementwise _map1_ of the base iterator.- Specified by:
mapWith
in interfaceExtendedIterator<T>
-
close
public static void close(java.util.Iterator<?> it)
Ifit
isCloseable
, close it.
-
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 interfaceExtendedIterator<T>
-
toSet
public java.util.Set<T> toSet()
Answer a list of the elements in order, consuming this iterator.- Specified by:
toSet
in interfaceExtendedIterator<T>
-
asSet
public static <T> java.util.Set<T> asSet(ExtendedIterator<T> it)
Answer a list of the elements ofit
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 fromit
, in order, consuming that iterator. Canonical implementation of toList().
-
-