/** * Executes with the given args all the cases matching the given match plus the defaut one * if it has been defined. * @param match The object to be matched to decide witch case has to be executed * @param args The arguments used to invoke the matching cases * @return The results of all the matching case invocations */ public List<T> execAll(Object match, Object ... args) { List<T> results = new ArrayList<T>(); for (Case<T> c : cases) { if (c.matches(match)) results.add(c.exec(args)); } if (defaultResult != null) results.add(defaultResult.exec(args)); return results; }
private T exec(Object ... args) { return result.exec(args); } }
/** * Executes with the given args the first case that matches the given match or the defaut one * if it has been defined and no other case matches. * @param match The object to be matched to decide witch case has to be executed * @param args The arguments used to invoke the matching case * @return The result of the matching case invocation */ public T exec(Object match, Object ... args) { for (Case<T> c : cases) { if (c.matches(match)) return c.exec(args); } return defaultResult != null ? defaultResult.exec(args) : null; }