public int partialHashCode ( ITuple tuple , int [ ] fields ) { int result = 0 ; for ( int field : fields ) { Object o = tuple . get ( field ) ; if ( o == null ) { // nulls don't account for hashcode continue ; } int hashCode ; if ( o instanceof String ) { // since String.hashCode() != Utf8.hashCode() HELPER_UTF8 . set ( ( String ) o ) ; hashCode = HELPER_UTF8 . hashCode ( ) ; } else if ( o instanceof Text ) { HELPER_UTF8 . set ( ( Text ) o ) ; hashCode = HELPER_UTF8 . hashCode ( ) ; } else if ( o instanceof byte [ ] ) { hashCode = hashBytes ( ( byte [ ] ) o , 0 , ( ( byte [ ] ) o ) . length ) ; } else if ( o instanceof ByteBuffer ) { ByteBuffer buffer = ( ByteBuffer ) o ; int offset = buffer . arrayOffset ( ) + buffer . position ( ) ; int length = buffer . limit ( ) - buffer . position ( ) ; hashCode = hashBytes ( buffer . array ( ) , offset , length ) ; } else { hashCode = o . hashCode ( ) ; } result = result * 31 + hashCode ; } return result ; }
Calculates a combinated hashCode using the specified number of fields .