Package de.aristaflow.adept2.util
Class ObjectTools
- java.lang.Object
-
- de.aristaflow.adept2.util.ObjectTools
-
-
Constructor Summary
Constructors Constructor Description ObjectTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Comparable<? super T>>
intcompareToNullSafe(T o1, T o2)
Compares the designated objects checking fornull
before applyingComparable.compareTo(Object)
.static <T> int
compareToNullSafe(T o1, T o2, Comparator<? super T> comp)
Compares the designated objects using the designated comparator.static <S,T>
TtransformNullRepl(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)
Handlesnull
before calling the designated transformating function.static <S,T>
TtransformNullSafe(S s, Function<S,T> transformator)
Transforms the designated object using the designated transformator.
-
-
-
Method Detail
-
compareToNullSafe
public static <T> int compareToNullSafe(T o1, T o2, Comparator<? super T> comp)
Compares the designated objects using the designated comparator. If one of the elements isnull
, it will be treated as lesser. Both elements beingnull
will 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
public static <T extends Comparable<? super T>> int compareToNullSafe(T o1, T o2)
Compares the designated objects checking fornull
before applyingComparable.compareTo(Object)
. If one of the elements isnull
, it will be treated as lesser. Both elements beingnull
will 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
public static <S,T> Function<S,T> transformNullSafe(Function<S,T> transformator)
Handlesnull
before calling the designated transformating function. If the provided value isnull
,null
will be returned without calling the designated function.- Parameters:
transformator
- The transformator which to apply which does not handlenull
yet or not properly.This must not benull
.- Returns:
- The transformed object instance or
null
.
-
transformNullSafe
public static <S,T> T transformNullSafe(S s, Function<S,T> transformator)
Transforms the designated object using the designated transformator. If the object isnull
,null
will 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
,null
will be used as replacing value.- Returns:
- The transformed object instance or
null
.
-
-