private Optional<MetricValue> apply_(MetricValue x) { return x.value() .map(this::apply_1_) .map(MetricValue::fromNumberValue); }
@Override protected Optional<Number> map_(MetricValue x) { final Optional<Number> hist_min = x.histogram().flatMap(Histogram::max).map(dbl -> dbl); if (hist_min.isPresent()) return hist_min; return x.value(); } @Override
private static Optional<Any2<Double, Histogram>> extract_(MetricValue mv) { final Optional<Histogram> hist = mv.histogram(); if (hist.isPresent()) return hist.map(Any2::right); return mv.value().map(Number::doubleValue).map(Any2::left); }
@Override protected Optional<Number> map_(MetricValue x) { final Optional<Number> hist_min = x.histogram().flatMap(Histogram::min).map(dbl -> dbl); if (hist_min.isPresent()) return hist_min; return x.value(); } @Override
private static Optional<Any2<? extends Number, Histogram>> extract_(MetricValue mv) { Optional<Any2<? extends Number, Histogram>> hist = mv.histogram().map(Any2::right); if (hist.isPresent()) return hist; return mv.value().map(Any2::left); }
@Override protected Optional<Number> map_(MetricValue x) { if (!x.isPresent()) return Optional.of(0L); final Optional<Number> hist_count = x.histogram().map(Histogram::sum); return hist_count.isPresent() ? hist_count : x.value(); } @Override
@Override protected AvgAgg map_(MetricValue x) { final Optional<AvgAgg> hist_params = x.histogram().map(h -> new AvgAgg(h.sum(), h.getEventCount())); if (hist_params.isPresent()) return hist_params.get(); return x.value() .map(Number::doubleValue) .map(x_number -> new AvgAgg(x_number, 1)) .orElseGet(() -> new AvgAgg(0, 0)); } @Override
private MetricValue interpolate(MetricValue a, MetricValue b) { if ((a.getBoolValue() != null || a.getIntValue() != null || a.getFltValue() != null) && (b.getBoolValue() != null || b.getIntValue() != null || b.getFltValue() != null)) return MetricValue.fromDblValue(backWeight * a.value().get().doubleValue() + forwWeight * b.value().get().doubleValue()); if (a.getStrValue() != null && b.getStrValue() != null) return a; if (a.getHistValue() != null && b.getHistValue() != null) { return MetricValue.fromHistValue(Histogram.add( Histogram.multiply(a.getHistValue(), backWeight), Histogram.multiply(b.getHistValue(), forwWeight))); } // Mismatched types, return empty metric value. return MetricValue.EMPTY; } }
value = mv.value().orElse(null); else if (mv.getBoolValue() != null) value = mv.getBoolValue();