Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit b37d735

Browse files
committed
Prefer #isEmpty over #size/#length > 0
1 parent fd1ab53 commit b37d735

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

jmespath-gson/src/main/java/io/burt/jmespath/gson/GsonRuntime.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public boolean isTruthy(JsonElement value) {
9191
case BOOLEAN:
9292
return value.getAsBoolean();
9393
case STRING:
94-
return value.getAsString().length() > 0;
94+
return !value.getAsString().isEmpty();
9595
case NUMBER:
9696
return true;
9797
case ARRAY:
98-
return value.getAsJsonArray().size() > 0;
98+
return !value.getAsJsonArray().isEmpty();
9999
case OBJECT:
100-
return value.getAsJsonObject().size() > 0;
100+
return !value.getAsJsonObject().isEmpty();
101101
}
102102
throw new IllegalStateException(String.format("Unknown node type encountered: %s", value.getClass()));
103103
}

jmespath-jackson/src/main/java/io/burt/jmespath/jackson/JacksonRuntime.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public boolean isTruthy(JsonNode value) {
9797
case ARRAY:
9898
case BINARY:
9999
case OBJECT:
100-
return value.size() > 0;
100+
return !value.isEmpty();
101101
case STRING:
102-
return value.textValue().length() > 0;
102+
return !value.textValue().isEmpty();
103103
case BOOLEAN:
104104
return value.booleanValue();
105105
case MISSING:

jmespath-jakarta-jsonp/src/main/java/io/burt/jmespath/jakarta/jsonp/JsonpRuntime.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ public boolean isTruthy(JsonValue value) {
110110
case TRUE:
111111
return true;
112112
case ARRAY:
113-
return ((JsonArray) value).size() > 0;
113+
return !((JsonArray) value).isEmpty();
114114
case OBJECT:
115-
return ((JsonObject) value).size() > 0;
115+
return !((JsonObject) value).isEmpty();
116116
case STRING:
117-
return ((JsonString) value).getString().length() > 0;
117+
return !((JsonString) value).getString().isEmpty();
118118
default:
119119
throw new IllegalStateException(String.format("Unknown node type encountered: %s", value.getValueType()));
120120
}

0 commit comments

Comments
 (0)