@Override public void forEachRemaining(Consumer<? super R> action) { source.forEachRemaining(t->{ if(data==false) data = true; list.mutate(var -> var.insertAt(Math.max(0, var.size()), t)); if(list.get().size()==windowSize){ action.accept(finalizer.apply(list.get())); sent = true; for (int i = 0; i < increment && list.get() .size() > 0; i++) list.mutate(var -> var.removeAt(0)); }else{ sent =false; } }); if(!sent && data){ action.accept(finalizer.apply(list.get())); } } boolean canAdvance = true;
@Override public void request(final long n) { if (n < 1) { sub.onError(new IllegalArgumentException( "3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); } if (!running.compareAndSet(true, false)) { return; } future.mutate(f -> f.peek(sub::onNext) .recover(t -> { sub.onError(t); return null; }) .peek(i -> sub.onComplete())); }
@Test public void testMutate(){ Mutable<Integer> num = Mutable.of(20); Stream.of(1,2,3,4).map(i->i*10).peek(i-> num.mutate(n->n+i)).forEach(System.out::println); assertThat(num.get(),is(120)); } @Test
@Override public void request(final long n) { if (n < 1) { sub.onError(new IllegalArgumentException( "3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); } if (!running.compareAndSet(true, false)) { return; } future.mutate(f -> f.peek(e->{ e.forEach(v->{ sub.onNext(v); }); }) .recover(t -> { sub.onError(t); return null; }) .peek(i -> sub.onComplete())); }
@Override public boolean tryAdvance(Consumer<? super R> action) { if(!canAdvance) return false; data = false; for (int i = 0; i < increment && list.get() .size() > 0; i++) list.mutate(var -> var.removeAt(0)); for (; list.get() .size() < windowSize && canAdvance;) { Mutable<T> box = Mutable.of(null); canAdvance = source.tryAdvance(t -> { box.accept(t); }); if (box.get()!=null) { data =true; list.mutate(var -> var.insertAt(Math.max(0, var.size()), box.get())); } } if(data) action.accept(finalizer.apply(list.get())); return canAdvance; }
@Override public void forEachRemaining(Consumer<? super R> action) { source.forEachRemaining(t->{ if(data==false) data = true; list.mutate(var -> var.insertAt(Math.max(0, var.size()), t)); if(list.get().size()==windowSize){ action.accept(finalizer.apply(list.get())); sent = true; for (int i = 0; i < increment && list.get() .size() > 0; i++) list.mutate(var -> var.removeAt(0)); }else{ sent =false; } }); if(!sent && data){ action.accept(finalizer.apply(list.get())); } } boolean canAdvance = true;
@Override public void request(final long n) { if (n < 1) { sub.onError(new IllegalArgumentException( "3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); } if (!running.compareAndSet(true, false)) { return; } future.mutate(f -> f.peek(sub::onNext) .recover(t -> { sub.onError(t); return null; }) .peek(i -> sub.onComplete())); }
@Override public boolean tryAdvance(Consumer<? super R> action) { if(!canAdvance) return false; data = false; for (int i = 0; i < increment && list.get() .size() > 0; i++) list.mutate(var -> var.removeAt(0)); for (; list.get() .size() < windowSize && canAdvance;) { Mutable<T> box = Mutable.of(null); canAdvance = source.tryAdvance(t -> { box.accept(t); }); if (box.get()!=null) { data =true; list.mutate(var -> var.insertAt(Math.max(0, var.size()), box.get())); } } if(data) action.accept(finalizer.apply(list.get())); return canAdvance; }
@Override public void request(final long n) { if (n < 1) { sub.onError(new IllegalArgumentException( "3.9 While the Subscription is not cancelled, Subscription.request(long n) MUST throw a java.lang.IllegalArgumentException if the argument is <= 0.")); } if (!running.compareAndSet(true, false)) { return; } future.mutate(f -> f.peek(e->{ e.forEach(v->{ sub.onNext(v); }); }) .recover(t -> { sub.onError(t); return null; }) .peek(i -> sub.onComplete())); }