@Test public void requireThatMergingTwoSmallSparseSketchesReturnsSparseSketch() { SparseSketch s1 = SketchUtils.createSparseSketch(1); SparseSketch s2 = SketchUtils.createSparseSketch(2); Sketch<?> result = merger.merge(s1, s2); assertEquals(result.getClass(), SparseSketch.class); assertTrue("Should return the instance given by first argument.", result == s1); SketchUtils.assertSketchContains(result, 1, 2); }
public Sketch<?> merge(Sketch<?> left, Sketch<?> right) { if (left instanceof NormalSketch && right instanceof NormalSketch) { return mergeNormalWithNormal(asNormal(left), asNormal(right)); } else if (left instanceof NormalSketch && right instanceof SparseSketch) { return mergeNormalWithSparse(asNormal(left), asSparse(right)); } else if (left instanceof SparseSketch && right instanceof NormalSketch) { return mergeNormalWithSparse(asNormal(right), asSparse(left)); } else if (left instanceof SparseSketch && right instanceof SparseSketch) { return mergeSparseWithSparse(asSparse(left), asSparse(right)); } else { throw new IllegalArgumentException( String.format("Invalid sketch types: left=%s, right=%s", right.getClass(), left.getClass())); } }
SketchMerger { public Sketch<?> merge(Sketch<?> left, Sketch<?> right) { if (left instanceof NormalSketch && right instanceof NormalSketch) { return mergeNormalWithNormal(asNormal(left), asNormal(right)); } else if (left instanceof NormalSketch && right instanceof SparseSketch) { return mergeNormalWithSparse(asNormal(left), asSparse(right)); } else if (left instanceof SparseSketch && right instanceof NormalSketch) { return mergeNormalWithSparse(asNormal(right), asSparse(left)); } else if (left instanceof SparseSketch && right instanceof SparseSketch) { return mergeSparseWithSparse(asSparse(left), asSparse(right)); } else { throw new IllegalArgumentException( String.format("Invalid sketch types: left=%s, right=%s", right.getClass(), left.getClass())); } } }
SketchMerger { public Sketch<?> merge(Sketch<?> left, Sketch<?> right) { if (left instanceof NormalSketch && right instanceof NormalSketch) { return mergeNormalWithNormal(asNormal(left), asNormal(right)); } else if (left instanceof NormalSketch && right instanceof SparseSketch) { return mergeNormalWithSparse(asNormal(left), asSparse(right)); } else if (left instanceof SparseSketch && right instanceof NormalSketch) { return mergeNormalWithSparse(asNormal(right), asSparse(left)); } else if (left instanceof SparseSketch && right instanceof SparseSketch) { return mergeSparseWithSparse(asSparse(left), asSparse(right)); } else { throw new IllegalArgumentException( String.format("Invalid sketch types: left=%s, right=%s", right.getClass(), left.getClass())); } }  }
SketchMerger { public Sketch<?> merge(Sketch<?> left, Sketch<?> right) { if (left instanceof NormalSketch && right instanceof NormalSketch) { return mergeNormalWithNormal(asNormal(left), asNormal(right)); } else if (left instanceof NormalSketch && right instanceof SparseSketch) { return mergeNormalWithSparse(asNormal(left), asSparse(right)); } else if (left instanceof SparseSketch && right instanceof NormalSketch) { return mergeNormalWithSparse(asNormal(right), asSparse(left)); } else if (left instanceof SparseSketch && right instanceof SparseSketch) { return mergeSparseWithSparse(asSparse(left), asSparse(right)); } else { throw new IllegalArgumentException( String.format("Invalid sketch types: left=%s, right=%s", right.getClass(), left.getClass())); } }  Sketch<?> merge(Sketch<?> left, Sketch<?> right); }
SketchMerger { public Sketch<?> merge(Sketch<?> left, Sketch<?> right) { if (left instanceof NormalSketch && right instanceof NormalSketch) { return mergeNormalWithNormal(asNormal(left), asNormal(right)); } else if (left instanceof NormalSketch && right instanceof SparseSketch) { return mergeNormalWithSparse(asNormal(left), asSparse(right)); } else if (left instanceof SparseSketch && right instanceof NormalSketch) { return mergeNormalWithSparse(asNormal(right), asSparse(left)); } else if (left instanceof SparseSketch && right instanceof SparseSketch) { return mergeSparseWithSparse(asSparse(left), asSparse(right)); } else { throw new IllegalArgumentException( String.format("Invalid sketch types: left=%s, right=%s", right.getClass(), left.getClass())); } }  Sketch<?> merge(Sketch<?> left, Sketch<?> right);  }