You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2021/01/26 18:57:27 UTC
[jmeter] branch master updated: Reduce number of return paths in
method
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 <fe...@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++) {