ConditionalFrequencyDistribution { public void addSample(C condition, V sample, long frequency) { FrequencyDistribution<V> freqDist = null; if (cfd.containsKey(condition)) { freqDist = cfd.get(condition); } else { freqDist = new FrequencyDistribution<V>(); cfd.put(condition, freqDist); } long countBefore = freqDist.getN(); freqDist.addSample(sample, frequency); this.n = n + (freqDist.getN() - countBefore); } ConditionalFrequencyDistribution();  ConditionalFrequencyDistribution(Map<C, Iterable<V>> samples); long getN(); long getCount(C condition, V sample); FrequencyDistribution<V> getFrequencyDistribution(C condition); void setFrequencyDistribution(C condition, FrequencyDistribution<V> fd); Set<C> getConditions(); boolean hasCondition(C condition); void inc(C condition, V sample); void incAll(C condition, Iterable<V> samples); void addSample(C condition, V sample, long frequency); void removeCondition(C condition); @Override String toString();  }
@Test public void addSampleTest() { ConditionalFrequencyDistribution<String, String> cfd = new ConditionalFrequencyDistribution<String, String>(); cfd.addSample("condition", "key", 10); assertEquals(1, cfd.getConditions().size()); assertEquals(10, cfd.getN()); assertEquals(10, cfd.getCount("condition", "key")); }