andreachild commented on code in PR #3121:
URL: https://github.com/apache/tinkerpop/pull/3121#discussion_r2105279277
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/NumberHelper.java:
##########
@@ -28,6 +28,50 @@
*/
public final class NumberHelper {
+ static final class NumberInfo {
+
+ int bits;
+ boolean fp;
+
+ NumberInfo(int bits, boolean fp) {
+ this.bits = bits;
+ this.fp = fp;
+ }
+ }
+
+ enum MathOperation {
Review Comment:
This enum can be avoided and code duplication reduced by changing the
`mathOperationWithPromote` method signature to accept a `Function` param which
takes a `NumberHelper` and returns a `BiFunction`.
Something like this:
```
private static Number mathOperationWithPromote(final Function<NumberHelper,
BiFunction<Number, Number, Number>> mathFunction, final boolean
forceFloatingPoint, final Number a, final Number b) {
...
final Class<? extends Number> clazz =
determineNumberClass(numberInfo.bits, numberInfo.fp);
NumberHelper helper = getHelper(clazz);
result = mathFunction.apply(helper).apply(a, b);
...
```
}
And then it can be called like this:
```
public static Number add(final Number a, final Number b) {
return mathOperationWithPromote(numberHelper -> numberHelper.add, false,
a, b);
}
public static Number sub(final Number a, final Number b) {
return mathOperationWithPromote(numberHelper -> numberHelper.sub, false,
a, b);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]