package com.aol.cyclops.internal.stream.spliterators;



import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;

public class OnEmptySpliterator<T> extends Spliterators.AbstractSpliterator<T> {
    private final Spliterator<T> source;
    private final T value;
    private boolean found=false;


    public OnEmptySpliterator(Spliterator<T> source, T value) {
        super(source.estimateSize(), source.characteristics() & Spliterator.ORDERED);
        this.source = source;
        this.value = value;
    }


    @Override
    public boolean tryAdvance(Consumer<? super T> action) {
        if(found)
            return source.tryAdvance(action);
        else{
            if(!source.tryAdvance(e->{
                found =true;
                action.accept(e);
            })){
                action.accept(value);
            }
        }

        return found;
    }
}

@@ -330,16 +330,48 @@
 =false;%0A
+    private boolean sent=false;%0A
 %0A%0A    pu
@@ -650,24 +650,67 @@
 %3E action) %7B%0A
+        if(sent)%0A            return false;%0A
         if(f
@@ -894,16 +894,44 @@
    %7D))%7B%0A
+                sent =true;%0A
         

fix tests