Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
8.5.2
-
None
-
New
Description
At my day job, we use ConstantValuesSource to represent default values or a constant query-level feature by calling DoubleValuesSource.constant. I realized under the hood the ConstantValuesSource.getDoubleValues creates a new DoubleValues which simply return the specified value each time it is called.
Unless I missed something, I don't see a risk of creating one DoubleValues as use it as the return value of all getDoubleValues() calls given that the constant DoubleValues doesn't maintain any state.
We can also offer the user flexibilities of how to initialize it.
1) DoubleValuesSource.constant(double constant) – we can eagerly initialize an `DoubleValues` that returns the constant and make it the return value of all getDoubleValues() calls.
2) DoubleValuesSource.constant(DoubleSupplier doubleSupplier) – For lazy evaluation if the constant takes some time to compute and user expects the returned DVS will not be used in all code path.