Multiplies each data point in the series by the scale factor, maintaining integers if both the data point and scale are integers. @param points The data points to factor @param scale_factor The factor to multiply by @return The resulting data points
(final DataPoints points, final double scale_factor)
| 79 | * @return The resulting data points |
| 80 | */ |
| 81 | private DataPoints scale(final DataPoints points, final double scale_factor) { |
| 82 | // TODO(cl) - Using an array as the size function may not return the exact |
| 83 | // results and we should figure a way to avoid copying data anyway. |
| 84 | final List<DataPoint> dps = new ArrayList<DataPoint>(); |
| 85 | final boolean scale_is_int = (scale_factor == Math.floor(scale_factor)) && |
| 86 | !Double.isInfinite(scale_factor); |
| 87 | final SeekableView view = points.iterator(); |
| 88 | while (view.hasNext()) { |
| 89 | DataPoint pt = view.next(); |
| 90 | if (pt.isInteger() && scale_is_int) { |
| 91 | dps.add(MutableDataPoint.ofLongValue(pt.timestamp(), |
| 92 | (long)scale_factor * pt.longValue())); |
| 93 | } else { |
| 94 | // NaNs are fine here, they'll just be re-computed as NaN |
| 95 | dps.add(MutableDataPoint.ofDoubleValue(pt.timestamp(), |
| 96 | scale_factor * pt.toDouble())); |
| 97 | } |
| 98 | } |
| 99 | final DataPoint[] results = new DataPoint[dps.size()]; |
| 100 | dps.toArray(results); |
| 101 | return new PostAggregatedDataPoints(points, results); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public String writeStringField(final List<String> query_params, |
no test coverage detected