Browse Source
Fix CompositeIterable
Fix CompositeIterable
Make it compatible with Spliterator/Stream in java8 by returning a new iterator each time iterator() is calledmaster
2 changed files with 42 additions and 32 deletions
-
34src/main/java/com/corundumstudio/socketio/misc/CompositeIterable.java
-
40src/main/java/com/corundumstudio/socketio/misc/CompositeIterator.java
@ -0,0 +1,40 @@ |
|||
package com.corundumstudio.socketio.misc; |
|||
|
|||
import java.util.Iterator; |
|||
|
|||
public class CompositeIterator<T> implements Iterator<T> { |
|||
|
|||
private Iterator<Iterator<T>> listIterator; |
|||
private Iterator<T> currentIterator; |
|||
|
|||
public CompositeIterator(Iterator<Iterator<T>> listIterator) { |
|||
this.currentIterator = null; |
|||
this.listIterator = listIterator; |
|||
} |
|||
|
|||
@Override |
|||
public boolean hasNext() { |
|||
if (currentIterator == null || !currentIterator.hasNext()) { |
|||
while (listIterator.hasNext()) { |
|||
Iterator<T> iterator = listIterator.next(); |
|||
if (iterator.hasNext()) { |
|||
currentIterator = iterator; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
return currentIterator.hasNext(); |
|||
} |
|||
|
|||
@Override |
|||
public T next() { |
|||
hasNext(); |
|||
return currentIterator.next(); |
|||
} |
|||
|
|||
@Override |
|||
public void remove() { |
|||
currentIterator.remove(); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue