org.openjena.atlas.iterator
Class Iter<T>

java.lang.Object
  extended by org.openjena.atlas.iterator.Iter<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>

public class Iter<T>
extends Object
implements Iterable<T>, Iterator<T>


Nested Class Summary
static interface Iter.Folder<X,Y>
           
 
Method Summary
static
<T> Iterator<T>
append(Iterable<T> iter1, Iterable<T> iter2)
           
static
<T> Iterator<T>
append(Iterator<? extends T> iter1, Iterator<? extends T> iter2)
           
 Iter<T> append(Iterator<T> iter)
           
 void apply(Action<T> action)
           
static
<T> void
apply(Iterable<? extends T> stream, Action<T> action)
           
static
<T> void
apply(Iterator<? extends T> stream, Action<T> action)
           
static
<K,V> void
apply(Map<K,V> map, ActionKeyValue<K,V> action)
           
 String asString()
           
static
<T> String
asString(Iter<T> stream)
           
static
<T> String
asString(Iter<T> stream, AccString<T> formatter)
           
static
<T> String
asString(Iter<T> stream, String sep)
           
static
<T> String
asString(Iterable<T> stream)
           
static
<T> String
asString(Iterable<T> stream, AccString<T> formatter)
           
static
<T> String
asString(Iterable<T> stream, String sep)
           
static
<T> String
asString(Iterator<T> stream)
           
static
<T> String
asString(Iterator<T> stream, AccString<T> formatter)
           
static
<T> String
asString(Iterator<T> stream, String sep)
           
 String asString(String sep)
           
static
<T> void
close(Iterator<T> iter)
           
static
<T> Iter<T>
concat(Iter<T> iter1, Iter<T> iter2)
           
static
<T> Iterator<T>
concat(Iterator<T> iter1, Iterator<T> iter2)
           
static
<T> void
consume(Iterable<T> iterator)
          Consume the iterable
static
<T> void
consume(Iterator<T> iterator)
          Consume the iterator
static
<T> Iterator<T>
convert(Iterator<?> iterator)
           
 long count()
          Count the iterator (this is destructive on the iterator)
static
<T> long
count(Iterable<T> iterator)
          Count the iterable - many iterable objects have a .size() operation which should be used in preference to this explicit counting operation
static
<T> long
count(Iterator<T> iterator)
          Count the iterator (this is destructive on the iterator)
static
<T> Iterator<T>
debug(Iterator<T> stream)
           
 Iter<T> distinct()
           
static
<T> Iterator<T>
distinct(Iterable<T> iter)
           
static
<T> Iterator<T>
distinct(Iterator<T> iter)
           
 boolean every(Filter<T> filter)
           
static
<T> boolean
every(Iterable<? extends T> stream, Filter<T> filter)
          Return true if every element of stream passes the filter (reads the stream)
static
<T> boolean
every(Iterator<? extends T> stream, Filter<T> filter)
          Return true if every element of stream passes the filter (reads the stream until the first element not passing the filter)
 Iter<T> filter(Filter<T> filter)
           
static
<T> Iterator<T>
filter(Iterable<? extends T> stream, Filter<T> filter)
           
static
<T> Iterator<T>
filter(Iterator<? extends T> stream, Filter<T> filter)
           
static
<T> T
first(Collection<T> collection, Filter<T> filter)
           
 T first(Filter<T> filter)
           
static
<T> T
first(Iterator<T> iter, Filter<T> filter)
           
static
<T> int
firstIndex(Collection<T> collection, Filter<T> filter)
           
 int firstIndex(Filter<T> filter)
           
static
<T> int
firstIndex(Iterator<T> iter, Filter<T> filter)
           
static
<T,R> R
foldLeft(Iterable<? extends T> stream, Iter.Folder<T,R> function, R value)
           
static
<T,R> R
foldLeft(Iterator<? extends T> stream, Iter.Folder<T,R> function, R value)
           
static
<T,R> R
foldRight(Iterable<? extends T> stream, Iter.Folder<T,R> function, R value)
           
static
<T,R> R
foldRight(Iterator<? extends T> stream, Iter.Folder<T,R> function, R value)
           
 boolean hasNext()
           
static
<T> Iter<T>
iter(Collection<T> collection)
           
static
<T> Iter<T>
iter(Iter<T> iter)
           
static
<T> Iter<T>
iter(Iterable<T> iterable)
           
static
<T> Iter<T>
iter(Iterator<T> iterator)
           
 Iterator<T> iterator()
           
static
<T> T
last(Collection<T> collection, Filter<T> filter)
           
 T last(Filter<T> filter)
           
static
<T> T
last(Iterator<T> iter, Filter<T> filter)
           
static
<T> int
lastIndex(Collection<T> collection, Filter<T> filter)
           
 int lastIndex(Filter<T> filter)
           
static
<T> int
lastIndex(Iterator<T> iter, Filter<T> filter)
           
static
<T,R> Iterator<R>
map(Iterable<? extends T> stream, Transform<T,R> converter)
           
static
<T,R> Iterator<R>
map(Iterator<? extends T> stream, Transform<T,R> converter)
           
static
<T,R> List<R>
map(List<? extends T> list, Transform<T,R> converter)
           
<R> Iter<R>
map(Transform<T,R> converter)
           
static
<T,R> Iterator<R>
mapMany(Iterable<? extends T> stream, Transform<T,Iterator<R>> converter)
           
static
<T,R> Iterator<R>
mapMany(Iterator<? extends T> stream, Transform<? super T,Iterator<R>> converter)
          Projects each element of a sequence to an Iterator<R> and flattens the resulting sequences into one sequence.
static
<T,R> List<R>
mapMany(List<? extends T> list, Transform<T,Iterator<R>> converter)
           
static
<T> Iterator<T>
materialize(Iterator<T> iter)
          Materializae an iterator, that is, force it to run now - useful in debugging
 T next()
           
static
<T> Iterator<T>
notFilter(Iterable<? extends T> stream, Filter<T> filter)
           
static
<T> Iterator<T>
notFilter(Iterator<? extends T> stream, Filter<T> filter)
           
static
<T> Iter<T>
nullIter()
           
static
<T> Iterator<T>
nullIterator()
           
 Iter<T> operate(Action<T> action)
          Apply an action to everything in the stream, yielding a stream of the same items
static
<T> Iterator<T>
operate(Iterable<? extends T> stream, Action<T> converter)
          Apply an action to everything in stream, yielding a stream of the same items
static
<T> Iterator<T>
operate(Iterator<? extends T> stream, Action<T> action)
          Apply an action to everything in stream, yielding a stream of the same items
static
<T> Iterator<T>
printWrapper(Iterator<? extends T> stream)
          Print an iterator as it gets used - this adds a printing wrapper
static
<T> Iterator<T>
printWrapper(PrintStream out, Iterator<? extends T> stream)
          Print an iterator as it gets used - this adds a printing wrapper
<R> R
reduce(Accumulate<T,R> aggregator)
           
static
<T,R> R
reduce(Iterable<? extends T> stream, Accumulate<T,R> aggregator)
           
static
<T,R> R
reduce(Iterator<? extends T> stream, Accumulate<T,R> aggregator)
           
 void remove()
           
 Iter<T> removeNulls()
           
static
<T> Iterator<T>
removeNulls(Iterable<T> iter)
           
static
<T> Iterator<T>
removeNulls(Iterator<T> iter)
           
static
<T> void
sendToSink(Iterable<T> stream, Sink<T> sink)
          Send the elements of the iterator to a sink - consumes the iterator
static
<T> void
sendToSink(Iterator<T> iter, Sink<T> sink)
          Send the elements of the iterator to a sink - consumes the iterator
 void sendToSink(Sink<T> sink)
           
static
<T> Iterator<T>
singleton(T item)
           
static
<T> Iter<T>
singletonIter(T item)
           
 boolean some(Filter<T> filter)
           
static
<T> boolean
some(Iterable<? extends T> stream, Filter<T> filter)
          Return true if every element of stream passes the filter (reads the stream until the first element passing the filter)
static
<T> boolean
some(Iterator<? extends T> stream, Filter<T> filter)
          Return true if one or more elements of stream passes the filter (reads the stream to first element passing the filter)
 List<T> toList()
           
static
<T> List<T>
toList(Iterable<? extends T> stream)
           
static
<T> List<T>
toList(Iterator<? extends T> stream)
           
 Set<T> toSet()
           
static
<T> Set<T>
toSet(Iterable<? extends T> stream)
           
static
<T> Set<T>
toSet(Iterator<? extends T> stream)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

singleton

public static <T> Iterator<T> singleton(T item)

nullIterator

public static <T> Iterator<T> nullIterator()

toSet

public static <T> Set<T> toSet(Iterable<? extends T> stream)

toSet

public static <T> Set<T> toSet(Iterator<? extends T> stream)

toList

public static <T> List<T> toList(Iterable<? extends T> stream)

toList

public static <T> List<T> toList(Iterator<? extends T> stream)

foldLeft

public static <T,R> R foldLeft(Iterable<? extends T> stream,
                               Iter.Folder<T,R> function,
                               R value)

foldLeft

public static <T,R> R foldLeft(Iterator<? extends T> stream,
                               Iter.Folder<T,R> function,
                               R value)

foldRight

public static <T,R> R foldRight(Iterable<? extends T> stream,
                                Iter.Folder<T,R> function,
                                R value)

foldRight

public static <T,R> R foldRight(Iterator<? extends T> stream,
                                Iter.Folder<T,R> function,
                                R value)

reduce

public static <T,R> R reduce(Iterable<? extends T> stream,
                             Accumulate<T,R> aggregator)

reduce

public static <T,R> R reduce(Iterator<? extends T> stream,
                             Accumulate<T,R> aggregator)

apply

public static <T> void apply(Iterable<? extends T> stream,
                             Action<T> action)

apply

public static <T> void apply(Iterator<? extends T> stream,
                             Action<T> action)

apply

public static <K,V> void apply(Map<K,V> map,
                               ActionKeyValue<K,V> action)

filter

public static <T> Iterator<T> filter(Iterable<? extends T> stream,
                                     Filter<T> filter)

filter

public static <T> Iterator<T> filter(Iterator<? extends T> stream,
                                     Filter<T> filter)

notFilter

public static <T> Iterator<T> notFilter(Iterable<? extends T> stream,
                                        Filter<T> filter)

notFilter

public static <T> Iterator<T> notFilter(Iterator<? extends T> stream,
                                        Filter<T> filter)

every

public static <T> boolean every(Iterable<? extends T> stream,
                                Filter<T> filter)
Return true if every element of stream passes the filter (reads the stream)


every

public static <T> boolean every(Iterator<? extends T> stream,
                                Filter<T> filter)
Return true if every element of stream passes the filter (reads the stream until the first element not passing the filter)


some

public static <T> boolean some(Iterable<? extends T> stream,
                               Filter<T> filter)
Return true if every element of stream passes the filter (reads the stream until the first element passing the filter)


some

public static <T> boolean some(Iterator<? extends T> stream,
                               Filter<T> filter)
Return true if one or more elements of stream passes the filter (reads the stream to first element passing the filter)


map

public static <T,R> Iterator<R> map(Iterable<? extends T> stream,
                                    Transform<T,R> converter)

map

public static <T,R> Iterator<R> map(Iterator<? extends T> stream,
                                    Transform<T,R> converter)

map

public static <T,R> List<R> map(List<? extends T> list,
                                Transform<T,R> converter)

mapMany

public static <T,R> Iterator<R> mapMany(Iterator<? extends T> stream,
                                        Transform<? super T,Iterator<R>> converter)
Projects each element of a sequence to an Iterator<R> and flattens the resulting sequences into one sequence.


mapMany

public static <T,R> Iterator<R> mapMany(Iterable<? extends T> stream,
                                        Transform<T,Iterator<R>> converter)

mapMany

public static <T,R> List<R> mapMany(List<? extends T> list,
                                    Transform<T,Iterator<R>> converter)

operate

public static <T> Iterator<T> operate(Iterable<? extends T> stream,
                                      Action<T> converter)
Apply an action to everything in stream, yielding a stream of the same items


operate

public static <T> Iterator<T> operate(Iterator<? extends T> stream,
                                      Action<T> action)
Apply an action to everything in stream, yielding a stream of the same items


printWrapper

public static <T> Iterator<T> printWrapper(Iterator<? extends T> stream)
Print an iterator as it gets used - this adds a printing wrapper


printWrapper

public static <T> Iterator<T> printWrapper(PrintStream out,
                                           Iterator<? extends T> stream)
Print an iterator as it gets used - this adds a printing wrapper


append

public static <T> Iterator<T> append(Iterable<T> iter1,
                                     Iterable<T> iter2)

append

public static <T> Iterator<T> append(Iterator<? extends T> iter1,
                                     Iterator<? extends T> iter2)

distinct

public static <T> Iterator<T> distinct(Iterable<T> iter)

distinct

public static <T> Iterator<T> distinct(Iterator<T> iter)

removeNulls

public static <T> Iterator<T> removeNulls(Iterable<T> iter)

removeNulls

public static <T> Iterator<T> removeNulls(Iterator<T> iter)

convert

public static <T> Iterator<T> convert(Iterator<?> iterator)

count

public static <T> long count(Iterable<T> iterator)
Count the iterable - many iterable objects have a .size() operation which should be used in preference to this explicit counting operation


count

public static <T> long count(Iterator<T> iterator)
Count the iterator (this is destructive on the iterator)


consume

public static <T> void consume(Iterable<T> iterator)
Consume the iterable


consume

public static <T> void consume(Iterator<T> iterator)
Consume the iterator


asString

public static <T> String asString(Iterable<T> stream)

asString

public static <T> String asString(Iterator<T> stream)

asString

public static <T> String asString(Iter<T> stream)

asString

public static <T> String asString(Iterable<T> stream,
                                  String sep)

asString

public static <T> String asString(Iterator<T> stream,
                                  String sep)

asString

public static <T> String asString(Iter<T> stream,
                                  String sep)

asString

public static <T> String asString(Iterable<T> stream,
                                  AccString<T> formatter)

asString

public static <T> String asString(Iterator<T> stream,
                                  AccString<T> formatter)

asString

public static <T> String asString(Iter<T> stream,
                                  AccString<T> formatter)

close

public static <T> void close(Iterator<T> iter)

debug

public static <T> Iterator<T> debug(Iterator<T> stream)

sendToSink

public static <T> void sendToSink(Iterator<T> iter,
                                  Sink<T> sink)
Send the elements of the iterator to a sink - consumes the iterator


sendToSink

public static <T> void sendToSink(Iterable<T> stream,
                                  Sink<T> sink)
Send the elements of the iterator to a sink - consumes the iterator


iter

public static <T> Iter<T> iter(Iter<T> iter)

iter

public static <T> Iter<T> iter(Collection<T> collection)

iter

public static <T> Iter<T> iter(Iterator<T> iterator)

iter

public static <T> Iter<T> iter(Iterable<T> iterable)

materialize

public static <T> Iterator<T> materialize(Iterator<T> iter)
Materializae an iterator, that is, force it to run now - useful in debugging


concat

public static <T> Iter<T> concat(Iter<T> iter1,
                                 Iter<T> iter2)

concat

public static <T> Iterator<T> concat(Iterator<T> iter1,
                                     Iterator<T> iter2)

first

public static <T> T first(Iterator<T> iter,
                          Filter<T> filter)

first

public static <T> T first(Collection<T> collection,
                          Filter<T> filter)

firstIndex

public static <T> int firstIndex(Iterator<T> iter,
                                 Filter<T> filter)

firstIndex

public static <T> int firstIndex(Collection<T> collection,
                                 Filter<T> filter)

last

public static <T> T last(Iterator<T> iter,
                         Filter<T> filter)

last

public static <T> T last(Collection<T> collection,
                         Filter<T> filter)

lastIndex

public static <T> int lastIndex(Iterator<T> iter,
                                Filter<T> filter)

lastIndex

public static <T> int lastIndex(Collection<T> collection,
                                Filter<T> filter)

toSet

public Set<T> toSet()

toList

public List<T> toList()

sendToSink

public void sendToSink(Sink<T> sink)

first

public T first(Filter<T> filter)

firstIndex

public int firstIndex(Filter<T> filter)

last

public T last(Filter<T> filter)

lastIndex

public int lastIndex(Filter<T> filter)

filter

public Iter<T> filter(Filter<T> filter)

every

public boolean every(Filter<T> filter)

some

public boolean some(Filter<T> filter)

removeNulls

public Iter<T> removeNulls()

map

public <R> Iter<R> map(Transform<T,R> converter)

operate

public Iter<T> operate(Action<T> action)
Apply an action to everything in the stream, yielding a stream of the same items


reduce

public <R> R reduce(Accumulate<T,R> aggregator)

apply

public void apply(Action<T> action)

append

public Iter<T> append(Iterator<T> iter)

count

public long count()
Count the iterator (this is destructive on the iterator)


asString

public String asString()

asString

public String asString(String sep)

distinct

public Iter<T> distinct()

iterator

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

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>

singletonIter

public static <T> Iter<T> singletonIter(T item)

nullIter

public static <T> Iter<T> nullIter()


Licenced under the Apache License, Version 2.0