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

io.zeebe.test.util.stream.StreamWrapper Maven / Gradle / Ivy

There is a newer version: 0.16.4
Show newest version
/*
 * Copyright © 2017 camunda services GmbH ([email protected])
 *
 * 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 io.zeebe.test.util.stream;

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;

import one.util.streamex.StreamEx;

public class StreamWrapper implements Stream
{
    private final Stream wrappedStream;

    public StreamWrapper(Stream wrappedStream)
    {
        this.wrappedStream = wrappedStream;
    }

    /**
     * Skips elements until the predicate is matched. Retains the first element that matches the predicate.
     */
    public StreamWrapper skipUntil(Predicate predicate)
    {
        return new StreamWrapper<>(StreamEx.of(this).dropWhile(predicate.negate()));
    }

    /**
     * short-circuiting operation; limits the stream to the first element that fulfills the predicate
     */
    public StreamWrapper limit(Predicate predicate)
    {
        // #takeWhile comes with Java >= 9
        return new StreamWrapper<>(StreamEx.of(this).takeWhileInclusive(predicate.negate()));
    }

    public Iterator iterator()
    {
        return wrappedStream.iterator();
    }

    public Spliterator spliterator()
    {
        return wrappedStream.spliterator();
    }

    public boolean isParallel()
    {
        return wrappedStream.isParallel();
    }

    public Stream sequential()
    {
        return wrappedStream.sequential();
    }

    public Stream parallel()
    {
        return wrappedStream.parallel();
    }

    public Stream unordered()
    {
        return wrappedStream.unordered();
    }

    public Stream onClose(Runnable closeHandler)
    {
        return wrappedStream.onClose(closeHandler);
    }

    public void close()
    {
        wrappedStream.close();
    }

    public Stream filter(Predicate predicate)
    {
        return wrappedStream.filter(predicate);
    }

    public  Stream map(Function mapper)
    {
        return wrappedStream.map(mapper);
    }

    public IntStream mapToInt(ToIntFunction mapper)
    {
        return wrappedStream.mapToInt(mapper);
    }

    public LongStream mapToLong(ToLongFunction mapper)
    {
        return wrappedStream.mapToLong(mapper);
    }

    public DoubleStream mapToDouble(ToDoubleFunction mapper)
    {
        return wrappedStream.mapToDouble(mapper);
    }

    public  Stream flatMap(Function> mapper)
    {
        return wrappedStream.flatMap(mapper);
    }

    public IntStream flatMapToInt(Function mapper)
    {
        return wrappedStream.flatMapToInt(mapper);
    }

    public LongStream flatMapToLong(Function mapper)
    {
        return wrappedStream.flatMapToLong(mapper);
    }

    public DoubleStream flatMapToDouble(Function mapper)
    {
        return wrappedStream.flatMapToDouble(mapper);
    }

    public Stream distinct()
    {
        return wrappedStream.distinct();
    }

    public Stream sorted()
    {
        return wrappedStream.sorted();
    }

    public Stream sorted(Comparator comparator)
    {
        return wrappedStream.sorted(comparator);
    }

    public Stream peek(Consumer action)
    {
        return wrappedStream.peek(action);
    }

    public Stream limit(long maxSize)
    {
        return wrappedStream.limit(maxSize);
    }

    public Stream skip(long n)
    {
        return wrappedStream.skip(n);
    }

    public void forEach(Consumer action)
    {
        wrappedStream.forEach(action);
    }

    public void forEachOrdered(Consumer action)
    {
        wrappedStream.forEachOrdered(action);
    }

    public Object[] toArray()
    {
        return wrappedStream.toArray();
    }

    public  A[] toArray(IntFunction generator)
    {
        return wrappedStream.toArray(generator);
    }

    public T reduce(T identity, BinaryOperator accumulator)
    {
        return wrappedStream.reduce(identity, accumulator);
    }

    public Optional reduce(BinaryOperator accumulator)
    {
        return wrappedStream.reduce(accumulator);
    }

    public  U reduce(U identity, BiFunction accumulator, BinaryOperator combiner)
    {
        return wrappedStream.reduce(identity, accumulator, combiner);
    }

    public  R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner)
    {
        return wrappedStream.collect(supplier, accumulator, combiner);
    }

    public  R collect(Collector collector)
    {
        return wrappedStream.collect(collector);
    }

    public Optional min(Comparator comparator)
    {
        return wrappedStream.min(comparator);
    }

    public Optional max(Comparator comparator)
    {
        return wrappedStream.max(comparator);
    }

    public long count()
    {
        return wrappedStream.count();
    }

    public boolean anyMatch(Predicate predicate)
    {
        return wrappedStream.anyMatch(predicate);
    }

    public boolean allMatch(Predicate predicate)
    {
        return wrappedStream.allMatch(predicate);
    }

    public boolean noneMatch(Predicate predicate)
    {
        return wrappedStream.noneMatch(predicate);
    }

    public Optional findFirst()
    {
        return wrappedStream.findFirst();
    }

    public Optional findAny()
    {
        return wrappedStream.findAny();
    }
}