Skip to content

Commit

Permalink
refactor(android): extract parser from for-loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Sep 11, 2023
1 parent fec6fea commit e909dc1
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public void setArgs(JSONArray args) throws JSONException {
} else if (type.equals("boolean")) {
argument = jsonArgument.optBoolean("value");
} else if (type.equals("Invocation")) {
argument = new Invocation(jsonArgument.optJSONObject("value"));
argument = new Invocation(jsonArgument.optJSONObject("value"));
} else {
throw new RuntimeException("Unhandled arg type" + type);
throw new RuntimeException("Unhandled arg type " + type);
}
}
}
Expand All @@ -105,6 +105,8 @@ public void setArgs(JSONArray args) throws JSONException {
}

public void setArgs(Object[] args) {
JsonParser parser = new JsonParser();

for (int i = 0; i < args.length; i++) {
Object argument = args[i];
if (argument instanceof HashMap && !((HashMap) argument).isEmpty()) {
Expand All @@ -125,10 +127,9 @@ public void setArgs(Object[] args) {
} else if (type.equals("boolean")) {
argument = ((Boolean) value).booleanValue();
} else if (type.equals("Invocation")) {
JsonParser parser = new JsonParser();
argument = parser.parse((String)value);
} else {
throw new RuntimeException("Unhandled arg type" + type);
throw new RuntimeException("Unhandled arg type " + type);
}

args[i] = argument;
Expand Down

0 comments on commit e909dc1

Please sign in to comment.