@Test public void tryAdvance() throws Exception { StreamFlatMappingSpliterator<String, String> split = new StreamFlatMappingSpliterator<>(new DummySpliterator<String>(-1l, 1), s -> Stream.of(s)); boolean called[] = {false}; split.tryAdvance(e->called[0]=true); assertTrue(called[0]); called[0] = false; split.tryAdvance(e->called[0]=true); assertTrue(called[0]); called[0] = false; split.tryAdvance(e->called[0]=true); assertTrue(called[0]); called[0] = false; split.tryAdvance(e->called[0]=true); assertTrue(called[0]); }
@Override public boolean tryAdvance(Consumer<? super R> action) { for(;;) { if (active != null) { if(active.tryAdvance(action)){ return true; }else{ active = null; } } boolean advance = source.tryAdvance(t -> { active = (Spliterator<R>) mapper.apply(t).spliterator(); }); if(!advance && active==null) return false; } }
StreamFlatMappingSpliterator extends Spliterators.AbstractSpliterator<R> implements CopyableSpliterator<R> { @Override public boolean tryAdvance(Consumer<? super R> action) { for(;;) { if (active != null) { if(active.tryAdvance(action)){ return true; }else{ active = null; } } boolean advance = source.tryAdvance(t -> { active = (Spliterator<R>) mapper.apply(t).spliterator(); }); if(!advance && active==null) return false; } } }
StreamFlatMappingSpliterator extends Spliterators.AbstractSpliterator<R> implements CopyableSpliterator<R> { @Override public boolean tryAdvance(Consumer<? super R> action) { for(;;) { if (active != null) { if(active.tryAdvance(action)){ return true; }else{ active = null; } } boolean advance = source.tryAdvance(t -> { active = (Spliterator<R>) mapper.apply(t).spliterator(); }); if(!advance && active==null) return false; } } StreamFlatMappingSpliterator(final Spliterator<T> source, Function<? super T, ? extends Stream<? extends R>> mapper); }
StreamFlatMappingSpliterator extends Spliterators.AbstractSpliterator<R> implements CopyableSpliterator<R> { @Override public boolean tryAdvance(Consumer<? super R> action) { for(;;) { if (active != null) { if(active.tryAdvance(action)){ return true; }else{ active = null; } } boolean advance = source.tryAdvance(t -> { active = (Spliterator<R>) mapper.apply(t).spliterator(); }); if(!advance && active==null) return false; } } StreamFlatMappingSpliterator(final Spliterator<T> source, Function<? super T, ? extends Stream<? extends R>> mapper); static StreamFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Stream<? extends R>> mapper); @Override void forEachRemaining(Consumer<? super R> action); @Override boolean tryAdvance(Consumer<? super R> action); @Override Spliterator<R> copy(); }
StreamFlatMappingSpliterator extends Spliterators.AbstractSpliterator<R> implements CopyableSpliterator<R> { @Override public boolean tryAdvance(Consumer<? super R> action) { for(;;) { if (active != null) { if(active.tryAdvance(action)){ return true; }else{ active = null; } } boolean advance = source.tryAdvance(t -> { active = (Spliterator<R>) mapper.apply(t).spliterator(); }); if(!advance && active==null) return false; } } StreamFlatMappingSpliterator(final Spliterator<T> source, Function<? super T, ? extends Stream<? extends R>> mapper); static StreamFlatMappingSpliterator<T2,R> compose(FunctionSpliterator<T2,T> fnS,Function<? super T, ? extends Stream<? extends R>> mapper); @Override void forEachRemaining(Consumer<? super R> action); @Override boolean tryAdvance(Consumer<? super R> action); @Override Spliterator<R> copy();  }