- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.ObjectUtils
-
public abstract class ObjectUtils extends Object
Several general utilities to deal with objects and the like.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classObjectUtils.OrElseClass allowing the invocation of a givenRunnabledepending on whether the previous operation was executed, formulated as aboolean.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> ObjectUtils.OrElsedoIfNotNull(T instance, Consumer<T> action)Performs the givenactionconsuming the giveninstance, granted that it is notnull.static booleanhasLength(String s)static <T> TnonNullOrDefault(T instance, T ifNull)Returns the giveninstanceif it is notnull.static StringrandomHex(int length)Creates a randomStringof the givenlength.static <T> voidsilently(T instance, Consumer<T> action)Silently performs the givenactionconsuming the giveninstance, granted that it is notnull.
-
-
-
Method Detail
-
nonNullOrDefault
public static <T> T nonNullOrDefault(T instance, T ifNull)Returns the giveninstanceif it is notnull. OtherwiseifNullis returned.- Type Parameters:
T- the type of the giveninstanceandifNull- Parameters:
instance- the object to validate if it is nonullifNull- the object to return ifinstanceisnull- Returns:
- the given
instanceif it is notnull. OtherwiseifNullis returned
-
doIfNotNull
public static <T> ObjectUtils.OrElse doIfNotNull(T instance, Consumer<T> action)
Performs the givenactionconsuming the giveninstance, granted that it is notnull.- Type Parameters:
T- the type of the giveninstanceand object to consume by the givenaction- Parameters:
instance- the object to consume by the givenaction, if it is notnullaction- theConsumerinvoked with the giveninstance- Returns:
- an
ObjectUtils.OrElseto allow to perform another operation if the givenactionwas not executed
-
silently
public static <T> void silently(T instance, Consumer<T> action)Silently performs the givenactionconsuming the giveninstance, granted that it is notnull. Will swallow any exceptions thrown by theaction- Type Parameters:
T- the type of the giveninstanceand object to consume by the givenaction- Parameters:
instance- the object to consume by the givenaction, if it is notnullaction- theConsumerto silently invoke with the giveninstance
-
hasLength
public static boolean hasLength(String s)
-
-