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); }
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 Number map_(MetricValue x) { final Optional<Number> hist_count = x.histogram().map(Histogram::getEventCount); return hist_count.orElse(x.isPresent() ? 1L : 0L); } @Override
@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
public Entry(@NonNull String tagName, @NonNull MetricValue tagValue) { if (tagName.isEmpty()) throw new IllegalArgumentException("tag with empty name"); if (!tagValue.isPresent()) throw new IllegalArgumentException("tag with absent metric value"); if (tagValue.histogram().isPresent()) throw new IllegalArgumentException("tag with histogram makes no sense"); this.tagName = tagName; this.tagValue = tagValue; } }
@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
public Entry(@NonNull String tagName, @NonNull MetricValue tagValue) { if (tagName.isEmpty()) throw new IllegalArgumentException("tag with empty name"); if (!tagValue.isPresent()) throw new IllegalArgumentException("tag with absent metric value"); if (tagValue.histogram().isPresent()) throw new IllegalArgumentException("tag with histogram makes no sense"); this.tagName = tagName; this.tagValue = tagValue; } }
@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
}) .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty)) .filter(entry -> !entry.getValue().histogram().isPresent()) // Skip any histograms. .collect(Collectors.toList()); LOG.log(Level.FINER, "scalars = {0}", scalars); .orElseGet(Collections::<Tags, MetricValue>emptyMap) .entrySet().stream() .filter(entry -> !entry.getValue().histogram().isPresent()) // Skip any histograms. .map(tagged_value -> SimpleMapEntry.create(tagged_value.getKey(), SimpleMapEntry.create(value.getKey(), tagged_value.getValue()))); })