org.infinispan.stream.impl.IntermediateLongCacheStream Maven / Gradle / Ivy
package org.infinispan.stream.impl;
import java.util.LongSummaryStatistics;
import java.util.OptionalDouble;
import java.util.OptionalLong;
import java.util.PrimitiveIterator;
import java.util.Set;
import java.util.Spliterator;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.LongBinaryOperator;
import java.util.function.LongConsumer;
import java.util.function.LongFunction;
import java.util.function.LongPredicate;
import java.util.function.LongToDoubleFunction;
import java.util.function.LongToIntFunction;
import java.util.function.LongUnaryOperator;
import java.util.function.ObjLongConsumer;
import java.util.function.Supplier;
import java.util.stream.LongStream;
import org.infinispan.BaseCacheStream;
import org.infinispan.Cache;
import org.infinispan.CacheStream;
import org.infinispan.DoubleCacheStream;
import org.infinispan.IntCacheStream;
import org.infinispan.LongCacheStream;
import org.infinispan.stream.impl.local.LocalLongCacheStream;
import org.infinispan.util.function.SerializableBiConsumer;
import org.infinispan.util.function.SerializableLongBinaryOperator;
import org.infinispan.util.function.SerializableLongConsumer;
import org.infinispan.util.function.SerializableLongFunction;
import org.infinispan.util.function.SerializableLongPredicate;
import org.infinispan.util.function.SerializableLongToDoubleFunction;
import org.infinispan.util.function.SerializableLongToIntFunction;
import org.infinispan.util.function.SerializableLongUnaryOperator;
import org.infinispan.util.function.SerializableObjLongConsumer;
import org.infinispan.util.function.SerializableSupplier;
/**
* An intermediate long cache stream used when an intermediate operation that requires both a remote and local portion
*/
public class IntermediateLongCacheStream implements LongCacheStream {
private BaseCacheStream remoteStream;
private final IntermediateType type;
private LocalLongCacheStream localLongStream;
private IntermediateCacheStreamSupplier supplier;
public IntermediateLongCacheStream(DistributedLongCacheStream remoteStream) {
this.remoteStream = remoteStream;
this.type = IntermediateType.LONG;
this.supplier = new IntermediateCacheStreamSupplier(type, remoteStream);
this.localLongStream = new LocalLongCacheStream(supplier, remoteStream.parallel,
remoteStream.registry);
}
public IntermediateLongCacheStream(BaseCacheStream remoteStream, IntermediateType type,
LocalLongCacheStream localLongStream, IntermediateCacheStreamSupplier supplier) {
this.remoteStream = remoteStream;
this.type = type;
this.localLongStream = localLongStream;
this.supplier = supplier;
}
@Override
public LongCacheStream sequentialDistribution() {
remoteStream = remoteStream.sequentialDistribution();
return this;
}
@Override
public LongCacheStream parallelDistribution() {
remoteStream = remoteStream.parallelDistribution();
return this;
}
@Override
public LongCacheStream filterKeySegments(Set segments) {
remoteStream = remoteStream.filterKeySegments(segments);
return this;
}
@Override
public LongCacheStream filterKeys(Set> keys) {
remoteStream = remoteStream.filterKeys(keys);
return this;
}
@Override
public LongCacheStream distributedBatchSize(int batchSize) {
remoteStream = remoteStream.distributedBatchSize(batchSize);
return this;
}
@Override
public LongCacheStream segmentCompletionListener(SegmentCompletionListener listener) {
throw new UnsupportedOperationException("Segment completion listener is only supported when no intermediate " +
"operation is provided (sorted, distinct, limit, skip)");
}
@Override
public LongCacheStream disableRehashAware() {
remoteStream = remoteStream.disableRehashAware();
return this;
}
@Override
public LongCacheStream timeout(long timeout, TimeUnit unit) {
remoteStream = remoteStream.timeout(timeout, unit);
return this;
}
@Override
public boolean isParallel() {
return localLongStream.isParallel();
}
@Override
public LongCacheStream sorted() {
localLongStream = localLongStream.sorted();
return this;
}
@Override
public LongCacheStream limit(long maxSize) {
localLongStream = localLongStream.limit(maxSize);
return this;
}
@Override
public LongCacheStream skip(long n) {
localLongStream = localLongStream.skip(n);
return this;
}
@Override
public LongCacheStream peek(LongConsumer action) {
localLongStream = localLongStream.peek(action);
return this;
}
@Override
public LongCacheStream peek(SerializableLongConsumer action) {
return peek((LongConsumer) action);
}
@Override
public LongCacheStream distinct() {
localLongStream = localLongStream.distinct();
return this;
}
@Override
public LongCacheStream filter(LongPredicate predicate) {
localLongStream = localLongStream.filter(predicate);
return this;
}
@Override
public LongCacheStream filter(SerializableLongPredicate predicate) {
return filter((LongPredicate) predicate);
}
@Override
public LongCacheStream map(LongUnaryOperator mapper) {
localLongStream.map(mapper);
return this;
}
@Override
public LongCacheStream map(SerializableLongUnaryOperator mapper) {
return map((LongUnaryOperator) mapper);
}
@Override
public CacheStream mapToObj(LongFunction extends U> mapper) {
return new IntermediateCacheStream<>(remoteStream, type, localLongStream.mapToObj(mapper), supplier);
}
@Override
public CacheStream mapToObj(SerializableLongFunction extends U> mapper) {
return mapToObj((LongFunction extends U>) mapper);
}
@Override
public IntCacheStream mapToInt(LongToIntFunction mapper) {
return new IntermediateIntCacheStream(remoteStream, type, localLongStream.mapToInt(mapper), supplier);
}
@Override
public IntCacheStream mapToInt(SerializableLongToIntFunction mapper) {
return mapToInt((LongToIntFunction) mapper);
}
@Override
public DoubleCacheStream mapToDouble(LongToDoubleFunction mapper) {
return new IntermediateDoubleCacheStream(remoteStream, type, localLongStream.mapToDouble(mapper), supplier);
}
@Override
public DoubleCacheStream mapToDouble(SerializableLongToDoubleFunction mapper) {
return mapToDouble((LongToDoubleFunction) mapper);
}
@Override
public LongCacheStream flatMap(LongFunction extends LongStream> mapper) {
localLongStream.flatMap(mapper);
return this;
}
@Override
public LongCacheStream flatMap(SerializableLongFunction extends LongStream> mapper) {
return flatMap((LongFunction extends LongStream>) mapper);
}
@Override
public LongCacheStream parallel() {
remoteStream = (BaseCacheStream) remoteStream.parallel();
localLongStream = (LocalLongCacheStream) localLongStream.parallel();
return this;
}
@Override
public PrimitiveIterator.OfLong iterator() {
return localLongStream.iterator();
}
@Override
public Spliterator.OfLong spliterator() {
return localLongStream.spliterator();
}
@Override
public LongCacheStream sequential() {
remoteStream = (BaseCacheStream) remoteStream.sequential();
localLongStream = (LocalLongCacheStream) localLongStream.sequential();
return this;
}
@Override
public LongCacheStream unordered() {
localLongStream = (LocalLongCacheStream) localLongStream.unordered();
return this;
}
@Override
public void forEach(LongConsumer action) {
localLongStream.forEach(action);
}
@Override
public void forEach(SerializableLongConsumer action) {
forEach((LongConsumer) action);
}
@Override
public void forEach(ObjLongConsumer> action) {
localLongStream.forEach(action);
}
@Override
public void forEach(SerializableObjLongConsumer> action) {
forEach((ObjLongConsumer>) action);
}
@Override
public void forEachOrdered(LongConsumer action) {
localLongStream.forEachOrdered(action);
}
@Override
public long[] toArray() {
return localLongStream.toArray();
}
@Override
public long reduce(long identity, LongBinaryOperator op) {
return localLongStream.reduce(identity, op);
}
@Override
public long reduce(long identity, SerializableLongBinaryOperator op) {
return reduce(identity, (LongBinaryOperator) op);
}
@Override
public OptionalLong reduce(LongBinaryOperator op) {
return localLongStream.reduce(op);
}
@Override
public OptionalLong reduce(SerializableLongBinaryOperator op) {
return reduce((LongBinaryOperator) op);
}
@Override
public R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) {
return localLongStream.collect(supplier, accumulator, combiner);
}
@Override
public R collect(SerializableSupplier supplier, SerializableObjLongConsumer accumulator,
SerializableBiConsumer combiner) {
return collect((Supplier) supplier, accumulator, combiner);
}
@Override
public long sum() {
return localLongStream.sum();
}
@Override
public OptionalLong min() {
return localLongStream.min();
}
@Override
public OptionalLong max() {
return localLongStream.max();
}
@Override
public long count() {
return localLongStream.count();
}
@Override
public OptionalDouble average() {
return localLongStream.average();
}
@Override
public LongSummaryStatistics summaryStatistics() {
return localLongStream.summaryStatistics();
}
@Override
public boolean anyMatch(LongPredicate predicate) {
return localLongStream.anyMatch(predicate);
}
@Override
public boolean anyMatch(SerializableLongPredicate predicate) {
return anyMatch((LongPredicate) predicate);
}
@Override
public boolean allMatch(LongPredicate predicate) {
return localLongStream.allMatch(predicate);
}
@Override
public boolean allMatch(SerializableLongPredicate predicate) {
return allMatch((LongPredicate) predicate);
}
@Override
public boolean noneMatch(LongPredicate predicate) {
return localLongStream.noneMatch(predicate);
}
@Override
public boolean noneMatch(SerializableLongPredicate predicate) {
return noneMatch((LongPredicate) predicate);
}
@Override
public OptionalLong findFirst() {
return localLongStream.findFirst();
}
@Override
public OptionalLong findAny() {
return localLongStream.findAny();
}
@Override
public CacheStream boxed() {
return mapToObj(Long::valueOf);
}
@Override
public DoubleCacheStream asDoubleStream() {
return mapToDouble(l -> (double) l);
}
@Override
public LongCacheStream onClose(Runnable closeHandler) {
remoteStream = (BaseCacheStream) remoteStream.onClose(closeHandler);
return this;
}
@Override
public void close() {
localLongStream.close();
remoteStream.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy