コード例 #1
0
 String[] getStringValues() {
   List<String> values = new ArrayList<>();
   for (ActionArgument argument : getArguments()) {
     values.add(argument.getStringValue());
   }
   return values.toArray(new String[0]);
 }
コード例 #2
0
 // region toJson/toString()
 public JSONObject toJson() {
   JSONObject jsonObject = new JSONObject();
   try {
     if (isRootRequired()) {
       jsonObject.put("root", true);
     }
     if (optional) {
       jsonObject.put("optional", true);
     }
     jsonObject.put("name", getName());
     if (getArguments().length > 0) {
       JSONArray jsonArray = new JSONArray();
       for (ActionArgument argument : getArguments()) {
         jsonArray.put(argument.toJson());
       }
       jsonObject.put("arguments", jsonArray);
     }
     jsonObject.put("description", getDescription());
     jsonObject.put("category", getCategory().toString());
     if (failure != null) {
       jsonObject.put("failure", failure);
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return jsonObject;
 }
コード例 #3
0
  // todo - dirty to be refactor
  public void parseValues(String... values) throws ActionParseException {

    ActionArgument[] arguments = getArguments();

    if (arguments.length != values.length) {
      throw new ActionParseException("Invalid number of arguments for action " + getName());
    }

    for (int i = 0; i < arguments.length; i++) {
      try {
        arguments[i].parseValue(values[i]);
      } catch (Exception e) {
        throw new ActionParseException(e.getMessage());
      }
    }
    List<Object> vals = new ArrayList<>();
    for (ActionArgument argument : arguments) {
      vals.add(argument.getValue());
    }
    setValues(vals.toArray(new Object[0]));
  }