jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] 03/07: Return early from if clauses
Date Sat, 28 Sep 2019 19:30:15 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

commit 9f536867ccb22bb9c8a44160faa6cbfff363b7f8
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sat Sep 28 21:13:01 2019 +0200

    Return early from if clauses
    
    Reduce else branches for if clauses to help readability.
    
    While at it, we can convert one of the used StringBuilder paths to a
    simple String concatenation and narrow the scope of the remaining
    StringBuilder.
---
 .../extractor/json/render/RenderAsJmesPathRenderer.java    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJmesPathRenderer.java
b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJmesPathRenderer.java
index 1b05b7d..8ec550f 100644
--- a/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJmesPathRenderer.java
+++ b/src/components/src/main/java/org/apache/jmeter/extractor/json/render/RenderAsJmesPathRenderer.java
@@ -59,18 +59,16 @@ public class RenderAsJmesPathRenderer extends AbstractRenderAsJsonRenderer
{
             JsonNode result = JMESPathCache.getInstance().get(expression).search(actualObj);
             if (result.isNull()) {
                 return NO_MATCH; //$NON-NLS-1$
-            } else {
+            }
+            if (result.isArray()) {
                 StringBuilder builder = new StringBuilder();
-                if (result.isArray()) {
-                    int i = 0;
-                    for (JsonNode element : (ArrayNode) result) {
-                        builder.append("Result[").append(i++).append("]=").append(writeJsonNode(OBJECT_MAPPER,
element)).append("\n");
-                    }
-                } else {
-                    builder.append("Result[").append(0).append("]=").append(writeJsonNode(OBJECT_MAPPER,
result)).append("\n");
+                int i = 0;
+                for (JsonNode element : (ArrayNode) result) {
+                    builder.append("Result[").append(i++).append("]=").append(writeJsonNode(OBJECT_MAPPER,
element)).append("\n");
                 }
                 return builder.toString();
             }
+            return "Result[0]=" + writeJsonNode(OBJECT_MAPPER, result) + "\n";
         } catch (Exception e) { // NOSONAR We handle it through return message
             log.debug("Exception extracting from '{}' with expression '{}'", textToParse,
expression);
             return "Exception: " + e.getMessage(); //$NON-NLS-1$


Mime
View raw message