From d8fdbb80c05bff3490bad618b5ab119639626d2d Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Mon, 1 Jan 2024 19:39:59 +0100 Subject: [PATCH] Simplify formula operation interfaces. This commit releases the BinaryOperation and UnaryOperation interfaces of the `formula` package from their `java.util.function` supertypes and redeclares the previously inherited functions directly in the operation interfaces, but also reifies them by explicitly using primitive doubles instead of generics and wrapper classes. Doing so does not change the functionality or any other code at all, but it makes the interfaces much "stronger", since they no longer need to consider `null` values, which they didn't actually take into account anyway. This fixes a warning in Visual Studio Code (not sure how to get the same warning in IntelliJ) about the operator registrations in the default formula environment factory method being unsafe. --- .../com/garbagemule/MobArena/formula/BinaryOperation.java | 7 ++++--- .../com/garbagemule/MobArena/formula/UnaryOperation.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/garbagemule/MobArena/formula/BinaryOperation.java b/src/main/java/com/garbagemule/MobArena/formula/BinaryOperation.java index 9a06a27..0a2c462 100644 --- a/src/main/java/com/garbagemule/MobArena/formula/BinaryOperation.java +++ b/src/main/java/com/garbagemule/MobArena/formula/BinaryOperation.java @@ -1,7 +1,8 @@ package com.garbagemule.MobArena.formula; -import java.util.function.BiFunction; - @FunctionalInterface -public interface BinaryOperation extends BiFunction { +public interface BinaryOperation { + + double apply(double left, double right); + } diff --git a/src/main/java/com/garbagemule/MobArena/formula/UnaryOperation.java b/src/main/java/com/garbagemule/MobArena/formula/UnaryOperation.java index f27f200..4b91232 100644 --- a/src/main/java/com/garbagemule/MobArena/formula/UnaryOperation.java +++ b/src/main/java/com/garbagemule/MobArena/formula/UnaryOperation.java @@ -1,7 +1,8 @@ package com.garbagemule.MobArena.formula; -import java.util.function.Function; - @FunctionalInterface -public interface UnaryOperation extends Function { +public interface UnaryOperation { + + double apply(double value); + }