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

org.llorllale.youtrack.api.StreamEnvelope Maven / Gradle / Ivy

There is a newer version: 1.1.0-rc59
Show newest version
/*
 * Copyright 2017 George Aristy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.llorllale.youtrack.api;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import java.util.Spliterator;
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;

/**
 * Stream envelope.
 * @author George Aristy ([email protected])
 * @param  This stream's type
 * @since 1.1.0
 */
@SuppressWarnings("checkstyle:MethodCount")
abstract class StreamEnvelope implements Stream {
  private final Supplier> stream;

  /**
   * Primary ctor.
   * 
   * @param stream the actual stream implementation 
   * @since 1.0.0
   */
  protected StreamEnvelope(Stream stream) {
    this.stream = () -> stream;
  }

  /**
   * Ctor.
   * @param stream the actual stream implementation
   * @since 1.1.0
   */
  protected StreamEnvelope(Supplier> stream) {
    this.stream = stream;
  }

  @Override
  public final Stream filter(Predicate predicate) {
    return this.stream.get().filter(predicate);
  }

  @Override
  public final  Stream map(Function mapper) {
    return this.stream.get().map(mapper);
  }

  @Override
  public final IntStream mapToInt(ToIntFunction mapper) {
    return this.stream.get().mapToInt(mapper);
  }

  @Override
  public final LongStream mapToLong(ToLongFunction mapper) {
    return this.stream.get().mapToLong(mapper);
  }

  @Override
  public final DoubleStream mapToDouble(ToDoubleFunction mapper) {
    return this.stream.get().mapToDouble(mapper);
  }

  @Override
  public final  Stream flatMap(Function> mapper) {
    return this.stream.get().flatMap(mapper);
  }

  @Override
  public final IntStream flatMapToInt(Function mapper) {
    return this.stream.get().flatMapToInt(mapper);
  }

  @Override
  public final LongStream flatMapToLong(Function mapper) {
    return this.stream.get().flatMapToLong(mapper);
  }

  @Override
  public final DoubleStream flatMapToDouble(Function mapper) {
    return this.stream.get().flatMapToDouble(mapper);
  }

  @Override
  public final Stream distinct() {
    return this.stream.get().distinct();
  }

  @Override
  public final Stream sorted() {
    return this.stream.get().sorted();
  }

  @Override
  public final Stream sorted(Comparator comparator) {
    return this.stream.get().sorted(comparator);
  }

  @Override
  public final Stream peek(Consumer action) {
    return this.stream.get().peek(action);
  }

  @Override
  public final Stream limit(long maxSize) {
    return this.stream.get().limit(maxSize);
  }

  @Override
  public final Stream skip(long n) {
    return this.stream.get().skip(n);
  }

  @Override
  public final void forEach(Consumer action) {
    this.stream.get().forEach(action);
  }

  @Override
  public final void forEachOrdered(Consumer action) {
    this.stream.get().forEachOrdered(action);
  }

  @Override
  public final Object[] toArray() {
    return this.stream.get().toArray();
  }

  @Override
  public final  A[] toArray(IntFunction generator) {
    return this.stream.get().toArray(generator);
  }

  @Override
  public final T reduce(T identity, BinaryOperator accumulator) {
    return this.stream.get().reduce(identity, accumulator);
  }

  @Override
  public final Optional reduce(BinaryOperator accumulator) {
    return this.stream.get().reduce(accumulator);
  }

  @Override
  public final  U reduce(
      U identity, BiFunction accumulator, 
      BinaryOperator combiner
  ) {
    return this.stream.get().reduce(identity, accumulator, combiner);
  }

  @Override
  public final  R collect(
      Supplier supplier, 
      BiConsumer accumulator, 
      BiConsumer combiner
  ) {
    return this.stream.get().collect(supplier, accumulator, combiner);
  }

  @Override
  public final  R collect(Collector collector) {
    return this.stream.get().collect(collector);
  }

  @Override
  public final Optional min(Comparator comparator) {
    return this.stream.get().min(comparator);
  }

  @Override
  public final Optional max(Comparator comparator) {
    return this.stream.get().max(comparator);
  }

  @Override
  public final long count() {
    return this.stream.get().count();
  }

  @Override
  public final boolean anyMatch(Predicate predicate) {
    return this.stream.get().anyMatch(predicate);
  }

  @Override
  public final boolean allMatch(Predicate predicate) {
    return this.stream.get().allMatch(predicate);
  }

  @Override
  public final boolean noneMatch(Predicate predicate) {
    return this.stream.get().noneMatch(predicate);
  }

  @Override
  public final Optional findFirst() {
    return this.stream.get().findFirst();
  }

  @Override
  public final Optional findAny() {
    return this.stream.get().findAny();
  }

  @Override
  public final Iterator iterator() {
    return this.stream.get().iterator();
  }

  @Override
  public final Spliterator spliterator() {
    return this.stream.get().spliterator();
  }

  @Override
  public final boolean isParallel() {
    return this.stream.get().isParallel();
  }

  @Override
  public final Stream sequential() {
    return this.stream.get().sequential();
  }

  @Override
  public final Stream parallel() {
    return this.stream.get().parallel();
  }

  @Override
  public final Stream unordered() {
    return this.stream.get().unordered();
  }

  @Override
  public final Stream onClose(Runnable closeHandler) {
    return this.stream.get().onClose(closeHandler);
  }

  @Override
  public final void close() {
    this.stream.get().close();
  }
}