com.aol.cyclops.streams.operators.SkipWhileOperator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-streams Show documentation
Show all versions of cyclops-streams Show documentation
Sequential Streams and Stream Utilities for Java 8
package com.aol.cyclops.streams.operators;
import java.util.Iterator;
import java.util.function.Predicate;
import java.util.stream.Stream;
import lombok.Value;
import com.aol.cyclops.streams.StreamUtils;
@Value
public class SkipWhileOperator {
Stream stream;
public Stream skipWhile(Predicate super U> predicate){
Iterator it = stream.iterator();
return StreamUtils.stream(new Iterator(){
U next;
boolean nextSet = false;
boolean init =false;
@Override
public boolean hasNext() {
if(init)
return it.hasNext();
try{
while(it.hasNext()){
next = it.next();
nextSet = true;
if(!predicate.test(next))
return true;
}
return false;
}finally{
init =true;
}
}
@Override
public U next() {
if(!init){
hasNext();
}
if(nextSet){
nextSet = false;
return next;
}
return it.next();
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy