// Expand grid search related argument sets @Override protected NanoHTTPD.Response serveGrid(NanoHTTPD server, Properties parms, RequestType type) { String[][] values = new String[_arguments.size()][]; boolean gridSearch = false; for (int i = 0; i < _arguments.size(); i++) { Argument arg = _arguments.get(i); if (arg._gridable) { String value = _parms.getProperty(arg._name); if (value != null) { // Skips grid if argument is an array, except if imbricated expression // Little hackish, waiting for real language boolean imbricated = value.contains("("); if (!arg._field.getType().isArray() || imbricated) { values[i] = split(value); if (values[i] != null && values[i].length > 1) gridSearch = true; } else if (arg._field.getType().isArray() && !imbricated) { // Copy values which are arrays values[i] = new String[] {value}; } } } } if (!gridSearch) return superServeGrid(server, parms, type); // Ignore destination key so that each job gets its own _parms.remove("destination_key"); for (int i = 0; i < _arguments.size(); i++) if (_arguments.get(i)._name.equals("destination_key")) values[i] = null; // Iterate over all argument combinations int[] counters = new int[values.length]; ArrayList<Job> jobs = new ArrayList<Job>(); for (; ; ) { Job job = (Job) create(_parms); Properties combination = new Properties(); for (int i = 0; i < values.length; i++) { if (values[i] != null) { String value = values[i][counters[i]]; value = value.trim(); combination.setProperty(_arguments.get(i)._name, value); _arguments.get(i).reset(); _arguments.get(i).check(job, value); } } job._parms = combination; jobs.add(job); if (!increment(counters, values)) break; } GridSearch grid = new GridSearch(); grid.jobs = jobs.toArray(new Job[jobs.size()]); return grid.superServeGrid(server, parms, type); }
public String input(String fieldName) { return _parms == null ? null : _parms.getProperty(fieldName); }