From 8bad7d14e00b3e47aa365f3695a975b1cc54421e Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sun, 20 Oct 2024 18:20:01 +0000 Subject: [PATCH] Reduce cycolmatic complexity (#793) --- .../maven/surefire/api/util/RunOrder.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/RunOrder.java b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/RunOrder.java index 263b312394..c8b2612df9 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/api/util/RunOrder.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/api/util/RunOrder.java @@ -47,8 +47,8 @@ public class RunOrder { /** * Returns the specified RunOrder * - * @param values The runorder string value - * @return An array of RunOrder objects, never null + * @param values the runorder string value + * @return an array of RunOrder objects, never null */ public static RunOrder[] valueOfMulti(String values) { List result = new ArrayList<>(); @@ -78,14 +78,13 @@ public static RunOrder valueOf(String name) { } private static String createMessageForMissingRunOrder(String name) { - RunOrder[] runOrders = values(); + RunOrder[] runOrders = values(); // guaranteed non-empty StringBuilder message = new StringBuilder("There's no RunOrder with the name "); message.append(name); message.append(". Use one of the following RunOrders: "); - for (int i = 0; i < runOrders.length; i++) { - if (i != 0) { - message.append(", "); - } + message.append(runOrders[0]); + for (int i = 1; i < runOrders.length; i++) { + message.append(", "); message.append(runOrders[i]); } message.append('.'); @@ -98,12 +97,11 @@ private static RunOrder[] values() { public static String asString(RunOrder[] runOrder) { StringBuilder stringBuffer = new StringBuilder(); - for (int i = 0; i < runOrder.length; i++) { + for (int i = 0; i < runOrder.length - 1; i++) { stringBuffer.append(runOrder[i].name); - if (i < (runOrder.length - 1)) { - stringBuffer.append(","); - } + stringBuffer.append(","); } + stringBuffer.append(runOrder[runOrder.length - 1].name); return stringBuffer.toString(); }