1 22 23 24 package com.mchange.v1.util; 25 26 import com.mchange.v2.lang.ObjectUtils; 27 28 public final class ArrayUtils 29 { 30 33 public static int hashArray(Object [] oo) 34 { 35 int len = oo.length; 36 int out = len; 37 for (int i = 0; i < len; ++i) 38 { 39 int elem_hash = ObjectUtils.hashOrZero(oo[i]); 43 int rot = i % 32; 44 int rot_hash = elem_hash >>> rot; 45 rot_hash |= elem_hash << (32 - rot); 46 out ^= rot_hash; 47 } 48 return out; 49 } 50 51 54 public static int hashArray(int[] ii) 55 { 56 int len = ii.length; 57 int out = len; 58 for (int i = 0; i < len; ++i) 59 { 60 int elem_hash = ii[i]; 64 int rot = i % 32; 65 int rot_hash = elem_hash >>> rot; 66 rot_hash |= elem_hash << (32 - rot); 67 out ^= rot_hash; 68 } 69 return out; 70 } 71 72 public static int hashOrZeroArray(Object [] oo) 73 { return (oo == null ? 0 : hashArray(oo)); } 74 75 public static int hashOrZeroArray(int[] ii) 76 { return (ii == null ? 0 : hashArray(ii)); } 77 78 public static String stringifyContents(Object [] array) 79 { 80 StringBuffer sb = new StringBuffer (); 81 sb.append("[ "); 82 for (int i = 0, len = array.length; i < len; ++i) 83 { 84 if (i != 0) 85 sb.append(", "); 86 sb.append( array[i].toString() ); 87 } 88 sb.append(" ]"); 89 return sb.toString(); 90 } 91 } 92 93 | Popular Tags |