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

org.infinispan.stream.impl.AbstractDelegatingCacheStream Maven / Gradle / Ivy

package org.infinispan.stream.impl;

import org.infinispan.CacheStream;

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.*;
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;

/**
 * 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 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 R reduce(R identity, BinaryOperator accumulator) {
      return castStream(underlyingStream).reduce(identity, accumulator);
   }

   @Override
   public Optional reduce(BinaryOperator 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  R1 collect(Supplier supplier, BiConsumer accumulator, BiConsumer 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 Stream sequential() {
      underlyingStream = (CacheStream) underlyingStream.sequential();
      return this;
   }

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

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

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

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

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

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

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

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

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

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

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

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

   @Override
   public Stream distinct() {
      underlyingStream = (CacheStream) 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 max(Comparator 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 allMatch(Predicate predicate) {
      return castStream(underlyingStream).allMatch(predicate);
   }

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

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

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

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

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

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

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

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

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