You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/05/27 20:58:22 UTC

[commons-math] branch modularized_master updated: MATH-1588: Fit into JDK 8 "function" API.

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch modularized_master
in repository https://gitbox.apache.org/repos/asf/commons-math.git


The following commit(s) were added to refs/heads/modularized_master by this push:
     new d92a3c6  MATH-1588: Fit into JDK 8 "function" API.
d92a3c6 is described below

commit d92a3c63358ef31014b8957cf24f5e7e31d4c269
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu May 27 22:56:48 2021 +0200

    MATH-1588: Fit into JDK 8 "function" API.
---
 .../commons/math4/legacy/analysis/BivariateFunction.java     | 10 +++++++++-
 .../commons/math4/legacy/analysis/UnivariateFunction.java    | 12 ++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/BivariateFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/BivariateFunction.java
index 19b5383..562aa32 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/BivariateFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/BivariateFunction.java
@@ -17,12 +17,15 @@
 
 package org.apache.commons.math4.legacy.analysis;
 
+import java.util.function.DoubleBinaryOperator;
+
 /**
  * An interface representing a bivariate real function.
  *
  * @since 2.1
  */
-public interface BivariateFunction {
+@FunctionalInterface
+public interface BivariateFunction extends DoubleBinaryOperator {
     /**
      * Compute the value for the function.
      *
@@ -32,4 +35,9 @@ public interface BivariateFunction {
      */
     double value(double x, double y);
 
+    /** {@inheritDoc} */
+    @Override
+    default double applyAsDouble(double x, double y) {
+        return value(x, y);
+    }
 }
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/UnivariateFunction.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/UnivariateFunction.java
index ff66cbb..43cfd61 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/UnivariateFunction.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/UnivariateFunction.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math4.legacy.analysis;
 
+import java.util.function.DoubleUnaryOperator;
+
 /**
  * An interface representing a univariate real function.
  * <p>
@@ -62,9 +64,9 @@ package org.apache.commons.math4.legacy.analysis;
  *
  * As shown, the exception is local to the user's code and it is guaranteed
  * that Apache Commons Math will not catch it.
- *
  */
-public interface UnivariateFunction {
+@FunctionalInterface
+public interface UnivariateFunction extends DoubleUnaryOperator {
     /**
      * Compute the value of the function.
      *
@@ -78,4 +80,10 @@ public interface UnivariateFunction {
      * the method.
      */
     double value(double x);
+
+    /** {@inheritDoc} */
+    @Override
+    default double applyAsDouble(double x) {
+        return value(x);
+    }
 }