Frequency implements Serializable { public void merge(final Frequency other) throws NullArgumentException { MathUtils.checkNotNull(other, LocalizedFormats.NULL_NOT_ALLOWED); final Iterator<Map.Entry<Comparable<?>, Long>> iter = other.entrySetIterator(); while (iter.hasNext()) { final Map.Entry<Comparable<?>, Long> entry = iter.next(); incrementValue(entry.getKey(), entry.getValue().longValue()); } } Frequency(); @SuppressWarnings("unchecked") // TODO is the cast OK?  Frequency(Comparator<?> comparator); @Override String toString(); void addValue(Comparable<?> v); void addValue(int v); void addValue(long v); void addValue(char v); void incrementValue(Comparable<?> v, long increment); void incrementValue(int v, long increment); void incrementValue(long v, long increment); void incrementValue(char v, long increment); void clear(); Iterator<Comparable<?>> valuesIterator(); Iterator<Map.Entry<Comparable<?>, Long>> entrySetIterator(); long getSumFreq(); long getCount(Comparable<?> v); long getCount(int v); long getCount(long v); long getCount(char v); int getUniqueCount(); double getPct(Comparable<?> v); double getPct(int v); double getPct(long v); double getPct(char v); @SuppressWarnings({ "rawtypes", "unchecked" }) long getCumFreq(Comparable<?> v); long getCumFreq(int v); long getCumFreq(long v); long getCumFreq(char v); double getCumPct(Comparable<?> v); double getCumPct(int v); double getCumPct(long v); double getCumPct(char v); List<Comparable<?>> getMode(); void merge(final Frequency other); void merge(final Collection<Frequency> others); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test public void testMerge() { Assert.assertEquals(0, f.getUniqueCount()); f.addValue(ONE_LONG); f.addValue(TWO_LONG); f.addValue(ONE); f.addValue(TWO); Assert.assertEquals(2, f.getUniqueCount()); Assert.assertEquals(2, f.getCount(ONE)); Assert.assertEquals(2, f.getCount(TWO)); Frequency g = new Frequency(); g.addValue(ONE_LONG); g.addValue(THREE_LONG); g.addValue(THREE); Assert.assertEquals(2, g.getUniqueCount()); Assert.assertEquals(1, g.getCount(ONE)); Assert.assertEquals(2, g.getCount(THREE)); f.merge(g); Assert.assertEquals(3, f.getUniqueCount()); Assert.assertEquals(3, f.getCount(ONE)); Assert.assertEquals(2, f.getCount(TWO)); Assert.assertEquals(2, f.getCount(THREE)); }