From 8f838278467c1d00ba3e9e83c4f9b963cf246984 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Wed, 14 Jul 2021 00:36:10 +0200 Subject: [PATCH] Code simplifications (suggested by "sonarcloud"). --- .../scalar/noderiv/SimplexOptimizer.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java index e2fb51097..60a2a388c 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/SimplexOptimizer.java @@ -123,27 +123,14 @@ public class SimplexOptimizer extends MultivariateOptimizer { // Indirect call to "computeObjectiveValue" in order to update the // evaluations counter. - final MultivariateFunction evalFunc - = new MultivariateFunction() { - /** {@inheritDoc} */ - @Override - public double value(double[] point) { - return computeObjectiveValue(point); - } - }; + final MultivariateFunction evalFunc = (p) -> computeObjectiveValue(p); final boolean isMinim = getGoalType() == GoalType.MINIMIZE; - final Comparator comparator - = new Comparator() { - /** {@inheritDoc} */ - @Override - public int compare(final PointValuePair o1, - final PointValuePair o2) { - final double v1 = o1.getValue(); - final double v2 = o2.getValue(); - return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); - } - }; + final Comparator comparator = (o1, o2) -> { + final double v1 = o1.getValue(); + final double v2 = o2.getValue(); + return isMinim ? Double.compare(v1, v2) : Double.compare(v2, v1); + }; final UnaryOperator update = updateRule.apply(evalFunc, comparator); @@ -202,12 +189,8 @@ public class SimplexOptimizer extends MultivariateOptimizer { for (OptimizationData data : optData) { if (data instanceof Simplex) { simplex = (Simplex) data; - continue; - } - - if (data instanceof Simplex.TransformFactory) { + } else if (data instanceof Simplex.TransformFactory) { updateRule = (Simplex.TransformFactory) data; - continue; } } }