Allow EventSample.record to accept numSamples=0

There's really no reason not to.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171037754
This commit is contained in:
guyben 2017-10-04 11:30:33 -07:00 committed by jianglai
parent 6b113603db
commit 0b5b16e97c
2 changed files with 9 additions and 2 deletions

View file

@ -41,7 +41,7 @@ public final class MutableDistribution implements Distribution {
private final DistributionFitter distributionFitter;
private double sumOfSquaredDeviation = 0.0;
private double mean = 0.0;
private int count = 0;
private long count = 0;
/** Constructs an empty Distribution with the specified {@link DistributionFitter}. */
public MutableDistribution(DistributionFitter distributionFitter) {
@ -70,9 +70,15 @@ public final class MutableDistribution implements Distribution {
}
public void add(double value, long numSamples) {
checkArgument(numSamples > 0, "numSamples must be greater than 0");
checkArgument(numSamples >= 0, "numSamples must be non-negative");
checkDouble(value);
// having numSamples = 0 works as expected (does nothing) even if we let it continue, but we
// can short-circuit it by returning early.
if (numSamples == 0) {
return;
}
Map.Entry<Range<Double>, Long> entry = intervalCounts.getEntry(value);
intervalCounts.put(entry.getKey(), entry.getValue() + numSamples);
this.count += numSamples;