Package de.aristaflow.adept2.util
Class ObjectTools
java.lang.Object
de.aristaflow.adept2.util.ObjectTools
Tool methods for objects, similar to
Objects.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
intcompareToNullSafe(T o1, T o2) Compares the designated objects checking fornullbefore applyingComparable.compareTo(Object).static <T> intcompareToNullSafe(T o1, T o2, Comparator<? super T> comp) Compares the designated objects using the designated comparator.static <S,T> T transformNullRepl(S s, Function<S, T> transformator, Supplier<T> nullSupplier) Transforms the designated object using the designated transformator.static <S,T> Function<S, T> transformNullSafe(Function<S, T> transformator) Handlesnullbefore calling the designated transformating function.static <S,T> T transformNullSafe(S s, Function<S, T> transformator) Transforms the designated object using the designated transformator.
-
Constructor Details
-
ObjectTools
public ObjectTools()
-
-
Method Details
-
compareToNullSafe
Compares the designated objects using the designated comparator. If one of the elements isnull, it will be treated as lesser. Both elements beingnullwill be treated as equal objects.- Parameters:
o1- The first object to be compared.o2- The second object to be compared.comp- The comparator for the objects.- Returns:
- The comparison result of the two objects.
-
compareToNullSafe
Compares the designated objects checking fornullbefore applyingComparable.compareTo(Object). If one of the elements isnull, it will be treated as lesser. Both elements beingnullwill be treated as equal objects.- Parameters:
o1- The first object to be compared.o2- The second object to be compared.- Returns:
- The comparison result of the two objects.
-
transformNullSafe
Handlesnullbefore calling the designated transformating function. If the provided value isnull,nullwill be returned without calling the designated function.- Parameters:
transformator- The transformator which to apply which does not handlenullyet or not properly.This must not benull.- Returns:
- The transformed object instance or
null.
-
transformNullSafe
Transforms the designated object using the designated transformator. If the object isnull,nullwill be returned without transforming anything.- Parameters:
s- The object which to transform ornull.transformator- The transformator which to apply. This must not benull.- Returns:
- The transformed object instance or
null.
-
transformNullRepl
public static <S,T> T transformNullRepl(S s, Function<S, T> transformator, Supplier<T> nullSupplier) Transforms the designated object using the designated transformator. If the object isnull, the designated supplier will be called.- Parameters:
s- The object which to transform ornull.transformator- The transformator which to apply. This must not benull.nullSupplier- The supplier providing the object to be used fornull. If this isnull,nullwill be used as replacing value.- Returns:
- The transformed object instance or
null.
-