protected final <N extends Metrics> N createSubMetrics( Function<M, ? extends N> supplier, Function<List<? extends N>, ? extends N> dispatchingMetricsSupplier) { List<N> allSubMetrics = new ArrayList<>(delegates.size()); for (M delegate : delegates) { N subMetrics = supplier.apply(delegate); if (subMetrics != null) { allSubMetrics.add(subMetrics); } } if (allSubMetrics.isEmpty()) { return null; } else if (allSubMetrics.size() == 1) { return allSubMetrics.get(0); } else { return dispatchingMetricsSupplier.apply(allSubMetrics); } }
public static AbstractMetrics unwrap(Measured measured) { MetricsProvider provider = (MetricsProvider) measured; Metrics baseMetrics = provider.getMetrics(); if (baseMetrics instanceof AbstractMetrics) { return (AbstractMetrics) baseMetrics; } return null; }