Class ObjectCmp
- java.lang.Object
-
- io.github.nejckorasa.ObjectCmp
-
public final class ObjectCmp extends Object
Class to compare objects of same or different type
-
-
Constructor Summary
Constructors Constructor Description ObjectCmp()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <B,W>
booleanequals(B base, W working, EqPair<B,W>... eqPair)
Compares base and working objects using equality pairstatic <B,W>
booleanequals(B base, W working, BiFunction<B,W,Boolean> equalsFunction)
Compares base and working objects using equals function equalsFunction.static <O> boolean
equals(O base, O working)
Compares base and working objects using default equals function.static <O> boolean
equals(O base, O working, Function<O,?> equality)
Compares base and working objects using equalitystatic <O> boolean
equals(O base, O working, List<Function<O,?>> equalities)
Compares base and working objects using equalities.
-
-
-
Method Detail
-
equals
public static <O> boolean equals(O base, O working)
Compares base and working objects using default equals function. Same as callingObjects.equals(Object, Object)
Comparison by reference is always performed first, also if one of the objects is
null
, false is returned.- Parameters:
base
- base object to compareworking
- working object to compare- Returns:
- true/false whether objects are equal
-
equals
public static <B,W> boolean equals(B base, W working, BiFunction<B,W,Boolean> equalsFunction)
Compares base and working objects using equals function equalsFunction. Similar as callingObjects.compare(Object, Object, Comparator)
Comparison by reference is always performed first, also if one of the objects is
null
, false is returned.- Parameters:
base
- base object to compareworking
- working object to compareequalsFunction
- equals function to compare objects with- Returns:
- true/false whether objects are equal
-
equals
public static <O> boolean equals(O base, O working, Function<O,?> equality)
Compares base and working objects using equalityComparison by reference is always performed first, also if one of the objects is
null
, false is returned.- Type Parameters:
O
- objects generic type- Parameters:
base
- base object to compareworking
- working object to compareequality
- equality based on which objects are compared- Returns:
- true/false whether objects are equal
- See Also:
equals(Object, Object, List)
-
equals
public static <O> boolean equals(O base, O working, List<Function<O,?>> equalities)
Compares base and working objects using equalities. All equalities must match in order for objects to be considered equal.Equality is a function that takes object as an input parameter and returns a value. Two objects are considered equal if the results of all it's equalities are equal.
You can use this option to compare objects of same type based on a few of their fields.
Comparison by reference is always performed first, also if one of the objects is
null
, false is returned.- Type Parameters:
O
- objects generic type- Parameters:
base
- base object to compareworking
- working object to compareequalities
- equalities based on which objects are compared- Returns:
- true/false whether objects are equal
-
equals
@SafeVarargs public static <B,W> boolean equals(B base, W working, EqPair<B,W>... eqPair)
Compares base and working objects using equality pairComparison by reference is always performed first, also if one of the objects is
null
, false is returned.- Parameters:
base
- base object to compareworking
- working object to compareeqPair
- equality pair based on which objects are compared- Returns:
- true/false whether objects are equal
- See Also:
EqPair
-
-