Averages/Median: Difference between revisions

m
Line 2,100:
@FunctionalInterface
interface MedianFinder<T, R> extends Function<Collection<T>, R> {
 
@Override
R apply(Collection<T> data);
}
 
@SuppressWarnings("ClassCanBeRecord")
class MedianFinderImpl<T, R> implements MedianFinder<T, R> {
 
private final Supplier<R> ifEmpty;
private final Function<T, R> ifOdd;
Line 2,142 ⟶ 2,139:
private static final MedianFinder<BigDecimal, BigDecimal> BIG_DECIMALS = new MedianFinderImpl<>(() -> BigDecimal.ZERO, n -> n, pair -> pair.get(0).add(pair.get(1)).divide(BigDecimal.valueOf(2), RoundingMode.FLOOR));
 
public static Integer integers(Collection<Integer> integerCollection) { return INTEGERS.apply(integerCollection); }
return INTEGERS.apply(integerCollection);
}
public static Float integersAsFloat(Collection<Integer> integerCollection) { return INTEGERS_AS_FLOAT.apply(integerCollection); }
public static Double integersAsDouble(Collection<Integer> integerCollection) { return INTEGERS_AS_DOUBLE.apply(integerCollection); }
public static Float floats(Collection<Float> floatCollection) { return FLOATS.apply(floatCollection); }
public static Double doubles(Collection<Double> doubleCollection) { return FLOATSDOUBLES.apply(floatCollectiondoubleCollection); }
}
public static Double doubles(Collection<Double> doubleCollection) {
return DOUBLES.apply(doubleCollection);
}
public static BigInteger bigIntegers(Collection<BigInteger> bigIntegerCollection) { return BIG_INTEGERS.apply(bigIntegerCollection); }
public static BigDecimal bigIntegersAsBigDecimal(Collection<BigInteger> bigIntegerCollection) { return BIG_INTEGERS_AS_BIG_DECIMAL.apply(bigIntegerCollection); }
Anonymous user