/** * Get all permutations of the method. A "permutation" is a known runtime * method invocation, and is formatted as in the following examples: * <ul> * <li> methodName</li> * <li> methodName?parm1=val1&parm2=val1</li> * <li> methodName?parm1=val1&parm2=val2</li> * <li> methodName?parm1=val2&parm2=val1</li> * <li> methodName?parm1=val2&parm2=val2</li> * </ul> * * @return the set of invokable permutations for the method. */ public Set<String> getPermutations() { Set<String> set = new HashSet<String>(); addPermutations(_methodName, getValues(), 0, '?', set); return set; }
/** * Recursively add permutations for all possible values of domains[index]. */ private static void addPermutations(String prefix, ParamDomain[] domains, int index, char delimiter, Set<String> set) { if (index + 1 > domains.length) { // no more parameters; prefix is a permutation set.add(prefix); return; } else { ParamDomain domain = domains[index]; if (domain.size() > 0) { // add permutations for each domain value of this parameter for (String domainValue : domain) { String newPrefix = prefix + delimiter + domain.getParameterName() + "=" + domainValue; addPermutations(newPrefix, domains, index + 1, '&', set); } } if (!domain.isRequired()) { // add permutations where this parameter is unspecified addPermutations(prefix, domains, index + 1, delimiter, set); } } }