Class HashUtil


  • public class HashUtil
    extends java.lang.Object
    This class provides some hashCode calculation utilities. Use the static methods of this class to generate
     hashCode()
     
    values in data objects. For example, to calculate the hashCode of a data object, use the methods of this class as follows:
     int myIntField;
     Object myObject;
     
     public int hashCode()
     {
            //        int hash = super.hashCode();    // use when not extending Object
            int hash = 0; // use when extending Object
            hash = HashUtil.hashCode(hash, myIntField);
            hash = HashUtil.hashCode(hash, myObject);
            return hash;
     }
     

    Hint: Start your hashCode calculation depending on the object your data object extends. If you extend Object initialize your hash value to 0. Otherwise initialize hash to super.hashCode(). See the example code.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int PRIME  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int hashCode​(int source, boolean x)  
      static int hashCode​(int source, double x)  
      static int hashCode​(int source, float x)  
      static int hashCode​(int source, int x)  
      static int hashCode​(int source, long x)  
      static int hashCode​(int source, java.lang.Object x)  
      static int hashCode​(int source, java.lang.Object[] x)  
      static int hashCode​(int source, java.util.Collection<?> c)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • hashCode

        public static final int hashCode​(int source,
                                         boolean x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         int x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         long x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         float x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         double x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         java.lang.Object x)
        Parameters:
        source -
        x -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         java.util.Collection<?> c)
        Parameters:
        source -
        c -
        Returns:
      • hashCode

        public static final int hashCode​(int source,
                                         java.lang.Object[] x)
        Parameters:
        source -
        x -
        Returns: