@Test public void testSum() { Assert.assertEquals(6L, BluefloodTimerRollup.sum(longs)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(doubles)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(mixed)); Assert.assertEquals(6.0d, BluefloodTimerRollup.sum(alsoMixed)); }
public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; doubleSum += longSum; } doubleSum += number.doubleValue(); } else if (number instanceof Long || number instanceof Integer) longSum += number.longValue(); } if (useDouble) return doubleSum; else return longSum; }
BluefloodTimerRollup implements Rollup, IBaseRollup { public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; doubleSum += longSum; } doubleSum += number.doubleValue(); } else if (number instanceof Long || number instanceof Integer) longSum += number.longValue(); } if (useDouble) return doubleSum; else return longSum; } }
BluefloodTimerRollup implements Rollup, IBaseRollup { public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; doubleSum += longSum; } doubleSum += number.doubleValue(); } else if (number instanceof Long || number instanceof Integer) longSum += number.longValue(); } if (useDouble) return doubleSum; else return longSum; } BluefloodTimerRollup(); }
BluefloodTimerRollup implements Rollup, IBaseRollup { public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; doubleSum += longSum; } doubleSum += number.doubleValue(); } else if (number instanceof Long || number instanceof Integer) longSum += number.longValue(); } if (useDouble) return doubleSum; else return longSum; } BluefloodTimerRollup(); BluefloodTimerRollup withSum(double sum); BluefloodTimerRollup withCount(long count); BluefloodTimerRollup withCountPS(double count_ps); BluefloodTimerRollup withSampleCount(int sampleCount); BluefloodTimerRollup withMinValue(MinValue min); BluefloodTimerRollup withMinValue(Number num); BluefloodTimerRollup withMaxValue(MaxValue max); BluefloodTimerRollup withMaxValue(Number num); BluefloodTimerRollup withAverage(Average average); BluefloodTimerRollup withAverage(Number average); BluefloodTimerRollup withVariance(Variance variance); BluefloodTimerRollup withVariance(Number variance); Average getAverage(); MaxValue getMaxValue(); MinValue getMinValue(); Variance getVariance(); void setPercentile(String label, Number mean); @Override Boolean hasData(); double getRate(); double getSum(); long getCount(); int getSampleCount(); String toString(); @Override RollupType getRollupType(); boolean equals(Object obj); static Number sum(Collection<Number> numbers); static Number avg(Collection<Number> numbers); static Number max(Collection<Number> numbers); static double calculatePerSecond(long countA, double countPerSecA, long countB, double countPerSecB); Map<String, Percentile> getPercentiles(); static BluefloodTimerRollup buildRollupFromTimerRollups(Points<BluefloodTimerRollup> input); }
BluefloodTimerRollup implements Rollup, IBaseRollup { public static Number sum(Collection<Number> numbers) { long longSum = 0; double doubleSum = 0d; boolean useDouble = false; for (Number number : numbers) { if (useDouble || number instanceof Double || number instanceof Float) { if (!useDouble) { useDouble = true; doubleSum += longSum; } doubleSum += number.doubleValue(); } else if (number instanceof Long || number instanceof Integer) longSum += number.longValue(); } if (useDouble) return doubleSum; else return longSum; } BluefloodTimerRollup(); BluefloodTimerRollup withSum(double sum); BluefloodTimerRollup withCount(long count); BluefloodTimerRollup withCountPS(double count_ps); BluefloodTimerRollup withSampleCount(int sampleCount); BluefloodTimerRollup withMinValue(MinValue min); BluefloodTimerRollup withMinValue(Number num); BluefloodTimerRollup withMaxValue(MaxValue max); BluefloodTimerRollup withMaxValue(Number num); BluefloodTimerRollup withAverage(Average average); BluefloodTimerRollup withAverage(Number average); BluefloodTimerRollup withVariance(Variance variance); BluefloodTimerRollup withVariance(Number variance); Average getAverage(); MaxValue getMaxValue(); MinValue getMinValue(); Variance getVariance(); void setPercentile(String label, Number mean); @Override Boolean hasData(); double getRate(); double getSum(); long getCount(); int getSampleCount(); String toString(); @Override RollupType getRollupType(); boolean equals(Object obj); static Number sum(Collection<Number> numbers); static Number avg(Collection<Number> numbers); static Number max(Collection<Number> numbers); static double calculatePerSecond(long countA, double countPerSecA, long countB, double countPerSecB); Map<String, Percentile> getPercentiles(); static BluefloodTimerRollup buildRollupFromTimerRollups(Points<BluefloodTimerRollup> input);  }