Class ObjectUtils
java.lang.Object
com.thanlinardos.spring_enterprise_library.objects.utils.ObjectUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B, C> Optional <C> applyIfBothNotNull(A a, B b, BiFunction<A, B, C> merger) static booleanevaluateAllTrue(Supplier<Boolean>... suppliers) Evaluates all the suppliers if needed and if all returns true then it returns true.static booleanevaluateAnyTrue(Supplier<Boolean>... suppliers) Evaluates any of the suppliers if needed and if any of them is true, returns true.static <T extends BasicIdJpa>
StringgetCommaSeparatedListOfIds(Collection<T> entities) Returns a concatenated comma separated list of ids from the entities.static <T> StringgetDebugString(Collection<T> entities) Returns useful debugging information like class, id, and toString representation.static <T> StringgetDebugString(T entity) Returns useful debugging information like class, id, and toString representation.static <T> Optional<T> getFirstNonNull(Supplier<T>... suppliers) Returns the first non-null element found by evaluating the suppliers.static <T> Optional<T> getFirstPresent(Supplier<Optional<T>>... suppliers) Returns the first present optional element found by evaluating the suppliers.static LonggetIdOrNull(BasicIdJpa entity) Returns the id of the entity, otherwise null.static <T extends BasicIdJpa>
Set<Long> getIds(Collection<T> entities) Returns a set of ids of the entitiesstatic <T,R> R Returns the value extracted by the getter from the object if the object is not null, otherwise returns null.static booleanisAllObjectsEquals(Object object, Object... objects) Returns true if all the objects supplied are equal.static booleanisAllObjectsNotNull(Object object, Object... objects) Returns true if all the objects supplied are not null.static booleanisAllObjectsNotNullAndEquals(Object object, Object... objects) Returns true if all the objects supplied are not null and are all equal.static booleanisAllObjectsNull(Object object, Object... objects) Returns true if all the objects supplied are null.static booleanisAnyObjectNotNull(Object object, Object... objects) Returns true if any of the objects supplied are not null.static booleanisAnyObjectNull(Object object, Object... objects) Returns true if any of the objects supplied are null.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
isAnyObjectNull
-
isAnyObjectNotNull
-
isAllObjectsNull
-
isAllObjectsNotNull
-
isAllObjectsEquals
-
isAllObjectsNotNullAndEquals
Returns true if all the objects supplied are not null and are all equal.- Parameters:
object- the first object to check for null and equals.objects- the objects to check for null and equals.- Returns:
- true if all the objects supplied are not null and are all equal.
-
evaluateAllTrue
Evaluates all the suppliers if needed and if all returns true then it returns true. It uses noneMatch which is a short-circuiting operation to skip evaluating the rest if one is false.- Parameters:
suppliers- the suppliers to evaluate- Returns:
- true if all suppliers evaluates to true, otherwise false.
-
evaluateAnyTrue
Evaluates any of the suppliers if needed and if any of them is true, returns true. It uses anyMatch which is a short-circuiting operation to skip evaluating the rest if one is true.- Parameters:
suppliers- the suppliers to evaluate- Returns:
- true if any suppliers evaluates to true, otherwise false.
-
getFirstNonNull
Returns the first non-null element found by evaluating the suppliers. It uses findFirst which is a short-circuiting operation to only evaluate enough suppliers to get the first non-null.- Type Parameters:
T- the type class of the elements.- Parameters:
suppliers- the suppliers to possibly evaluate- Returns:
- first non-null element found as an optional, otherwise empty optional.
-
getFirstPresent
Returns the first present optional element found by evaluating the suppliers. It uses findFirst which is a short-circuiting operation to only evaluate enough suppliers to get the first present.- Type Parameters:
T- the type class of the elements.- Parameters:
suppliers- the suppliers to possibly evaluate.- Returns:
- The first present element found, otherwise empty optional.
-
getOrNull
Returns the value extracted by the getter from the object if the object is not null, otherwise returns null.- Type Parameters:
T- the type class of the given objectR- the type class of the extracted value- Parameters:
object- The objectgetter- The getter- Returns:
- the value extracted by the getter from the object if the object is not null, otherwise null.
-
getIdOrNull
Returns the id of the entity, otherwise null.- Parameters:
entity- the entity.- Returns:
- the id of the entity, otherwise null.
-
getCommaSeparatedListOfIds
Returns a concatenated comma separated list of ids from the entities.- Type Parameters:
T- the type class of the given entities.- Parameters:
entities- the entities.- Returns:
- a concatenated comma separated list of ids from the entities.
-
getIds
Returns a set of ids of the entities- Type Parameters:
T- the type class of the given entities.- Parameters:
entities- the entities- Returns:
- a set of ids of the entities
-
getDebugString
Returns useful debugging information like class, id, and toString representation.- Type Parameters:
T- type of the entities- Parameters:
entities- the entities- Returns:
- a string describing the entities
-
getDebugString
Returns useful debugging information like class, id, and toString representation.- Type Parameters:
T- type of the entity- Parameters:
entity- the entity- Returns:
- a string describing the entity
-
applyIfBothNotNull
public static <A,B, Optional<C> applyIfBothNotNullC> (@Nullable A a, @Nullable B b, BiFunction<A, B, C> merger) Apply the given mergerBiFunctionon two given parameters, if both parametersaandbare not null. Returns the result of the merger wrapped in an Optional, otherwise it will returnOptional.empty(). If the merger returns an Optional as well, then apply:.flatMap(Function.identity())
to the result of this method.- Type Parameters:
A- the type of the first parameter.B- the type of the second parameter.C- the result type.- Parameters:
a- first parameterb- second parametermerger- a method that takes two objects with typesAandB, and returns a result with typeC- Returns:
- an optional containing the result of the merger method if both input parameters are not null, otherwise
Optional.empty().
-