merged from trunk @62336

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-access/streams/2.0@67188 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
fabio.simeoni 2013-01-08 08:37:41 +00:00
parent 83641cc478
commit b42309a2f9
4 changed files with 15 additions and 7 deletions

View File

@ -9,7 +9,7 @@
<groupId>org.gcube.data.access</groupId>
<artifactId>streams</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
<name>Stream Library</name>

View File

@ -25,9 +25,18 @@ public abstract class LookAheadStream<E> implements Stream<E> {
private FaultHandler handler = new RethrowHandler();
private static class NullOr<T> {
T element;
NullOr(T element) {
this.element=element;
}
T value() {
return element;
}
}
// iteration state
protected Boolean hasNext;
protected E element;
protected NullOr<E> element;
private RuntimeException failure;
/**
@ -63,7 +72,7 @@ public abstract class LookAheadStream<E> implements Stream<E> {
return false;
try {
this.element = delegateNext();
this.element = new NullOr<E>(delegateNext());
return true;
}
catch (RuntimeException failure) {
@ -113,7 +122,7 @@ public abstract class LookAheadStream<E> implements Stream<E> {
else
throw new NoSuchElementException();
return element;
return element.value();
}

View File

@ -116,8 +116,7 @@ public class Utils {
//consume
while (stream.hasNext())
try {
if (stream.next()==null)
throw new AssertionError("hasNext() returns true but next() returns null");
stream.next();
}
catch(RuntimeException e) {
//ignore exceptions for this test

View File

@ -25,7 +25,7 @@ public class RsStreamTest {
@Test
public void resultsetsMakeValidStreams() throws Exception {
final List<String> elements = asList("1","2","3");
final List<String> elements = asList("1",null,"3");
StreamProvider provider = new StreamProvider() {