public final class ProducerUtil
extends java.lang.Object
Producer-related utility methods.| Modifier and Type | Method and Description |
|---|---|
static <T> Producer<T> |
alternate(T first,
T second) |
static <T> Producer<T> |
asProducer(ProducerWhichThrows<? extends T,? extends java.lang.RuntimeException> source)
Converts the source into a
Producer<T>. |
static <T,EX extends java.lang.Throwable> |
asProducerWhichThrows(Producer<? extends T> source)
Converts the source into a
ProducerWhichThrows<T, EX>. |
static <T> Producer<T> |
compress(Producer<? extends T> delegate,
Predicate<? super T> compressable,
T compressed)
Discards the elements that the delegate produces while they are compressable.
|
static <T> Producer<T> |
concat(Producer<? extends T> delegate1,
Producer<? extends T> delegate2) |
static <T> Producer<T> |
constantProducer(T constant) |
static Producer<java.lang.Boolean> |
every(long interval)
Returns a
Producer<Boolean> who's first evaluation result is true, and each following result is
true iff the last true result was returned at least the given interval milliseconds ago. |
static <T> Producer<T> |
fromArray(T[] delegate)
Produces the elements of the delegate array, in ascending index order, and after that an infinite
sequence of
nulls. |
static <T> Producer<T> |
fromArray(T[] delegate,
int from,
int to)
Produces the elements from ...
|
static <T> Producer<T> |
fromCollection(java.util.Collection<T> delegate)
Produces the elements of the
delegate collection, in its iteration order, or null iff the
collection is empty. |
static <T> Producer<T> |
fromElements(T... elements) |
static <T> Producer<T> |
fromIndexTransformer(Transformer<? super java.lang.Integer,T> indexTransformer)
Produces objects based on the number of preceding invocations, i.e. the
indexTransformer is invoked
with subjects '0', '1', '2', ... |
static <T,EX extends java.lang.Exception> |
fromIndexTransformer(TransformerWhichThrows<? super java.lang.Integer,T,EX> indexTransformer)
Produces objects based on the number of preceding invocations, i.e. the
indexTransformer is invoked
with subjects '0', '1', '2', ... |
static <T> Producer<T> |
fromIterator(java.util.Iterator<T> iterator)
Produces the products of the
iterator, or null iff the iterator has no more elements. |
static Producer<java.lang.Integer> |
increasing() |
static Producer<java.lang.Byte> |
randomByteProducer(long seed) |
static <T,ST> Producer<T> |
sparingProducer(Producer<? extends T> delegate,
Predicate<? super ST> condition,
ST subject)
The returned
Producer calls the delegate iff the condition returns true,
otherwise it returns the previous product of the delegate, or null iff the delegate has
not yet been called. |
public static <T,ST> Producer<T> sparingProducer(Producer<? extends T> delegate, Predicate<? super ST> condition, ST subject)
Producer calls the delegate iff the condition returns true,
otherwise it returns the previous product of the delegate, or null iff the delegate has
not yet been called.subject - The subject argument for the conditionpublic static Producer<java.lang.Boolean> every(long interval)
Producer<Boolean> who's first evaluation result is true, and each following result is
true iff the last true result was returned at least the given interval milliseconds ago.
In other words, the interval between two returned true values is never shorter than interval
milliseconds.public static <T,EX extends java.lang.Throwable> ProducerWhichThrows<T,EX> asProducerWhichThrows(Producer<? extends T> source)
ProducerWhichThrows<T, EX>.
This is always possible, because the source is only allowed to throw RuntimeExceptions.
Notice Producer<T> extends ProducerWhichThrows<T, RuntimeException>, thus you don't
need this method to convert to ProducerWhichThrows<T, RuntimeException>.
T - The product typeEX - The target producer's exceptionpublic static <T> Producer<T> asProducer(ProducerWhichThrows<? extends T,? extends java.lang.RuntimeException> source)
Producer<T>.
This is always possible, because both are only allowed to throw RuntimeExceptions.
T - The product typepublic static <T> Producer<T> fromElements(T... elements)
Producer that produced the given elementspublic static <T> Producer<T> fromCollection(java.util.Collection<T> delegate)
delegate collection, in its iteration order, or null iff the
collection is empty. The elements are removed from the collection as they are produced.public static <T> Producer<T> fromArray(T[] delegate)
nulls.public static <T> Producer<T> fromArray(T[] delegate, int from, int to)
delegate array, and after that an
infinite sequence of nulls.java.lang.IllegalArgumentException - from is less than 0java.lang.IllegalArgumentException - to is less than fromjava.lang.IllegalArgumentException - to is greater than delegate.lengthpublic static <T> Producer<T> fromIterator(java.util.Iterator<T> iterator)
iterator, or null iff the iterator has no more elements.public static <T> Producer<T> fromIndexTransformer(Transformer<? super java.lang.Integer,T> indexTransformer)
indexTransformer is invoked
with subjects '0', '1', '2', ...public static <T,EX extends java.lang.Exception> ProducerWhichThrows<T,EX> fromIndexTransformer(TransformerWhichThrows<? super java.lang.Integer,T,EX> indexTransformer)
indexTransformer is invoked
with subjects '0', '1', '2', ...public static Producer<java.lang.Byte> randomByteProducer(long seed)
new java.util.Random(seed).nextInt(0x100)public static <T> Producer<T> constantProducer(T constant)
constantpublic static <T> Producer<T> compress(Producer<? extends T> delegate, Predicate<? super T> compressable, T compressed)
public static <T> Producer<T> alternate(T first, T second)
Producer that produces first, second, first,
second, ...public static Producer<java.lang.Integer> increasing()
Producer that produces 0, 1, 2, 3, ...