/** * Construct a metric value from a Number implementation. * @param number A floating point or integral type. * @return a MetricValue holding the specified number. * @throws IllegalArgumentException if the derived type of Number is not recognized. */ public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } }
/** * Construct a metric value from a Number implementation. * @param number A floating point or integral type. * @return a MetricValue holding the specified number. * @throws IllegalArgumentException if the derived type of Number is not recognized. */ public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } }
result = MetricValue.fromDblValue(right_fraction * left_value + left_fraction * right_value); } else if (left < collected.size()) { result = MetricValue.fromDblValue(collected.get(left)); } else { result = MetricValue.EMPTY;
private static MetricValue strAsMetricValue(String str) { // Try to coerce elem to a boolean. if ("true".equals(str)) return MetricValue.TRUE; if ("false".equals(str)) return MetricValue.FALSE; // Try to coerce elem to an integral number. try { return MetricValue.fromIntValue(Long.parseLong(str)); } catch (NumberFormatException e) { // Ignore. } // Try to coerce elem to a floating point number. try { return MetricValue.fromDblValue(Double.parseDouble(str)); } catch (NumberFormatException e) { // Ignore. } // Give up and just yield a string. return MetricValue.fromStrValue(str); }
@Override protected MetricValue unmap_(AvgAgg v) { if (v.getCount() == 0) return MetricValue.EMPTY; return MetricValue.fromDblValue(v.getSum() / v.getCount()); } @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; } }
((Metric_constantContext)_localctx).s = MetricValue.fromDblValue(((Metric_constantContext)_localctx).s1_dbl.s);