Modifier and Type | Class and Description |
---|---|
static interface |
ConsumerUtil.Produmer<PT,CT>
|
Modifier and Type | Method and Description |
---|---|
static <T> Consumer<T> |
addToCollection(Collection<T> drain) |
static <T,EX extends RuntimeException> |
asConsumer(ConsumerWhichThrows<? super T,? extends RuntimeException> source)
Converts the source into a
Consumer<T> . |
static <T,EX extends Throwable> |
asConsumerWhichThrows(Consumer<? super T> source)
Deprecated.
Superseded by
widen2(ConsumerWhichThrows) . |
static Writer |
characterConsumerWriter(ConsumerWhichThrows<? super Character,IOException> delegate) |
static <T> Producer<Consumer<T>> |
combine(Consumer<? super T> target)
The returned producer is a factory for consumers of
T . |
static <T,EX extends Throwable> |
combineInOrder(ConsumerWhichThrows<? super T,EX> target)
The returned producer is a factory for consumers of
T . |
static <T> Consumer<T> |
compress(Consumer<? super T> delegate,
Predicate<? super T> compressable,
T compressed)
Replaces sequences of compressable subjects with one compressed subject.
|
static <T> Consumer<T> |
compress(Consumer<T> delegate,
Predicate<T> compressable)
Forwards each subject it consumes to the given delegate, but only iff the
subject is not compressable.
|
static Consumer<Long> |
compressExponentially(long initialLimit,
Consumer<? super Long> delegate)
Creates and returns a
Consumer<Long> which forwards the quantity to the given delegate , but only if the quantity is equal to or greater than the limit, which starts with initialLimit and increases exponentially. |
static ConsumerUtil.Produmer<Long,Number> |
cumulate()
Equivalent with
cumulate(0L) . |
static Consumer<Number> |
cumulate(Consumer<? super Long> delegate)
Equivalent with
cumulate(delegate) . |
static Consumer<Number> |
cumulate(Consumer<? super Long> delegate,
long initialCount)
Creates and returns a
Consumer which forwards the cumulated quantity to the given delegate . |
static ConsumerUtil.Produmer<Long,Number> |
cumulate(long initialValue)
Creates and returns a
ConsumerUtil.Produmer which adds up the quantities it consumes, and produces the current
total. |
static <T,EX extends Throwable> |
head(Iterable<? extends T> subject,
int n,
ConsumerWhichThrows<? super T,? extends EX> delegate1,
ConsumerWhichThrows<? super T,? extends EX> delegate2)
Passes the first n elements of the subject to delegate1, and all remaining
elements (if any) to delegate2.
|
static <T,EX extends Throwable> |
head(Iterator<? extends T> subject,
int n,
ConsumerWhichThrows<? super T,? extends EX> delegate1,
ConsumerWhichThrows<? super T,? extends EX> delegate2)
Passes the first n products of the subject to delegate1, and all remaining
products (if any) to delegate2.
|
static <T,EX extends Throwable> |
ignoreExceptions(Class<EX> exceptionClass,
ConsumerWhichThrows<T,? extends EX> delegate)
Wraps the delegate such that its declared exception is caught and ignored.
|
static <E extends Exception> |
lineAggregator(ConsumerWhichThrows<? super String,E> delegate)
Creates and returns a
Consumer<Character> which aggregates characters to lines, which it
passes to the delegate. |
static ConsumerWhichThrows<String,IOException> |
lineConsumer(File file,
boolean append) |
static ConsumerWhichThrows<String,IOException> |
lineConsumer(File file,
String charsetName,
boolean append) |
static Consumer<String> |
lineConsumer(PrintStream printStream,
boolean closeOnFinalize) |
static ConsumerWhichThrows<String,IOException> |
lineConsumer(Writer writer,
boolean closeOnFinalize) |
static <T> Consumer<T> |
nop() |
static <T,EX extends Throwable> |
splice(int n,
ConsumerWhichThrows<? super List<T>,EX> target)
Returns a list of consumers of size n.
|
static <T> ConsumerUtil.Produmer<T,T> |
store()
Equivalent with
store(null) . |
static <T> ConsumerUtil.Produmer<T,T> |
store(T initialValue)
The returned
ConsumerUtil.Produmer simply produces the last consumed subject, or initialValue if no
subject has been consumed yet. |
static <T,EX extends Throwable> |
tail(Collection<? extends T> subject,
int n,
ConsumerWhichThrows<? super T,? extends EX> delegate1,
ConsumerWhichThrows<? super T,? extends EX> delegate2)
Passes the first subject
.length() - n elements of the subject
collection to delegate1, and all remaining elements (if any) to delegate2. |
static <T,EX extends Throwable> |
tail(Iterator<? extends T> subject,
int n,
ConsumerWhichThrows<? super T,? extends EX> delegate1,
ConsumerWhichThrows<? super T,? extends EX> delegate2)
Passes the first x - n products of the subject to delegate1, and all
remaining products (if any) to delegate2, where x is the number of products of the
subject.
|
static <T,EX extends Throwable> |
tee(Collection<ConsumerWhichThrows<? super T,EX>> delegates) |
static <T> Consumer<T> |
tee(Consumer<? super T> delegate1,
Consumer<? super T> delegate2) |
static <T,EX extends Throwable> |
tee(ConsumerWhichThrows<? super T,EX> delegate1,
ConsumerWhichThrows<? super T,EX> delegate2) |
static <EX extends Throwable> |
throwsSubject() |
static <T,EX extends Throwable> |
widen(ConsumerWhichThrows<? super T,? extends EX> source)
Deprecated.
Not necessary if you declare variables, fields an parameters as "
ConsumerWhichThrows<? super
consumed-type, ? extends thrown-exception> " |
static <T,EX extends Throwable> |
widen2(ConsumerWhichThrows<? super T,? extends RuntimeException> source)
Converts the source into a
ConsumerWhichThrows<T, EX> . |
public static <T,EX extends Throwable> ConsumerWhichThrows<T,EX> tee(ConsumerWhichThrows<? super T,EX> delegate1, ConsumerWhichThrows<? super T,EX> delegate2)
public static <T> Consumer<T> tee(Consumer<? super T> delegate1, Consumer<? super T> delegate2)
public static <T,EX extends Throwable> ConsumerWhichThrows<T,EX> tee(Collection<ConsumerWhichThrows<? super T,EX>> delegates)
@Deprecated public static <T,EX extends Throwable> ConsumerWhichThrows<T,EX> asConsumerWhichThrows(Consumer<? super T> source)
widen2(ConsumerWhichThrows)
.ConsumerWhichThrows<T, EX>
.
This is always possible, because the source is only allowed to throw unchecked exceptions.
T
- The element typeEX
- The target consumer's exception@Deprecated public static <T,EX extends Throwable> ConsumerWhichThrows<T,EX> widen(ConsumerWhichThrows<? super T,? extends EX> source)
ConsumerWhichThrows<? super
consumed-type, ? extends thrown-exception>
"ConsumerWhichThrows<T, EX>
.
This is always possible, because the source consumes a superclass of T, and the source is only allowed to throw a subclass of EX.
T
- The element typeEX
- The target consumer's exceptionpublic static <T,EX extends Throwable> ConsumerWhichThrows<T,EX> widen2(ConsumerWhichThrows<? super T,? extends RuntimeException> source)
ConsumerWhichThrows<T, EX>
.
This is always possible, because the source consumes a superclass of T, and the
source is only allowed to throw a RuntimeException
.
T
- The element typeEX
- The target consumer's exceptionpublic static <T,EX extends RuntimeException> Consumer<T> asConsumer(ConsumerWhichThrows<? super T,? extends RuntimeException> source)
Consumer<T>
.
This is always possible, because both ar allowed to throw RuntimeException
s.
T
- The element typeEX
- The source consumer's exceptionpublic static Writer characterConsumerWriter(ConsumerWhichThrows<? super Character,IOException> delegate)
Writer
which forwards the characters to a ConsumerWhichThrows<Character, IOException>
public static <E extends Exception> ConsumerWhichThrows<Character,E> lineAggregator(ConsumerWhichThrows<? super String,E> delegate)
Consumer<Character>
which aggregates characters to lines, which it
passes to the delegate.
Notice that iff the last consumed character is neither a CR nor an LF (a.k.a. "last line lacks a line separator"), then that last line will not be sent to the delegate.
public static ConsumerWhichThrows<String,IOException> lineConsumer(File file, boolean append) throws IOException
Consumer
that writes lines to the given file with the default character encodingIOException
public static ConsumerWhichThrows<String,IOException> lineConsumer(File file, String charsetName, boolean append) throws IOException
Consumer
that writes lines to the given file with the given encodingIOException
public static ConsumerWhichThrows<String,IOException> lineConsumer(Writer writer, boolean closeOnFinalize)
public static Consumer<String> lineConsumer(PrintStream printStream, boolean closeOnFinalize)
public static <T> Producer<Consumer<T>> combine(Consumer<? super T> target)
T
. The subjects sent to these consumers are
forwarded immediately to the given target.combineInOrder(ConsumerWhichThrows)
public static <T,EX extends Throwable> Producer<ConsumerWhichThrows<T,EX>> combineInOrder(ConsumerWhichThrows<? super T,EX> target)
T
. The first subject sent to each of these consumers
is passed to the given target in the order the consumers were created (not in the order in
which the subjects were sent to the consumers).combine(Consumer)
public static <T,EX extends Throwable> List<ConsumerWhichThrows<T,EX>> splice(int n, ConsumerWhichThrows<? super List<T>,EX> target)
public static <T> Consumer<T> addToCollection(Collection<T> drain)
public static <EX extends Throwable> ConsumerWhichThrows<EX,EX> throwsSubject()
ConsumerWhichThrows
which throws each subject it consumespublic static <T> ConsumerUtil.Produmer<T,T> store()
store(null)
.public static <T> ConsumerUtil.Produmer<T,T> store(@Nullable T initialValue)
ConsumerUtil.Produmer
simply produces the last consumed subject, or initialValue if no
subject has been consumed yet.public static Consumer<Number> cumulate(Consumer<? super Long> delegate)
cumulate(delegate)
.public static Consumer<Number> cumulate(Consumer<? super Long> delegate, long initialCount)
Consumer
which forwards the cumulated quantity to the given delegate
.initialCount
- Initial value for the cumulated quantity, usually 0L
public static ConsumerUtil.Produmer<Long,Number> cumulate()
cumulate(0L)
.public static ConsumerUtil.Produmer<Long,Number> cumulate(long initialValue)
ConsumerUtil.Produmer
which adds up the quantities it consumes, and produces the current
total.initialValue
- Initial value for the cumulated quantity, usually 0L
public static Consumer<Long> compressExponentially(long initialLimit, Consumer<? super Long> delegate)
Consumer<Long>
which forwards the quantity to the given delegate
, but only if the quantity is equal to or greater than the limit, which starts with initialLimit
and increases exponentially.public static <T> Consumer<T> compress(Consumer<T> delegate, Predicate<T> compressable)
public static <T> Consumer<T> compress(Consumer<? super T> delegate, Predicate<? super T> compressable, T compressed)
Leading and trailing compressables are discarded.
public static <T> Consumer<T> nop()
public static <T,EX extends Throwable> Consumer<T> ignoreExceptions(Class<EX> exceptionClass, ConsumerWhichThrows<T,? extends EX> delegate)
public static <T,EX extends Throwable> void head(Iterable<? extends T> subject, int n, ConsumerWhichThrows<? super T,? extends EX> delegate1, ConsumerWhichThrows<? super T,? extends EX> delegate2) throws EX extends Throwable
This method resembles UNIX's head
command.
EX extends Throwable
public static <T,EX extends Throwable> void head(Iterator<? extends T> subject, int n, ConsumerWhichThrows<? super T,? extends EX> delegate1, ConsumerWhichThrows<? super T,? extends EX> delegate2) throws EX extends Throwable
This method resembles UNIX's head
command.
EX extends Throwable
public static <T,EX extends Throwable> void tail(Iterator<? extends T> subject, int n, ConsumerWhichThrows<? super T,? extends EX> delegate1, ConsumerWhichThrows<? super T,? extends EX> delegate2) throws EX extends Throwable
This method resembles UNIX's tail
command.
EX extends Throwable
public static <T,EX extends Throwable> void tail(Collection<? extends T> subject, int n, ConsumerWhichThrows<? super T,? extends EX> delegate1, ConsumerWhichThrows<? super T,? extends EX> delegate2) throws EX extends Throwable
.length()
- n elements of the subject
collection to delegate1, and all remaining elements (if any) to delegate2.
This method resembles UNIX's tail
command.
EX extends Throwable
Copyright © 2018 Arno Unkrig. All rights reserved.