jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Reduce number of return paths in method
Date Tue, 26 Jan 2021 18:57:27 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new ff9866a  Reduce number of return paths in method
ff9866a is described below

commit ff9866aa21608b211c0652f4c05a270a9b4eb3ac
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Tue Jan 26 19:56:28 2021 +0100

    Reduce number of return paths in method
    
    I am not sure I like it better, but at least the linter is happy and
    future will tell, whether it was a good idea :)
---
 .../apache/jorphan/util/AlphaNumericComparator.java | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/AlphaNumericComparator.java
b/src/jorphan/src/main/java/org/apache/jorphan/util/AlphaNumericComparator.java
index 07a0451..a2380ce 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/util/AlphaNumericComparator.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/util/AlphaNumericComparator.java
@@ -57,13 +57,8 @@ public class AlphaNumericComparator<T> implements Comparator<T>
{
             }
             String numberPart1 = m1.group(NUM_PART);
             String numberPart2 = m2.group(NUM_PART);
-            if (numberPart1.isEmpty()) {
-                if (numberPart2.isEmpty()) {
-                    return 0;
-                }
-                return -1;
-            } else if (numberPart2.isEmpty()) {
-                return 1;
+            if (numberPart1.isEmpty() || numberPart2.isEmpty()) {
+                return compareOneEmptyPart(numberPart1, numberPart2);
             }
             String nonZeroNumberPart1 = trimLeadingZeroes(numberPart1);
             String nonZeroNumberPart2 = trimLeadingZeroes(numberPart2);
@@ -89,6 +84,18 @@ public class AlphaNumericComparator<T> implements Comparator<T>
{
         return 1;
     }
 
+    private int compareOneEmptyPart(String numberPart1, String numberPart2) {
+        if (numberPart1.isEmpty()) {
+            if (numberPart2.isEmpty()) {
+                return 0;
+            }
+            return -1;
+        } else if (numberPart2.isEmpty()) {
+            return 1;
+        }
+        throw new IllegalArgumentException("At least one of the parameters have to be empty");
+    }
+
     private String trimLeadingZeroes(String numberPart) {
         int length = numberPart.length();
         for (int i = 0; i < length; i++) {


Mime
View raw message