| 1 | package com.github.dakusui.symfonion.compat.json; | |
| 2 | ||
| 3 | import com.google.gson.JsonArray; | |
| 4 | import com.google.gson.JsonElement; | |
| 5 | import com.google.gson.JsonObject; | |
| 6 | import com.google.gson.JsonPrimitive; | |
| 7 | ||
| 8 | import java.util.Optional; | |
| 9 | ||
| 10 | import static com.github.valid8j.fluent.Expectations.require; | |
| 11 | import static com.github.valid8j.fluent.Expectations.value; | |
| 12 | ||
| 13 | /** | |
| 14 | * //@formatter:off | |
| 15 | * //@formatter:on | |
| 16 | */ | |
| 17 | public enum JsonUtils { | |
| 18 | ; | |
| 19 | private static final JsonElement DEFAULT_VALUE = new JsonArray(); | |
| 20 | public static Path path(Object... path) { | |
| 21 |
1
1. path : replaced return value with null for com/github/dakusui/symfonion/compat/json/JsonUtils::path → KILLED |
return new Path(path); |
| 22 | } | |
| 23 | ||
| 24 | public static Optional<JsonElement> findJsonElement(JsonElement base, Path path) { | |
| 25 |
1
1. findJsonElement : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonElement → NO_COVERAGE |
return getJsonElement(JsonElement.class, base, path); |
| 26 | } | |
| 27 | ||
| 28 | public static Optional<JsonObject> findJsonObject(JsonElement base, Path path) { | |
| 29 |
1
1. findJsonObject : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonObject → NO_COVERAGE |
return getJsonElement(JsonObject.class, base, path); |
| 30 | } | |
| 31 | ||
| 32 | public static Optional<JsonArray> findJsonArray(JsonElement base, Path path) { | |
| 33 |
1
1. findJsonArray : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonArray → KILLED |
return getJsonElement(JsonArray.class, base, path); |
| 34 | } | |
| 35 | ||
| 36 | public static Optional<JsonPrimitive> findJsonPrimitive(JsonPrimitive base, Path path) { | |
| 37 |
1
1. findJsonPrimitive : replaced return value with Optional.empty for com/github/dakusui/symfonion/compat/json/JsonUtils::findJsonPrimitive → NO_COVERAGE |
return getJsonElement(JsonPrimitive.class, base, path); |
| 38 | } | |
| 39 | ||
| 40 | @SuppressWarnings("unchecked") | |
| 41 | private static <T extends JsonElement> Optional<T> getJsonElement(Class<T> jsonType, JsonElement base, Path path) { | |
| 42 | var ret = require(value(CompatJsonUtils.asJsonElementWithDefault(base, DEFAULT_VALUE, path.path())).toBe() | |
| 43 | .instanceOf(jsonType)); | |
| 44 |
1
1. getJsonElement : negated conditional → KILLED |
return ret != DEFAULT_VALUE ? Optional.of((T) ret) |
| 45 | : Optional.empty(); | |
| 46 | } | |
| 47 | ||
| 48 | public record Path(Object... path) { | |
| 49 | } | |
| 50 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 25 |
1.1 |
|
| 29 |
1.1 |
|
| 33 |
1.1 |
|
| 37 |
1.1 |
|
| 44 |
1.1 |