Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nimakarimipour committed Jan 10, 2025
1 parent fea9f6f commit a23219c
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -77,17 +76,18 @@ public JsonParser(String content) {
*/
public OrElse getValueFromKey(String key) {
JsonObject current = json;
List<String> keys = Arrays.asList(key.split(":"));
while (keys.size() != 1) {
if (current.keySet().contains(keys.get(0))) {
current = (JsonObject) current.get(keys.get(0));
keys.remove(0);
String[] keys = key.split(":");
int index = 0;
while (index != keys.length - 1) {
if (current.keySet().contains(keys[index])) {
current = (JsonObject) current.get(keys[index]);
index++;
} else {
return new OrElse(JsonNull.INSTANCE);
}
}
return current.keySet().contains(keys.get(0))
? new OrElse(current.get(keys.get(0)))
return current.keySet().contains(keys[index])
? new OrElse(current.get(keys[index]))
: new OrElse(JsonNull.INSTANCE);
}

Expand Down

0 comments on commit a23219c

Please sign in to comment.