Class EqualsHelper

java.lang.Object
net.sf.basedb.util.EqualsHelper

public class EqualsHelper
extends Object
Helper class for implementing equals and hash code calculations in classes.
Since:
2.15
Author:
nicklas
  • Constructor Summary

    Constructors
    Constructor Description
    EqualsHelper()  
  • Method Summary

    Modifier and Type Method Description
    static boolean equals​(Object o1, Object o2)
    Check if two objects are equal according to their equals implementation.
    static int hashCode​(Object o)
    Get the hashcode for an object.
    static <T> int hashCode​(T... objects)
    Hashcode calculation for an array of objects that doesn't depend on the position in the array.
    static boolean invariantEquals​(List<?> l1, List<?> l2)
    Checks if two lists contains equal elements disregarding their positions in the array.
    static <T> boolean invariantEquals​(T[] a1, T[] a2)
    Checks if two arrays contains equal elements disregarding their positions in the array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EqualsHelper

      public EqualsHelper()
  • Method Details

    • equals

      public static boolean equals​(Object o1, Object o2)
      Check if two objects are equal according to their equals implementation. This method is safe to use with null values and returns true if both objects are null. Otherwise, it calls o1.equals(o2).
      Parameters:
      o1 - The first object
      o2 - The second object
      Returns:
      TRUE if the objects are equal
    • hashCode

      public static int hashCode​(Object o)
      Get the hashcode for an object. This method is safe to use with null and returns 0.
      Parameters:
      o - The object to get the hash code for
      Returns:
      The hash code
    • hashCode

      @SafeVarargs public static <T> int hashCode​(T... objects)
      Hashcode calculation for an array of objects that doesn't depend on the position in the array. Null objects are ignored.
      Parameters:
      objects - An array of objects
      Returns:
      The combined hash code for objects in the array
      See Also:
      invariantEquals(Object[], Object[])
    • invariantEquals

      public static <T> boolean invariantEquals​(T[] a1, T[] a2)
      Checks if two arrays contains equal elements disregarding their positions in the array. Eg. [1, 2] is equal to [2, 1]
      Parameters:
      a1 - The first array
      a2 - The second array
      Returns:
      TRUE if both arrays contains the same elements
    • invariantEquals

      public static boolean invariantEquals​(List<?> l1, List<?> l2)
      Checks if two lists contains equal elements disregarding their positions in the array. Eg. [1, 2] is equal to [2, 1]
      Parameters:
      l1 - The first list
      l2 - The second list
      Returns:
      TRUE if both list contains the same elements
      Since:
      3.8