Class HashCodes


  • public class HashCodes
    extends java.lang.Object
    Static methods useful for implementing hashCode() methods.

    For example:

    
     public class Foo {
        @NonNull private String a;
        @Nullable private String b;
         private boolean c;
         private int d;
    
        @Override
         public int hashCode() {
             return HashCodes.mix(a.hashCode(), Objects.hashCode(b), Boolean.hashCode(c), d);
         }
     }
     
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int mix​(int hashCode1, int hashCode2)
      Combines two hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3)
      Combines three hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4)
      Combines four hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5)
      Combines five hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5, int hashCode6)
      Combines six hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5, int hashCode6, int hashCode7)
      Combines seven hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5, int hashCode6, int hashCode7, int hashCode8)
      Combines eight hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5, int hashCode6, int hashCode7, int hashCode8, int hashCode9)
      Combines nine hash codes into one.
      static int mix​(int hashCode1, int hashCode2, int hashCode3, int hashCode4, int hashCode5, int hashCode6, int hashCode7, int hashCode8, int hashCode9, int hashCode10)
      Combines ten hash codes into one.
      • Methods inherited from class java.lang.Object

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

      • mix

        public static int mix​(int hashCode1,
                              int hashCode2)
        Combines two hash codes into one. Can be used for computing the hash code of an object containing two fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3)
        Combines three hash codes into one. Can be used for computing the hash code of an object containing three fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4)
        Combines four hash codes into one. Can be used for computing the hash code of an object containing four fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5)
        Combines five hash codes into one. Can be used for computing the hash code of an object containing five fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5,
                              int hashCode6)
        Combines six hash codes into one. Can be used for computing the hash code of an object containing six fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5,
                              int hashCode6,
                              int hashCode7)
        Combines seven hash codes into one. Can be used for computing the hash code of an object containing seven fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5,
                              int hashCode6,
                              int hashCode7,
                              int hashCode8)
        Combines eight hash codes into one. Can be used for computing the hash code of an object containing eight fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5,
                              int hashCode6,
                              int hashCode7,
                              int hashCode8,
                              int hashCode9)
        Combines nine hash codes into one. Can be used for computing the hash code of an object containing nine fields.
      • mix

        public static int mix​(int hashCode1,
                              int hashCode2,
                              int hashCode3,
                              int hashCode4,
                              int hashCode5,
                              int hashCode6,
                              int hashCode7,
                              int hashCode8,
                              int hashCode9,
                              int hashCode10)
        Combines ten hash codes into one. Can be used for computing the hash code of an object containing ten fields.