public abstract class ObjectUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ObjectUtils.OrElse
Class allowing the invocation of a given
Runnable depending on whether the previous operation was
executed, formulated as a boolean. |
| Modifier and Type | Method and Description |
|---|---|
static <T> ObjectUtils.OrElse |
doIfNotNull(T instance,
Consumer<T> action)
Performs the given
action consuming the given instance, granted that it is not null. |
static boolean |
hasLength(String s)
|
static <T> T |
nonNullOrDefault(T instance,
T ifNull)
Returns the given
instance if it is not null. |
static String |
randomHex(int length)
Creates a random
String of the given length. |
static <T> void |
silently(T instance,
Consumer<T> action)
Silently performs the given
action consuming the given instance, granted that it is not null. |
public static <T> T nonNullOrDefault(T instance,
T ifNull)
instance if it is not null. Otherwise ifNull is returned.T - the type of the given instance and ifNullinstance - the object to validate if it is no nullifNull - the object to return if instance is nullinstance if it is not null. Otherwise ifNull is returnedpublic static <T> ObjectUtils.OrElse doIfNotNull(T instance, Consumer<T> action)
action consuming the given instance, granted that it is not null.T - the type of the given instance and object to consume by the given actioninstance - the object to consume by the given action, if it is not nullaction - the Consumer invoked with the given instanceObjectUtils.OrElse to allow to perform another operation if the given action was not executedpublic static <T> void silently(T instance,
Consumer<T> action)
action consuming the given instance, granted that it is not null. Will swallow any exceptions thrown by the actionT - the type of the given instance and object to consume by the given actioninstance - the object to consume by the given action, if it is not nullaction - the Consumer to silently invoke with the given instancepublic static boolean hasLength(String s)
Copyright © 2020–2023 AxonIQ BV. All rights reserved.