Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.davidmoten.rx.internal.operators;
import java.util.*;
import java.util.concurrent.atomic.*;
import rx.*;
import rx.Observable;
import rx.Observable.*;
import rx.exceptions.*;
import rx.functions.Func1;
import rx.internal.operators.*;
import rx.internal.util.atomic.SpscAtomicArrayQueue;
import rx.internal.util.unsafe.*;
/**
* Buffers values into a continuous, non-overlapping Lists where the boundary is determined
* by a predicate returning true.
*
* @param the source and List element type
*/
public final class OperatorBufferPredicateBoundary implements Transformer> {
final Func1 super T, Boolean> predicate;
final int prefetch;
final int capacityHint;
final boolean after;
public OperatorBufferPredicateBoundary(Func1 super T, Boolean> predicate, int prefetch, int capacityHint, boolean after) {
if (predicate == null) {
throw new NullPointerException("predicate");
}
if (prefetch <= 0) {
throw new IllegalArgumentException("prefetch > 0 required but it was " + prefetch);
}
if (capacityHint <= 0) {
throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint);
}
this.predicate = predicate;
this.prefetch = prefetch;
this.capacityHint = capacityHint;
this.after = after;
}
@Override
public Observable> call(Observable source) {
return source.lift(new Operator, T>() {
@Override
public Subscriber super T> call(Subscriber super List> child) {
final BoundedSubscriber parent = after
? new BoundedAfterSubscriber(child, capacityHint, predicate, prefetch)
: new BoundedBeforeSubscriber(child, capacityHint, predicate, prefetch);
child.add(parent);
child.setProducer(new Producer() {
@Override
public void request(long n) {
parent.requestMore(n);
}
});
return parent;
}
});
}
static abstract class BoundedSubscriber extends Subscriber {
final Subscriber super List> actual;
final int capacityHint;
final Func1 super T, Boolean> predicate;
final Queue