Modifier and Type | Class and Description |
---|---|
static interface |
ProducerUtil.BooleanProducer |
static interface |
ProducerUtil.FromArrayProducer<T>
Extends the concept of the
Producer by an "index". |
Modifier and Type | Method and Description |
---|---|
static Producer<Boolean> |
after(long expirationTime)
Returns a "
Producer <Object> " that produces true iff the current time is after the
given expirationTime (in milliseconds). |
static <T> Producer<T> |
alternate(T first,
T second)
Creates and returns a
Producer that produces first, second, first,
second, ... |
static <T> Producer<T> |
asProducer(ProducerWhichThrows<? extends T,? extends RuntimeException> source)
Converts the source into a
Producer<T> . |
static <T,EX extends Throwable> |
asProducerWhichThrows(Producer<? extends T> source)
Converts the source into a
ProducerWhichThrows<T, EX> . |
static Producer<Boolean> |
atMostEvery(long milliseconds)
Creates and returns a producer for which the first product is
true , and, for all following
products, the time interval between adjacent true products will (A) be minimal and (B) never
shorter than milliseconds. |
static Producer<Boolean> |
atMostEvery(long milliseconds,
boolean firstProduct,
boolean startAtTrueProduct)
Creates and returns a producer which first produces firstProduct, and afterwards products that are
true iff they are produced milliseconds or more after the most recent true product,
or, iff ! |
static <T,EX extends Throwable> |
cache(ProducerWhichThrows<T,? extends EX> delegate)
Constantly produces the first product of the delegate.
|
static <T,EX extends Throwable> |
cache(ProducerWhichThrows<T,? extends EX> delegate,
ProducerWhichThrows<Boolean,? extends EX> invalidationCondition)
The first product is the first product of the delegate; each following product is the next product
of the delegate if the invalidationCondition evaluates to
true , otherwise it is
the previous product. |
static <T,EX extends Throwable> |
cache(T firstProduct,
ProducerWhichThrows<T,? extends EX> delegate,
ProducerWhichThrows<Boolean,? extends EX> invalidationCondition)
The first product is the firstProduct; each following product is the next product of the
delegate iff the invalidationCondition evaluates to
true , otherwise it is the
previous product. |
static <T,EX extends Throwable> |
cacheAsynchronously(ProducerWhichThrows<Future<T>,? extends EX> delegate,
ProducerWhichThrows<Boolean,? extends EX> invalidationCondition,
boolean prefetch)
Creates and returns a producer which caches the products of a delegate producer asynchronously.
|
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)
Creates and returns a producer that produces the products of delegate1, and, when that produces
null , the products of delegate2. |
static <T> Producer<T> |
constantProducer(T constant) |
static Producer<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,EX extends Throwable> |
filter(ProducerWhichThrows<? extends T,? extends EX> delegate,
Predicate<? super T> predicate) |
static <T,EX extends Throwable> |
filter(ProducerWhichThrows<? extends T,? extends EX> delegate,
PredicateWhichThrows<? super T,? extends EX> predicate)
Returns a producer which, when invoked, calls the delegate, and returns its product iff the
predicate evaluates to
true . |
static <T> ProducerUtil.FromArrayProducer<T> |
fromArray(T[] delegate)
Produces the elements of the delegate array, in ascending index order, and after that an infinite
sequence of
null s. |
static <T> ProducerUtil.FromArrayProducer<T> |
fromArray(T[] delegate,
int from,
int to)
Produces the elements from ...
|
static <T> Producer<T> |
fromCollection(Collection<T> delegate)
Deprecated.
Use "
fromIterator( delegate.iterator(), true) " instead |
static <T> Producer<T> |
fromElements(T... elements)
Creates and returns a
Producer that produced the given elements. |
static <T> Producer<T> |
fromIndexTransformer(Transformer<? super 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 Throwable> |
fromIndexTransformer(TransformerWhichThrows<? super 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> |
fromIterable(Iterable<T> delegate,
boolean remove)
Deprecated.
Use "
fromIterator( delegate.iterator(), true) " instead |
static <T> Producer<T> |
fromIterator(Iterator<T> delegate)
Produces the products of the delegate, or
null iff the delegate has no more
elements. |
static <T> Producer<T> |
fromIterator(Iterator<T> delegate,
boolean remove)
Produces the products of the delegate, or
null iff the delegate has no more
elements. |
static <T,EX extends Throwable> |
ignoreExceptions(Class<EX> exceptionClass,
ProducerWhichThrows<T,EX> delegate,
T defaultValue)
Wraps the delegate such that its declared exception is caught, ignored, and the
defaultValue is returned.
|
static Producer<Integer> |
increasing()
Creates and returns a
Producer that produces 0, 1, 2, 3, ... |
static Producer<Integer> |
increasing(int initialValue)
|
static ProducerUtil.BooleanProducer |
once() |
static Producer<Boolean> |
oneOutOf(int n,
int initialFalses) |
static Producer<Byte> |
randomByteProducer(long seed) |
static <T,EX extends Exception> |
roundRobin(ProducerWhichThrows<? extends T,? extends EX>... delegates)
The ith product is produced by delegates
[ i % delegates.length].produce() . |
static <T,ST> Producer<T> |
sparingProducer(Producer<? extends T> delegate,
Predicate<? super ST> condition,
ST subject)
Deprecated.
Use
cache(ProducerWhichThrows, ProducerWhichThrows) instead, which has very similar (but
not identical) semantics. |
static <T,EX extends Throwable> |
synchronizedProducer(ProducerWhichThrows<? extends T,EX> delegate)
Creates and returns a proxy to the delegate with a synchronized
produce() method. |
static <T1,T2,EX extends Throwable> |
transform(ProducerWhichThrows<? extends T1,? extends EX> delegate,
FunctionWhichThrows<? super T1,? extends T2,EX> function)
Transforms each product of the delegate through the function.
|
static <T1,T2,EX extends Throwable> |
transform(ProducerWhichThrows<? extends T1,? extends EX> delegate,
TransformerWhichThrows<? super T1,? extends T2,EX> transformer)
Transforms each product of the delegate through the transformer.
|
@Deprecated public static <T,ST> Producer<T> sparingProducer(Producer<? extends T> delegate, Predicate<? super ST> condition, ST subject)
cache(ProducerWhichThrows, ProducerWhichThrows)
instead, which has very similar (but
not identical) semantics.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<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.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> asProducerWhichThrows(Producer<? extends T> source)
ProducerWhichThrows<T, EX>
.
This is always possible, because the source is only allowed to throw RuntimeException
s.
Notice Producer<T>
extends ProducerWhichThrows<T, NoException>
, thus you don't
need this method to convert to ProducerWhichThrows<T, NoException>
.
T
- The product typeEX
- The target producer's exceptionpublic static <T> Producer<T> asProducer(ProducerWhichThrows<? extends T,? extends RuntimeException> source)
Producer<T>
.
This is always possible, because both are only allowed to throw RuntimeException
s.
T
- The product typepublic static <T> Producer<T> fromElements(T... elements)
Producer
that produced the given elements.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
@Deprecated public static <T> Producer<T> fromCollection(Collection<T> delegate)
fromIterator(
delegate.iterator(), true)
" instead@Deprecated public static <T> Producer<T> fromIterable(Iterable<T> delegate, boolean remove)
fromIterator(
delegate.iterator(), true)
" insteadpublic static <T> ProducerUtil.FromArrayProducer<T> fromArray(T[] delegate)
null
s.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T> ProducerUtil.FromArrayProducer<T> fromArray(T[] delegate, int from, int to)
null
s.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
IllegalArgumentException
- from is less than 0IllegalArgumentException
- to is less than fromIllegalArgumentException
- to is greater than delegate.length
public static <T> Producer<T> fromIterator(Iterator<T> delegate)
null
iff the delegate has no more
elements.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T> Producer<T> fromIterator(Iterator<T> delegate, boolean remove)
null
iff the delegate has no more
elements.
If remove is true
, then products are removed from the underlying collections as the
elements are iterated.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T> Producer<T> fromIndexTransformer(Transformer<? super Integer,T> indexTransformer)
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> fromIndexTransformer(TransformerWhichThrows<? super Integer,T,EX> indexTransformer)
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T1,T2,EX extends Throwable> ProducerWhichThrows<T2,EX> transform(ProducerWhichThrows<? extends T1,? extends EX> delegate, TransformerWhichThrows<? super T1,? extends T2,EX> transformer)
null
products are not transformed and give a null
product.
public static <T1,T2,EX extends Throwable> ProducerWhichThrows<T2,EX> transform(ProducerWhichThrows<? extends T1,? extends EX> delegate, FunctionWhichThrows<? super T1,? extends T2,EX> function)
null
products are not transformed and give a null
product.
public static Producer<Byte> randomByteProducer(long seed)
new java.util.Random(seed).nextInt(0x100)
public static <T> Producer<T> constantProducer(T constant)
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> filter(ProducerWhichThrows<? extends T,? extends EX> delegate, PredicateWhichThrows<? super T,? extends EX> predicate)
true
.public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> filter(ProducerWhichThrows<? extends T,? extends EX> delegate, Predicate<? super T> predicate)
public static <T> Producer<T> compress(Producer<? extends T> delegate, Predicate<? super T> compressable, T compressed)
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T> Producer<T> alternate(T first, T second)
Producer
that produces first, second, first,
second, ...
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static Producer<Integer> increasing()
Producer
that produces 0, 1, 2, 3, ...
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static Producer<Integer> increasing(int initialValue)
Producer
that produces initialValue, initialValue+1
,
initialValue+ 2
, etc.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T> Producer<T> concat(Producer<? extends T> delegate1, Producer<? extends T> delegate2)
null
, the products of delegate2.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> cache(ProducerWhichThrows<T,? extends EX> delegate)
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> cache(ProducerWhichThrows<T,? extends EX> delegate, ProducerWhichThrows<Boolean,? extends EX> invalidationCondition)
true
, otherwise it is
the previous product.
Example:
ProducerUtil.cache(delegate, ProducerUtil.atMostEvery(milliseconds, false, true))
caches the products of the delegate for milliseconds' time.
The returned producer is not synchronized and therefore not thread-safe; to get a thread-safe producer, use
synchronizedProducer(ProducerWhichThrows)
.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> cache(@Nullable T firstProduct, ProducerWhichThrows<T,? extends EX> delegate, ProducerWhichThrows<Boolean,? extends EX> invalidationCondition)
true
, otherwise it is the
previous product.
The returned PredicateWhichThrows
is not synchronized and therefore not thread-safe.
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> cacheAsynchronously(ProducerWhichThrows<Future<T>,? extends EX> delegate, ProducerWhichThrows<Boolean,? extends EX> invalidationCondition, boolean prefetch) throws EX extends Throwable
Iff prefetch is true
, then this method uses the delegate immediately to start
the "background fetch".
On the first call to produce()
of the returned producer:
On all consecutive calls to produce()
of the returned producer:
Iff the "background fetch" is not pending:
Iff false
:
Iff true
Iff the "background fetch" is pending:
Iff it has not yet completed:
Otherwise, iff the "background fetch" has completed:
Notice that the invalidationCondition is never evaluated while the "background fetch" is pending.
The returned producer is not thread-safe; to get a thread-safe asynchronous cache, use synchronizedProducer(ProducerWhichThrows)
.
The returned producer produces null
if the current thread was interrupted while prefetching.
atMostEvery(milliseconds, false, false
may be a good choice for
the invalidationCondition to set up an expiration-time-based cache.
EX extends Throwable
public static Producer<Boolean> atMostEvery(long milliseconds)
true
, and, for all following
products, the time interval between adjacent true
products will (A) be minimal and (B) never
shorter than milliseconds.
Calling this method is equivalent to calling
ProducerUtil.atMostEvery(milliseconds, true, true)
The returned producer is not thread-safe; to get a thread-safe producer, use synchronizedProducer(ProducerWhichThrows)
.
atMostEvery(long, boolean, boolean)
public static Producer<Boolean> atMostEvery(long milliseconds, boolean firstProduct, boolean startAtTrueProduct)
true
iff they are produced milliseconds or more after the most recent true
product,
or, iff !
startAtTrueProduct, after the first false
product after the most recent
true
product.
The returned producer is not thread-safe; to get a thread-safe producer, use synchronizedProducer(ProducerWhichThrows)
.
public static Producer<Boolean> after(long expirationTime)
Producer
<Object>
" that produces true
iff the current time is after the
given expirationTime (in milliseconds).expirationTime
- Milliseconds since Jan 1 1970, UTCpublic static <T,EX extends Throwable> Producer<T> ignoreExceptions(Class<EX> exceptionClass, ProducerWhichThrows<T,EX> delegate, T defaultValue)
public static <T,EX extends Throwable> ProducerWhichThrows<T,EX> synchronizedProducer(ProducerWhichThrows<? extends T,EX> delegate)
produce()
method.ProducerWhichThrows
public static Producer<Boolean> oneOutOf(int n, int initialFalses)
initialFalses
- How many false
products appear before the first true
productBoolean
s, where every one-out-of-n is true
public static <T,EX extends Exception> ProducerWhichThrows<T,EX> roundRobin(ProducerWhichThrows<? extends T,? extends EX>... delegates)
[
i %
delegates.length].produce()
.public static ProducerUtil.BooleanProducer once()
true
once, and then always false
Copyright © 2018 Arno Unkrig. All rights reserved.