This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push: new 72ade3244d Trivial refactor: compare numbers with `compare()` method 72ade3244d is described below commit 72ade3244de90d892f573fe791d167356ce60cad Author: Daniel Sun <sun...@apache.org> AuthorDate: Sat Jun 14 23:46:53 2025 +0900 Trivial refactor: compare numbers with `compare()` method --- .../main/java/groovy/swing/table/TableSorter.java | 24 ++++------------------ 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/subprojects/groovy-swing/src/main/java/groovy/swing/table/TableSorter.java b/subprojects/groovy-swing/src/main/java/groovy/swing/table/TableSorter.java index b10eee4906..5a3e089c1b 100644 --- a/subprojects/groovy-swing/src/main/java/groovy/swing/table/TableSorter.java +++ b/subprojects/groovy-swing/src/main/java/groovy/swing/table/TableSorter.java @@ -114,11 +114,7 @@ public class TableSorter extends TableMap { String s2 = v2.toString(); int result = s1.compareTo(s2); - if (result < 0) - return -1; - if (result > 0) - return 1; - return 0; + return Integer.compare(result, 0); } private static int compareBooleans(TableModel data, int row1, int column, int row2) { @@ -137,11 +133,7 @@ public class TableSorter extends TableMap { String s2 = (String) data.getValueAt(row2, column); int result = s1.compareTo(s2); - if (result < 0) - return -1; - if (result > 0) - return 1; - return 0; + return Integer.compare(result, 0); } private static int compareDates(TableModel data, int row1, int column, int row2) { @@ -150,11 +142,7 @@ public class TableSorter extends TableMap { Date d2 = (Date) data.getValueAt(row2, column); long n2 = d2.getTime(); - if (n1 < n2) - return -1; - if (n1 > n2) - return 1; - return 0; + return Long.compare(n1, n2); } private static int compareNumbers(TableModel data, int row1, int column, int row2) { @@ -163,11 +151,7 @@ public class TableSorter extends TableMap { Number n2 = (Number) data.getValueAt(row2, column); double d2 = n2.doubleValue(); - if (d1 < d2) - return -1; - if (d1 > d2) - return 1; - return 0; + return Double.compare(d1, d2); } public int compare(int row1, int row2) {