All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.util.AbstractDelegatingCacheStream Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.util;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import java.util.Set;
import java.util.Spliterator;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.stream.Collector;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.infinispan.Cache;
import org.infinispan.CacheStream;
import org.infinispan.DoubleCacheStream;
import org.infinispan.IntCacheStream;
import org.infinispan.LongCacheStream;
import org.infinispan.util.function.SerializableBiConsumer;
import org.infinispan.util.function.SerializableBiFunction;
import org.infinispan.util.function.SerializableBinaryOperator;
import org.infinispan.util.function.SerializableComparator;
import org.infinispan.util.function.SerializableConsumer;
import org.infinispan.util.function.SerializableFunction;
import org.infinispan.util.function.SerializableIntFunction;
import org.infinispan.util.function.SerializablePredicate;
import org.infinispan.util.function.SerializableSupplier;
import org.infinispan.util.function.SerializableToDoubleFunction;
import org.infinispan.util.function.SerializableToIntFunction;
import org.infinispan.util.function.SerializableToLongFunction;

/**
 * Delegate that forwards all the of the method calls to the underlying cache stream.  It is assumed that a CacheStream
 * is returned for all intermediate operations.
 */
public class AbstractDelegatingCacheStream implements CacheStream {
   protected CacheStream underlyingStream;

   public AbstractDelegatingCacheStream(CacheStream stream) {
      this.underlyingStream = stream;
   }

   private CacheStream castStream(CacheStream stream) {
      return stream;
   }

   @Override
   public CacheStream sequentialDistribution() {
      underlyingStream = underlyingStream.sequentialDistribution();
      return this;
   }

   @Override
   public CacheStream parallelDistribution() {
      underlyingStream = underlyingStream.parallelDistribution();
      return this;
   }

   @Override
   public CacheStream filterKeySegments(Set segments) {
      underlyingStream = underlyingStream.filterKeySegments(segments);
      return this;
   }

   @Override
   public CacheStream filterKeys(Set keys) {
      underlyingStream = underlyingStream.filterKeys(keys);
      return this;
   }

   @Override
   public CacheStream distributedBatchSize(int batchSize) {
      underlyingStream = underlyingStream.distributedBatchSize(batchSize);
      return this;
   }

   @Override
   public CacheStream segmentCompletionListener(SegmentCompletionListener listener) {
      underlyingStream = underlyingStream.segmentCompletionListener(listener);
      return this;
   }

   @Override
   public CacheStream disableRehashAware() {
      underlyingStream = underlyingStream.disableRehashAware();
      return this;
   }

   @Override
   public CacheStream timeout(long timeout, TimeUnit unit) {
      underlyingStream = underlyingStream.timeout(timeout, unit);
      return this;
   }

   @Override
   public void forEach(Consumer action) {
      castStream(underlyingStream).forEach(action);
   }

   @Override
   public void forEach(SerializableConsumer action) {
      castStream(underlyingStream).forEach(action);
   }

   @Override
   public  void forEach(BiConsumer, ? super R> action) {
      castStream(underlyingStream).forEach(action);
   }

   @Override
   public  void forEach(SerializableBiConsumer, ? super R> action) {
      castStream(underlyingStream).forEach(action);
   }

   @Override
   public void forEachOrdered(Consumer action) {
      castStream(underlyingStream).forEachOrdered(action);
   }

   @Override
   public Object[] toArray() {
      return underlyingStream.toArray();
   }

   @Override
   public  A[] toArray(IntFunction generator) {
      return underlyingStream.toArray(generator);
   }

   @Override
   public  A[] toArray(SerializableIntFunction generator) {
      return underlyingStream.toArray(generator);
   }

   @Override
   public R reduce(R identity, BinaryOperator accumulator) {
      return castStream(underlyingStream).reduce(identity, accumulator);
   }

   @Override
   public R reduce(R identity, SerializableBinaryOperator accumulator) {
      return castStream(underlyingStream).reduce(identity, accumulator);
   }

   @Override
   public Optional reduce(BinaryOperator accumulator) {
      return castStream(underlyingStream).reduce(accumulator);
   }

   @Override
   public Optional reduce(SerializableBinaryOperator accumulator) {
      return castStream(underlyingStream).reduce(accumulator);
   }

   @Override
   public  U reduce(U identity, BiFunction accumulator, BinaryOperator combiner) {
      return castStream(underlyingStream).reduce(identity, accumulator, combiner);
   }

   @Override
   public  U reduce(U identity, SerializableBiFunction accumulator, SerializableBinaryOperator combiner) {
      return castStream(underlyingStream).reduce(identity, accumulator, combiner);
   }

   @Override
   public  R1 collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) {
      return castStream(underlyingStream).collect(supplier, accumulator, combiner);
   }

   @Override
   public  R1 collect(SerializableSupplier supplier, SerializableBiConsumer accumulator, SerializableBiConsumer combiner) {
      return castStream(underlyingStream).collect(supplier, accumulator, combiner);
   }

   @Override
   public Iterator iterator() {
      return castStream(underlyingStream).iterator();
   }

   @Override
   public Spliterator spliterator() {
      return castStream(underlyingStream).spliterator();
   }

   @Override
   public boolean isParallel() {
      return underlyingStream.isParallel();
   }

   @Override
   public CacheStream sequential() {
      underlyingStream = underlyingStream.sequential();
      return this;
   }

   @Override
   public CacheStream parallel() {
      underlyingStream = underlyingStream.parallel();
      return this;
   }

   @Override
   public CacheStream unordered() {
      underlyingStream = underlyingStream.unordered();
      return this;
   }

   @Override
   public CacheStream onClose(Runnable closeHandler) {
      underlyingStream = underlyingStream.onClose(closeHandler);
      return this;
   }

   @Override
   public void close() {
      underlyingStream.close();
   }

   @Override
   public CacheStream sorted() {
      underlyingStream = underlyingStream.sorted();
      return this;
   }

   @Override
   public CacheStream sorted(Comparator comparator) {
      underlyingStream = castStream(underlyingStream).sorted(comparator);
      return this;
   }

   @Override
   public CacheStream sorted(SerializableComparator comparator) {
      underlyingStream = castStream(underlyingStream).sorted(comparator);
      return this;
   }

   @Override
   public CacheStream peek(Consumer action) {
      underlyingStream = castStream(underlyingStream).peek(action);
      return this;
   }

   @Override
   public CacheStream peek(SerializableConsumer action) {
      underlyingStream = castStream(underlyingStream).peek(action);
      return this;
   }

   @Override
   public CacheStream limit(long maxSize) {
      underlyingStream = underlyingStream.limit(maxSize);
      return this;
   }

   @Override
   public CacheStream skip(long n) {
      underlyingStream = underlyingStream.limit(n);
      return this;
   }

   @Override
   public CacheStream filter(Predicate predicate) {
      underlyingStream = castStream(underlyingStream).filter(predicate);
      return this;
   }

   @Override
   public CacheStream filter(SerializablePredicate predicate) {
      underlyingStream = castStream(underlyingStream).filter(predicate);
      return this;
   }

   @Override
   public  CacheStream map(Function mapper) {
      underlyingStream = castStream(underlyingStream).map(mapper);
      return (CacheStream) this;
   }

   @Override
   public  CacheStream map(SerializableFunction mapper) {
      underlyingStream = castStream(underlyingStream).map(mapper);
      return (CacheStream) this;
   }

   @Override
   public  CacheStream flatMap(Function> mapper) {
      underlyingStream = castStream(underlyingStream).flatMap(mapper);
      return (CacheStream) this;
   }

   @Override
   public  CacheStream flatMap(SerializableFunction> mapper) {
      underlyingStream = castStream(underlyingStream).flatMap(mapper);
      return (CacheStream) this;
   }

   @Override
   public CacheStream distinct() {
      underlyingStream = underlyingStream.distinct();
      return this;
   }

   @Override
   public  R1 collect(Collector collector) {
      return castStream(underlyingStream).collect(collector);
   }

   @Override
   public Optional min(Comparator comparator) {
      return castStream(underlyingStream).min(comparator);
   }

   @Override
   public Optional min(SerializableComparator comparator) {
      return castStream(underlyingStream).min(comparator);
   }

   @Override
   public Optional max(Comparator comparator) {
      return castStream(underlyingStream).max(comparator);
   }

   @Override
   public Optional max(SerializableComparator comparator) {
      return castStream(underlyingStream).max(comparator);
   }

   @Override
   public long count() {
      return underlyingStream.count();
   }

   @Override
   public boolean anyMatch(Predicate predicate) {
      return castStream(underlyingStream).anyMatch(predicate);
   }

   @Override
   public boolean anyMatch(SerializablePredicate predicate) {
      return castStream(underlyingStream).anyMatch(predicate);
   }

   @Override
   public boolean allMatch(Predicate predicate) {
      return castStream(underlyingStream).allMatch(predicate);
   }

   @Override
   public boolean allMatch(SerializablePredicate predicate) {
      return castStream(underlyingStream).allMatch(predicate);
   }

   @Override
   public boolean noneMatch(Predicate predicate) {
      return castStream(underlyingStream).noneMatch(predicate);
   }

   @Override
   public boolean noneMatch(SerializablePredicate predicate) {
      return castStream(underlyingStream).noneMatch(predicate);
   }

   @Override
   public Optional findFirst() {
      return castStream(underlyingStream).findFirst();
   }

   @Override
   public Optional findAny() {
      return castStream(underlyingStream).findAny();
   }

   @Override
   public IntCacheStream mapToInt(ToIntFunction mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public IntCacheStream mapToInt(SerializableToIntFunction mapper) {
      return mapToInt((ToIntFunction) mapper);
   }

   @Override
   public LongCacheStream mapToLong(ToLongFunction mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public LongCacheStream mapToLong(SerializableToLongFunction mapper) {
      return mapToLong((ToLongFunction) mapper);
   }

   @Override
   public DoubleCacheStream mapToDouble(ToDoubleFunction mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public DoubleCacheStream mapToDouble(SerializableToDoubleFunction mapper) {
      return mapToDouble((ToDoubleFunction) mapper);
   }

   @Override
   public IntCacheStream flatMapToInt(Function mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public IntCacheStream flatMapToInt(SerializableFunction mapper) {
      return flatMapToInt((Function) mapper);
   }

   @Override
   public LongCacheStream flatMapToLong(Function mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public LongCacheStream flatMapToLong(SerializableFunction mapper) {
      return flatMapToLong((Function) mapper);
   }

   @Override
   public DoubleCacheStream flatMapToDouble(Function mapper) {
      throw new UnsupportedOperationException("Primitive delegate is not yet supported!");
   }

   @Override
   public DoubleCacheStream flatMapToDouble(SerializableFunction mapper) {
      return flatMapToDouble((Function) mapper);
   }
}