io.zeebe.test.util.stream.StreamWrapper Maven / Gradle / Ivy
/*
* 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 super T> predicate)
{
return wrappedStream.filter(predicate);
}
public Stream map(Function super T, ? extends R> mapper)
{
return wrappedStream.map(mapper);
}
public IntStream mapToInt(ToIntFunction super T> mapper)
{
return wrappedStream.mapToInt(mapper);
}
public LongStream mapToLong(ToLongFunction super T> mapper)
{
return wrappedStream.mapToLong(mapper);
}
public DoubleStream mapToDouble(ToDoubleFunction super T> mapper)
{
return wrappedStream.mapToDouble(mapper);
}
public Stream flatMap(Function super T, ? extends Stream extends R>> mapper)
{
return wrappedStream.flatMap(mapper);
}
public IntStream flatMapToInt(Function super T, ? extends IntStream> mapper)
{
return wrappedStream.flatMapToInt(mapper);
}
public LongStream flatMapToLong(Function super T, ? extends LongStream> mapper)
{
return wrappedStream.flatMapToLong(mapper);
}
public DoubleStream flatMapToDouble(Function super T, ? extends DoubleStream> mapper)
{
return wrappedStream.flatMapToDouble(mapper);
}
public Stream distinct()
{
return wrappedStream.distinct();
}
public Stream sorted()
{
return wrappedStream.sorted();
}
public Stream sorted(Comparator super T> comparator)
{
return wrappedStream.sorted(comparator);
}
public Stream peek(Consumer super T> 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 super T> action)
{
wrappedStream.forEach(action);
}
public void forEachOrdered(Consumer super T> 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 super T, A, R> collector)
{
return wrappedStream.collect(collector);
}
public Optional min(Comparator super T> comparator)
{
return wrappedStream.min(comparator);
}
public Optional max(Comparator super T> comparator)
{
return wrappedStream.max(comparator);
}
public long count()
{
return wrappedStream.count();
}
public boolean anyMatch(Predicate super T> predicate)
{
return wrappedStream.anyMatch(predicate);
}
public boolean allMatch(Predicate super T> predicate)
{
return wrappedStream.allMatch(predicate);
}
public boolean noneMatch(Predicate super T> predicate)
{
return wrappedStream.noneMatch(predicate);
}
public Optional findFirst()
{
return wrappedStream.findFirst();
}
public Optional findAny()
{
return wrappedStream.findAny();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy