public final class MoreSuppliers
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> Spplr<T> |
cache(Spplr<T> supplier)
Wrap the given supplier in a supplier that will only call the underlying supplier once,
and then cache the returned value.
|
static <T,R> Spplr<R> |
map(Spplr<T> supplier,
Func<T,R> function)
Create a supplier that will transform the value returned by the given supplier by invoking the given function on it.
|
static <T> Spplr<T> |
of(T value)
Create a supplier that will return the given value.
|
static <T> Spplr<java.util.List<T>> |
reflectionListSupplier(java.lang.Object instance,
java.lang.String methodName,
java.lang.Class<T[]> suppliedClass)
Create a supplier that will invoke the method specified by the give method name
on the given object instance through reflection.
|
static <T> Spplr<T> |
reflectionSupplier(java.lang.Object instance,
java.lang.String methodName,
java.lang.Class<T> suppliedClass)
Create a supplier that will invoke the method specified by the give method name
on the given object instance through reflection.
|
static <T> Spplr<T> |
reflectionSupplier(java.lang.Object instance,
java.lang.String methodName,
java.lang.Class<T> primaryClass,
java.lang.Class<T> secondaryClass)
Similar to
reflectionSupplier(Object, String, Class), except allows for an alternative return type. |
public static <T> Spplr<T> of(T value)
T - Value type.value - Value to return.Spplr that will return the given constant value.public static <T,R> Spplr<R> map(@NonNull Spplr<T> supplier, @NonNull Func<T,R> function)
T - Supplied value type.R - Transformed value type.supplier - Supplier to transform.function - Function to transform the supplier with.Spplr that will apply the given function to the value supplied by the given supplier.public static <T> Spplr<T> cache(@NonNull Spplr<T> supplier)
T - Supplied value type.supplier - Supplier to cache.Spplr that will call the wrapped supplier once and only once and cache the value for future
calls.public static <T> Spplr<T> reflectionSupplier(@NonNull java.lang.Object instance, @NonNull java.lang.String methodName, @NonNull java.lang.Class<T> suppliedClass)
T - Supplier return type.instance - Instance to invoke the method one.methodName - Method name to invoke. Method must be no-args and return a value of the specified type.suppliedClass - Expected return type of the method.Spplr that will invoke the no-args method specified by the given name on the given instance.public static <T> Spplr<T> reflectionSupplier(java.lang.Object instance, java.lang.String methodName, java.lang.Class<T> primaryClass, java.lang.Class<T> secondaryClass)
reflectionSupplier(Object, String, Class), except allows for an alternative return type.
Will first try to create a reflection supplier using the primary class, but if that fails (the method doesn't
return the primary class), will re-try with the secondary class.
Useful for cases where the return type could be either a primitive or the primitive's boxed version
(i.e. Integer.type or Integer.class).T - Supplier return type.instance - Instance to invoke the method one.methodName - Method name to invoke. Method must be no-args and return a value of
either the primary class or the secondary type.primaryClass - Primary return type of the method. Will be tried first.secondaryClass - Secondary return type of the method.
Will be tried if the method doesn't return the primary type.Spplr that will invoke the no-args method specified by the given name on the given instance.public static <T> Spplr<java.util.List<T>> reflectionListSupplier(java.lang.Object instance, java.lang.String methodName, java.lang.Class<T[]> suppliedClass)
List of values.
The method must be no-args and must return an array of the specified type.
The method may be private, in which case it will be made accessible outside it's class.T - Supplier return type.instance - Instance to invoke the method one.methodName - Method name to invoke. Method must be no-args and return an array of the specified type.suppliedClass - Expected array return type of the method.Spplr that will invoke the no-args method specified by the given name on the given instance.