From 2b31689d9a8ea27e5c9204ca034a84d5d776dece Mon Sep 17 00:00:00 2001 From: Yang Song Date: Mon, 20 Aug 2018 16:34:51 -0700 Subject: Make an internal function static. (#1375) * Make an internal function static. * Make other functions static too. --- .../io/opencensus/implcore/stats/MetricUtils.java | 55 +++++++++++++++------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'impl_core') diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/MetricUtils.java b/impl_core/src/main/java/io/opencensus/implcore/stats/MetricUtils.java index b706b0da..cd1e5364 100644 --- a/impl_core/src/main/java/io/opencensus/implcore/stats/MetricUtils.java +++ b/impl_core/src/main/java/io/opencensus/implcore/stats/MetricUtils.java @@ -64,25 +64,17 @@ final class MetricUtils { return aggregation.match( Functions.returnConstant( measure.match( - Functions.returnConstant(Type.CUMULATIVE_DOUBLE), // Sum Double - Functions.returnConstant(Type.CUMULATIVE_INT64), // Sum Int64 - Functions.throwAssertionError())), - Functions.returnConstant(Type.CUMULATIVE_INT64), // Count - Functions.returnConstant(Type.CUMULATIVE_DISTRIBUTION), // Distribution + TYPE_CUMULATIVE_DOUBLE_FUNCTION, // Sum Double + TYPE_CUMULATIVE_INT64_FUNCTION, // Sum Int64 + TYPE_UNRECOGNIZED_FUNCTION)), + TYPE_CUMULATIVE_INT64_FUNCTION, // Count + TYPE_CUMULATIVE_DISTRIBUTION_FUNCTION, // Distribution Functions.returnConstant( measure.match( - Functions.returnConstant(Type.GAUGE_DOUBLE), // LastValue Double - Functions.returnConstant(Type.GAUGE_INT64), // LastValue Long - Functions.throwAssertionError())), - new Function() { - @Override - public Type apply(Aggregation arg) { - if (arg instanceof Aggregation.Mean) { - return Type.CUMULATIVE_DOUBLE; // Mean - } - throw new AssertionError(); - } - }); + TYPE_GAUGE_DOUBLE_FUNCTION, // LastValue Double + TYPE_GAUGE_INT64_FUNCTION, // LastValue Long + TYPE_UNRECOGNIZED_FUNCTION)), + AGGREGATION_TYPE_DEFAULT_FUNCTION); } static List tagValuesToLabelValues(List tagValues) { @@ -93,5 +85,34 @@ final class MetricUtils { return labelValues; } + private static final Function TYPE_CUMULATIVE_DOUBLE_FUNCTION = + Functions.returnConstant(Type.CUMULATIVE_DOUBLE); + + private static final Function TYPE_CUMULATIVE_INT64_FUNCTION = + Functions.returnConstant(Type.CUMULATIVE_INT64); + + private static final Function TYPE_CUMULATIVE_DISTRIBUTION_FUNCTION = + Functions.returnConstant(Type.CUMULATIVE_DISTRIBUTION); + + private static final Function TYPE_GAUGE_DOUBLE_FUNCTION = + Functions.returnConstant(Type.GAUGE_DOUBLE); + + private static final Function TYPE_GAUGE_INT64_FUNCTION = + Functions.returnConstant(Type.GAUGE_INT64); + + private static final Function TYPE_UNRECOGNIZED_FUNCTION = + Functions.throwAssertionError(); + + private static final Function AGGREGATION_TYPE_DEFAULT_FUNCTION = + new Function() { + @Override + public Type apply(Aggregation arg) { + if (arg instanceof Aggregation.Mean) { + return Type.CUMULATIVE_DOUBLE; // Mean + } + throw new AssertionError(); + } + }; + private MetricUtils() {} } -- cgit v1.2.3