| Modifier and Type | Method and Description |
|---|---|
static <T,R> Stream<R> |
extract(T object,
Function<? super T,? extends R>... extractors)
Extract (derive) multiple values from one given object.
|
static <T,R> Stream<R> |
extractIfPresent(T object,
Function<? super T,? extends Optional<R>>... extractors)
Extract (derive) multiple values from one given object.
|
static String |
friendlyName(Class<?> clazz)
The "friendly name" of a class is defined as its
simple name, with
all enclosing classes prepended and joined with a '.' delimiter. |
static <T> T |
nonNull(String descriptiveRefKey,
Function<? super String,T> refResolver)
Not allow
null-references. |
static <T,X extends Throwable> |
nonNull(String descriptiveRefKey,
Function<? super String,T> refResolver,
Function<? super String,X> throwIfNull)
Not allow
null-references. |
static <T> T |
nonNull(String description,
T t)
Not allow
null-references. |
static <T,X extends Throwable> |
nonNull(String description,
T t,
Function<? super String,X> throwIfNull)
Not allow
null-references. |
static <T,X extends Throwable> |
nonNull(T t,
Supplier<X> throwIfNull)
Not allow
null-references. |
public static <T> T nonNull(String description, T t)
null-references.description - A small description of the reference. Will be used in the exception message if
the reference is nullt - the referenceNullPointerException - if t is null.public static <T,X extends Throwable> T nonNull(String description, T t, Function<? super String,X> throwIfNull) throws X extends Throwable
null-references.description - A small description of the reference. Will be used in the exception message if
the reference is nullt - the referencethrowIfNull - Construct the exception to be thrown if the reference is null.X - if t is null.X extends Throwablepublic static <T,X extends Throwable> T nonNull(T t, Supplier<X> throwIfNull) throws X extends Throwable
null-references.t - the referencethrowIfNull - the exception to throw if t is nullX - if t is null.X extends Throwablepublic static <T> T nonNull(String descriptiveRefKey, Function<? super String,T> refResolver)
null-references. This is a convenience method for when a descriptive refKey
can be used to resolve the reference, for instance to resolve resources
on classpath with .class::getResourceAsStream.
The refKey will appear in the exception message if the resolved reference is null.descriptiveRefKey - the key used to resolve the referencerefResolver - the function the will resolve the non-null result based on the description.refResolver, never nullpublic static <T,X extends Throwable> T nonNull(String descriptiveRefKey, Function<? super String,T> refResolver, Function<? super String,X> throwIfNull) throws X extends Throwable
null-references.descriptiveRefKey - the key used to resolve the referencerefResolver - the function the will resolve the non-null result based on the description.throwIfNull - the function to construct the exception if the refResolver yields null.refResolver, never nullX - if refResolver yields nullX extends Throwablepublic static String friendlyName(Class<?> clazz)
simple name, with
all enclosing classes prepended and joined with a '.' delimiter. This name is typically
useful for logging, naming based on classes, where the fully qualified name would be too verbose
and the simple name is not specific enough.
Given the following class model:
class Base {
class Nested {}
}
The friendly name for the Nested class is "Base.Nested".clazz - the clazz to get the friendly name of@SafeVarargs public static final <T,R> Stream<R> extract(T object, Function<? super T,? extends R>... extractors)
T - The type of the object to extract from.R - The resulting most common type of the extracted values. Typically, the extractors
should yield the same type.object - the object to extract values from.extractors - each function that will extract a value from the given object. The resulting
value must not be null. Use extract(Object, Function...)
if the extractors may yield non-existing values.@SafeVarargs public static final <T,R> Stream<R> extractIfPresent(T object, Function<? super T,? extends Optional<R>>... extractors)
{@link #extract(Object, Function...) extract(object, extractors...)}{@link Stream#filter(java.util.function.Predicate) .filter(}{@link Optional#isPresent() Optional::isPresent)}{@link Stream#map(Function) .map(}{@link Optional#get() Optional::get)}
T - The type of the object to extract from.R - The resulting most common type of the extracted values. Typically, the extractors
should yield the same type.object - the object to extract values from.extractors - each function that will extract a value from the given object.Copyright © 2016 Digipost. All rights reserved.