Class 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>
      boolean
      equals​(B base, W working, EqPair<B,​W>... eqPair)
      Compares base and working objects using equality pair
      static <B,​W>
      boolean
      equals​(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 equality
      static <O> boolean equals​(O base, O working, List<Function<O,​?>> equalities)
      Compares base and working objects using equalities.
    • Constructor Detail

      • ObjectCmp

        public ObjectCmp()
    • Method Detail

      • equals

        public static <O> boolean equals​(O base,
                                         O working)
        Compares base and working objects using default equals function. Same as calling Objects.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 compare
        working - 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 calling Objects.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 compare
        working - working object to compare
        equalsFunction - 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 equality

        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 compare
        working - working object to compare
        equality - 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 compare
        working - working object to compare
        equalities - 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 pair

        Comparison by reference is always performed first, also if one of the objects is null, false is returned.

        Parameters:
        base - base object to compare
        working - working object to compare
        eqPair - equality pair based on which objects are compared
        Returns:
        true/false whether objects are equal
        See Also:
        EqPair