/** * Split a comma separated request param into a list of trimmed strings discarding any blank parts. * <p> * x=comma,separated,,%20value -> ["comma", "separated", "value"] */ public static Monadics.ListMonadic<String> splitCommaSeparatedParam(Option<String> param) { for (String p : param) return mlist(CSV_SPLIT.apply(p)).bind(trimToNil); return mlist(); }
/** Create a list of access control entries for a given role. */ public static Either<AccessControlEntry, List<AccessControlEntry>> entries(final String role, Tuple<String, Boolean>... actions) { final List<AccessControlEntry> entries = mlist(actions).map( new Function<Tuple<String, Boolean>, AccessControlEntry>() { @Override public AccessControlEntry apply(Tuple<String, Boolean> action) { return new AccessControlEntry(role, action.getA(), action.getB()); } }).value(); return right(entries); }
/** Create a config info string suitable for logging purposes. */ public static String showConfig(Tuple<String, ?>... cfg) { return "Config\n" + Collections.mkString(mlist(cfg).map(new Function<Tuple<String, ?>, String>() { @Override public String apply(Tuple<String, ?> t) { return t.getA() + "=" + t.getB().toString(); } }).value(), "\n"); }
/** Pattern matching on the wrapped list. */ public final <B> B match(List<Matcher<A, B>> ms) { for (Matcher<A, B> m : ms) { if (m.matches(this)) { return m.apply(this); } } return unexhaustiveMatch(); }