@Test public void testGetValueForEvenNumberOfFloatBandValues() { Number[] evenNumberOfFloatBandValues = new Float[]{3.5f, 5.5f, 8.5f, 13.5f}; assertEquals(7F, strategy.getMedian(evenNumberOfFloatBandValues), 0.0001); }
float getMedian(Number[] bandValues) { if (bandValues == null || bandValues.length == 0) { return Float.NaN; } Number[] values = bandValues.clone(); Arrays.sort(values); if (values.length % 2 == 1) { return values[values.length / 2].floatValue(); } final float leftMedian = values[values.length / 2 - 1].floatValue(); final float rightMedian = values[values.length / 2].floatValue(); return (leftMedian + rightMedian) / 2; }
MedianAggregatorStrategy extends AbstractAggregatorStrategy { float getMedian(Number[] bandValues) { if (bandValues == null || bandValues.length == 0) { return Float.NaN; } Number[] values = bandValues.clone(); Arrays.sort(values); if (values.length % 2 == 1) { return values[values.length / 2].floatValue(); } final float leftMedian = values[values.length / 2 - 1].floatValue(); final float rightMedian = values[values.length / 2].floatValue(); return (leftMedian + rightMedian) / 2; } }
MedianAggregatorStrategy extends AbstractAggregatorStrategy { float getMedian(Number[] bandValues) { if (bandValues == null || bandValues.length == 0) { return Float.NaN; } Number[] values = bandValues.clone(); Arrays.sort(values); if (values.length % 2 == 1) { return values[values.length / 2].floatValue(); } final float leftMedian = values[values.length / 2 - 1].floatValue(); final float rightMedian = values[values.length / 2].floatValue(); return (leftMedian + rightMedian) / 2; }  }
MedianAggregatorStrategy extends AbstractAggregatorStrategy { float getMedian(Number[] bandValues) { if (bandValues == null || bandValues.length == 0) { return Float.NaN; } Number[] values = bandValues.clone(); Arrays.sort(values); if (values.length % 2 == 1) { return values[values.length / 2].floatValue(); } final float leftMedian = values[values.length / 2 - 1].floatValue(); final float rightMedian = values[values.length / 2].floatValue(); return (leftMedian + rightMedian) / 2; }  @Override Number[] getValues(Record record, int rasterIndex); @Override String[] getSuffixes(); }
MedianAggregatorStrategy extends AbstractAggregatorStrategy { float getMedian(Number[] bandValues) { if (bandValues == null || bandValues.length == 0) { return Float.NaN; } Number[] values = bandValues.clone(); Arrays.sort(values); if (values.length % 2 == 1) { return values[values.length / 2].floatValue(); } final float leftMedian = values[values.length / 2 - 1].floatValue(); final float rightMedian = values[values.length / 2].floatValue(); return (leftMedian + rightMedian) / 2; }  @Override Number[] getValues(Record record, int rasterIndex); @Override String[] getSuffixes();  }