/** * Calculates the hash code for array of Objects that contains writables. This is used * to work around the buggy Hadoop DoubleWritable hashCode implementation. This should * only be used for process-local hash codes; don't replace stored hash codes like bucketing. */ public static int writableArrayHashCode(Object[] keys) { if (keys == null) return 0; int hashcode = 1; for (Object element : keys) { hashcode = 31 * hashcode; if (element == null) { // nothing } else if (element instanceof LazyDouble) { long v = Double.doubleToLongBits(((LazyDouble) element).getWritableObject().get()); hashcode = hashcode + (int) (v ^ (v >>> 32)); } else if (element instanceof DoubleWritable) { long v = Double.doubleToLongBits(((DoubleWritable) element).get()); hashcode = hashcode + (int) (v ^ (v >>> 32)); } else if (element instanceof Object[]) { // use deep hashcode for arrays hashcode = hashcode + Arrays.deepHashCode((Object[]) element); } else { hashcode = hashcode + element.hashCode(); } } return hashcode; }
throw new RuntimeException("Expected LazyDouble"); double value = ((LazyDouble) primitiveObject).getWritableObject().get(); double expected = ((DoubleWritable) expectedObject).get(); if (value != expected) {
public static double asJavaDouble(@Nullable final Object o) { if (o == null) { throw new IllegalArgumentException(); } if (o instanceof Double) { return ((Double) o).doubleValue(); } if (o instanceof LazyDouble) { DoubleWritable d = ((LazyDouble) o).getWritableObject(); return d.get(); } if (o instanceof DoubleWritable) { return ((DoubleWritable) o).get(); } String s = o.toString(); return Double.parseDouble(s); }
/** * Calculates the hash code for array of Objects that contains writables. This is used * to work around the buggy Hadoop DoubleWritable hashCode implementation. This should * only be used for process-local hash codes; don't replace stored hash codes like bucketing. */ public static int writableArrayHashCode(Object[] keys) { if (keys == null) return 0; int hashcode = 1; for (Object element : keys) { hashcode = 31 * hashcode; if (element == null) { // nothing } else if (element instanceof LazyDouble) { long v = Double.doubleToLongBits(((LazyDouble) element).getWritableObject().get()); hashcode = hashcode + (int) (v ^ (v >>> 32)); } else if (element instanceof DoubleWritable) { long v = Double.doubleToLongBits(((DoubleWritable) element).get()); hashcode = hashcode + (int) (v ^ (v >>> 32)); } else if (element instanceof Object[]) { // use deep hashcode for arrays hashcode = hashcode + Arrays.deepHashCode((Object[]) element); } else { hashcode = hashcode + element.hashCode(); } } return hashcode; }
throw new RuntimeException("Expected LazyDouble"); double value = ((LazyDouble) primitiveObject).getWritableObject().get(); double expected = ((DoubleWritable) expectedObject).get(); if (value != expected) {