Function Package
The org.apache.juneau.commons.function package extends the standard java.util.function toolkit with higher-arity functional interfaces, checked-exception–friendly variants, small immutable tuples, and lazy/nullable suppliers used throughout the framework.
Higher-Arity Functional Interfaces
Two-to-five argument extensions of the standard Consumer and Function patterns.
Consumer2
An operation that accepts two arguments and returns no result. Higher-arity siblings:
Function2
A function that accepts two arguments and produces a result. Higher-arity siblings:
Checked-Exception Variants
Functional interfaces whose functional method is allowed to throw checked exceptions — useful for passing exception-throwing code where the JDK interfaces would force a try/catch.
Snippet
Identical to Runnable but its run() method may throw a checked exception.
ThrowingConsumer
A Consumer whose acceptThrows(T) may throw a checked exception. Higher-arity siblings:
ThrowingFunction
A Function whose functional method may throw a checked exception. Higher-arity siblings:
ThrowingSupplier
A Supplier whose get() may throw a checked exception.
Lazy and Nullable Suppliers
NullableSupplier
A Supplier whose value may be null, with Optional-like null-safe query methods.
NullableSupplier<String> s = NullableSupplier.ofNullable(computeOrNull());
Memoizer
A thread-safe supplier that caches the result of its first call and can be reset.
Memoizer<Config> config = new Memoizer<>(() -> loadExpensiveConfig());
Config c = config.get(); // computed once
config.reset(); // next get() recomputes
Suppliers
Static factory methods for creating memoizing suppliers, without needing to call the NullableSupplier/Memoizer constructors directly.
Suppliers.memoize(Supplier) — wraps aSupplierin a thread-safe, non-resettable memoizingNullableSupplier. The underlying supplier is invoked at most once (races are tolerated — if multiple threads callget()before the first result is cached, the supplier may be invoked more than once, but every caller ends up with the same cached value).Suppliers.memoizer(Supplier) — wraps aSupplierin a resettableMemoizer, equivalent tonew Memoizer<>(supplier).
// One-shot memoization - no reset needed
NullableSupplier<Config> config = Suppliers.memoize(() -> loadExpensiveConfig());
Config c = config.get(); // computed once and cached
// Resettable memoization - equivalent to new Memoizer<>(supplier)
Memoizer<Config> config2 = Suppliers.memoizer(() -> loadExpensiveConfig());
config2.reset(); // next get() recomputes
Tuples
Immutable value tuples with content-based equals()/hashCode() — handy as composite map keys.
Tuple1
A single-value tuple. Wider tuples:
Tuple2<String,Integer> key = Tuple2.of("foo", 42);
String a = key.getA();
Integer b = key.getB();
Bean Streaming
Lifecycle-aware source/target interfaces that let the marshalling layer stream beans one at a time without buffering an entire document.
BeanSupplier
A lazy, one-at-a-time producer used as a serializer source (extends Iterable).
BeanConsumer
A one-at-a-time consumer used as a parser target (extends ThrowingConsumer).
BeanChannel
Combines BeanSupplier and BeanConsumer for round-trip use on the same property or class. ArrayList-backed implementation.
BeanFactory
A universal factory interface used with @Marshalled(factory=...) as the single DI hook for framework-instantiated classes.