SampledSetImpl implements SampledSet<T> { @Override public SampledSet<T> merge(SampledSet<T> sampledSet) { SampledSet<T> mergedSampleSet = this.makeSnapshot(); mergedSampleSet.mergeInPlaceWith(sampledSet); mergedSampleSet.hasChanged(); return mergedSampleSet; } @Deprecated  SampledSetImpl(
      int maxSetSize,
      DigestFunction<T> digestFunction,
      SnapshotableSet<T> baseSet,
      SetFactory<T, SnapshotableSet<T>> setFactory,
      int currentSampleRate);  SampledSetImpl(
      int maxSetSize,
      DigestFunction<T> digestFunction,
      SetFactory<T, SnapshotableSet<T>> setFactory); @Override boolean add(T element); @Override int getMaxSetSize(); @Override int getScaledSize(); @Override int getSampleRate(); @Override int getSize(); @Override Set<T> getEntries(); @Override SampledSetSnapshot<T> sampleAt(int rate); @Override SampledSet<T> merge(SampledSet<T> sampledSet); @Override boolean mergeInPlaceWith(SampledSet<T> sampledSet); @Override boolean hasChanged(); @Override Iterator<T> iterator(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override V[] toArray(V[] a); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); @Override SampledSet<T> makeSnapshot(); @Override SampledSet<T> makeTransientSnapshot(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(groups = "fast") public void testMerge() throws Exception { IntegerHashSetFactory longHashSetFactory = new IntegerHashSetFactory(maxSetSize); SampledSet<Long> otherSet = new SampledSetImpl<>(maxSetSize / 4, new LongMurmur3Hash(), longHashSetFactory); int firstSetSize = maxSetSize / 2; for (int i = 0; i < firstSetSize; i++) { integerSet.add((long) i); } Assert.assertEquals(integerSet.getScaledSize(), firstSetSize); int secondSetSize = maxSetSize / 4; for (int i = 0; i < secondSetSize; i++) { otherSet.add((long) i); } Assert.assertEquals(otherSet.getScaledSize(), secondSetSize); SampledSet<Long> mergeIntoFirst = integerSet.merge(otherSet); SampledSet<Long> mergeIntoSecond = otherSet.merge(integerSet); int maxofMaxSetSize = Math.max(integerSet.getMaxSetSize(), otherSet.getMaxSetSize()); Assert.assertEquals(mergeIntoFirst.getMaxSetSize(), maxofMaxSetSize); Assert.assertTrue(mergeIntoFirst.getSize() < maxofMaxSetSize); Assert.assertEquals(mergeIntoSecond.getMaxSetSize(), secondSetSize); }