public static String internalReducer ( Metric metric , String reducerType ) { Map < Long , Double > sortedDatapoints = new TreeMap <> ( ) ; List < Double > operands = new ArrayList < Double > ( ) ; if ( ! reducerType . equals ( InternalReducerType . NAME . getName ( ) ) ) { if ( metric . getDatapoints ( ) != null && metric . getDatapoints ( ) . size ( ) > 0 ) { sortedDatapoints . putAll ( metric . getDatapoints ( ) ) ; for ( Double value : sortedDatapoints . values ( ) ) { if ( value == null ) { operands . add ( 0.0 ) ; } else { operands . add ( value ) ; } } } else { return null ; } } InternalReducerType type = InternalReducerType . fromString ( reducerType ) ; switch ( type ) { case AVG : return String . valueOf ( ( new Mean ( ) ) . evaluate ( Doubles . toArray ( operands ) ) ) ; case MIN : return String . valueOf ( Collections . min ( operands ) ) ; case MAX : return String . valueOf ( Collections . max ( operands ) ) ; case RECENT : return String . valueOf ( operands . get ( operands . size ( ) - 1 ) ) ; case MAXIMA : return String . valueOf ( Collections . max ( operands ) ) ; case MINIMA : return String . valueOf ( Collections . min ( operands ) ) ; case NAME : return metric . getMetric ( ) ; case DEVIATION : return String . valueOf ( ( new StandardDeviation ( ) ) . evaluate ( Doubles . toArray ( operands ) ) ) ; default : throw new UnsupportedOperationException ( reducerType ) ; } }
Reduces the give metric to a single value based on the specified reducer .