From 0c6fd2023806d040feb8f25327ce35d1841d64e4 Mon Sep 17 00:00:00 2001 From: Astesana Date: Mon, 2 Sep 2024 14:07:41 +0200 Subject: [PATCH] More Sonar complaints fixes --- .../soft/javaluator/demo/ConstantTableModel.java | 7 ++----- .../soft/javaluator/examples/junit/ExamplesTest.java | 2 +- .../com/fathzer/soft/javaluator/DoubleEvaluator.java | 2 +- .../java/com/fathzer/soft/javaluator/Parameters.java | 12 ++++++------ .../fathzer/soft/javaluator/junit/BracketsTest.java | 3 +-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/javaluator-demo/src/main/java/com/fathzer/soft/javaluator/demo/ConstantTableModel.java b/javaluator-demo/src/main/java/com/fathzer/soft/javaluator/demo/ConstantTableModel.java index 2bcd1da..9f43708 100644 --- a/javaluator-demo/src/main/java/com/fathzer/soft/javaluator/demo/ConstantTableModel.java +++ b/javaluator-demo/src/main/java/com/fathzer/soft/javaluator/demo/ConstantTableModel.java @@ -16,11 +16,8 @@ public class ConstantTableModel extends AbstractTableModel { public ConstantTableModel(Collection collection) { this.constants = new ArrayList<>(collection); - Collections.sort(this.constants, new Comparator() { - public int compare(Constant c1, Constant c2) { - return c1.getName().compareTo(c2.getName()); - } - }); + final Comparator cmp = (c1, c2) -> c1.getName().compareTo(c2.getName()); + Collections.sort(this.constants, cmp); } public int getColumnCount() { diff --git a/javaluator-examples/src/test/java/com/fathzer/soft/javaluator/examples/junit/ExamplesTest.java b/javaluator-examples/src/test/java/com/fathzer/soft/javaluator/examples/junit/ExamplesTest.java index 6ab2fdc..1a5fa53 100644 --- a/javaluator-examples/src/test/java/com/fathzer/soft/javaluator/examples/junit/ExamplesTest.java +++ b/javaluator-examples/src/test/java/com/fathzer/soft/javaluator/examples/junit/ExamplesTest.java @@ -34,7 +34,7 @@ public void testExtended() { ExtendedDoubleEvaluator evaluator = new ExtendedDoubleEvaluator(); // Test that all this stuff is ok String expression = "sqrt(abs(-2))^2"; - assertEquals(2, evaluator.evaluate(expression), 0.00001);; + assertEquals(2, evaluator.evaluate(expression), 0.00001); } @Test diff --git a/javaluator/src/main/java/com/fathzer/soft/javaluator/DoubleEvaluator.java b/javaluator/src/main/java/com/fathzer/soft/javaluator/DoubleEvaluator.java index a9b1af0..0bbfafd 100644 --- a/javaluator/src/main/java/com/fathzer/soft/javaluator/DoubleEvaluator.java +++ b/javaluator/src/main/java/com/fathzer/soft/javaluator/DoubleEvaluator.java @@ -219,7 +219,7 @@ protected Iterator tokenize(String expression) { if (supportsScientificNotation) { // There's a trap with scientific number notation (1E+50 for example): // + is considered as an operator. We'll make a basic work around... - final List tokens = new ArrayList(); + final List tokens = new ArrayList<>(); final Iterator rawTokens = super.tokenize(expression); while (rawTokens.hasNext()) { tokens.add(rawTokens.next()); diff --git a/javaluator/src/main/java/com/fathzer/soft/javaluator/Parameters.java b/javaluator/src/main/java/com/fathzer/soft/javaluator/Parameters.java index 3877130..fcd6e27 100644 --- a/javaluator/src/main/java/com/fathzer/soft/javaluator/Parameters.java +++ b/javaluator/src/main/java/com/fathzer/soft/javaluator/Parameters.java @@ -25,12 +25,12 @@ public class Parameters { *
Function argument separator is set to ','. */ public Parameters() { - this.operators = new ArrayList(); - this.functions = new ArrayList(); - this.constants = new ArrayList(); - this.translations = new HashMap(); - this.expressionBrackets = new ArrayList(); - this.functionBrackets = new ArrayList(); + this.operators = new ArrayList<>(); + this.functions = new ArrayList<>(); + this.constants = new ArrayList<>(); + this.translations = new HashMap<>(); + this.expressionBrackets = new ArrayList<>(); + this.functionBrackets = new ArrayList<>(); setFunctionArgumentSeparator(','); } diff --git a/javaluator/src/test/java/com/fathzer/soft/javaluator/junit/BracketsTest.java b/javaluator/src/test/java/com/fathzer/soft/javaluator/junit/BracketsTest.java index 4343fc6..43f0717 100644 --- a/javaluator/src/test/java/com/fathzer/soft/javaluator/junit/BracketsTest.java +++ b/javaluator/src/test/java/com/fathzer/soft/javaluator/junit/BracketsTest.java @@ -26,8 +26,7 @@ private DoubleEvaluator buildEvaluator() { params.addExpressionBracket(BracketPair.PARENTHESES); params.addExpressionBracket(BracketPair.BRACKETS); params.addFunctionBracket(BracketPair.ANGLES); - DoubleEvaluator eval = new DoubleEvaluator(params); - return eval; + return new DoubleEvaluator(params); } @Test (expected=IllegalArgumentException.class)