simplify ToDouble(Object) to do only one thing

This commit is contained in:
Jonathan Shook 2023-06-06 14:30:13 -05:00
parent 41ebd93530
commit 422b513578

View File

@ -27,11 +27,10 @@ import java.util.function.LongToDoubleFunction;
/** /**
* Create a double by converting values. This function works in the following modes: * Create a double by converting values. This function works in the following modes:
* <UL> * <UL>
* <LI>If a double is provided, then the long input is scaled to be between 0.0f and the value provided, * <LI>If you pass a function that produces a numeric type, then the result of this function
* as a fraction of the highest possible long.</LI> * is evaluated for the input cycle and converted to a double.</LI>
* <LI>If any other type of number is provided, then this function returns the equivalent double value.</LI> * <LI>If you pass any numeric value which is not a function, then this value is converted and
* <LI>Otherwise, the input is assumed to be a function which takes a long input, and, if necessary, * returned for every cycle as a fixed value.</LI>
* adapts to return a double with an appropriate type conversion.</LI>
* </UL> * </UL>
*/ */
@Categories(Category.conversion) @Categories(Category.conversion)
@ -41,10 +40,7 @@ public class ToDouble implements LongToDoubleFunction {
private final LongToDoubleFunction func; private final LongToDoubleFunction func;
ToDouble(Object func) { ToDouble(Object func) {
if (func instanceof Double aDouble) { if (func instanceof Number number) {
double scale = aDouble.doubleValue();
this.func = l -> (double) (l % scale);
} else if (func instanceof Number number) {
final double aDouble = number.doubleValue(); final double aDouble = number.doubleValue();
this.func = l -> aDouble; this.func = l -> aDouble;
} else { } else {