NormalSketch extends Sketch<NormalSketch> { @Override public void merge(NormalSketch other) { Preconditions.checkArgument(data.length == other.data.length, "Trying to merge sketch with one of different size. Expected %s, actual %s", data.length, other.data.length); for (int i = 0; i < data.length; i++) { data[i] = (byte) Math.max(data[i], other.data[i]); } } NormalSketch();  NormalSketch(int precision); @Override void merge(NormalSketch other); @Override void aggregate(Iterable<Integer> hashValues); @Override void aggregate(int hash); byte[] data(); int size(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final int classId; }
@Test public void requireThatMergeDoesElementWiseMax() { NormalSketch s1 = new NormalSketch(2); setSketchValues(s1, 0, 1, 1, 3); NormalSketch s2 = new NormalSketch(2); setSketchValues(s2, 2, 1, 1, 0); s1.merge(s2); assertBucketEquals(s1, 0, 2); assertBucketEquals(s1, 1, 1); assertBucketEquals(s1, 2, 1); assertBucketEquals(s1, 3, 3); }
@Test(expected = IllegalArgumentException.class) public void requireThatMergingFailsForSketchesOfDifferentSize() { NormalSketch s1 = new NormalSketch(2); NormalSketch s2 = new NormalSketch(3); s1.merge(s2); }