A tool to bridge OsidLists to Java iteration and streaming.
Converts OsidList to Java Iterators to
bridge OsidLists with the Java streaming API. This tool implements
Iterator, Iterable,
and Spliterator over the element type.
Because OsidLists are I/O streams and not
internal Collections,
checked OperationFailedException exceptions from the
OsidList provider are snaked through the stream. You should use
OsidStreams.go()
at the boundary to unsnake and retrieve the original OsidException
to continue on your merry OSID compliant way.
List<Grade> getGoodGrades(GradeList grades)
throws OperationFailedException {
List<Grade> good = OsidStreams.go(() ->
GradeIterator.stream(grades)
.filter(grade -> grade.getDisplayName()
.getText().startsWith("A"))
.collect(Collectors.toList())
);
return (good);
}
The above example illustrates the use of the tool and not so much the lazy plopping of results into a Java List. There is always a design issue when you have to get in the way and buffer versus keeping the stream flowing up the stack. But sometimes it can't be helped.
net.okapia.osid.torrefacto.streams
An implementation exists for every org.osid.OsidList.
| Parameter | Type | Description |
|---|---|---|
list |
OsidObjectList |
the OsidList to iterate |
| Parameter | Type | Description |
|---|---|---|
list |
OsidObjectList |
the OsidList to stream |