@Override public List<String> apply(String a) { if (a != null) { final String trimmed = a.trim(); return trimmed.length() > 0 ? list(trimmed) : NIL; } else { return NIL; } } };
protected ProcessExecutor(String[] commandLine) { this.commandLine = commandLine; this.environment = map(); this.redirectErrorStream = false; }
@Override public Option<A> apply(List<A> as) { return Collections.head(as); } };
public static HttpPost post(String uri, List<NameValuePair> formParams) { final HttpPost post = new HttpPost(uri); setFormParams(post, Collections.toArray(NameValuePair.class, formParams)); return post; }
@Override public List<A> eval() { return toList(as); } };
@Override public <B> ListMonadic<B> bind(Function<? super A, ? extends Iterable<B>> f) { final List<B> target = newListBuilder(); while (as.hasNext()) appendTo(target, f.apply(as.next())); return mlist(target); }
/** * Partition a list after some predicate <code>keyGen</code>. The partition function has to make sure that keys are * unique per list element because each key holds only one value. Later values overwrite newer ones. * * The resulting map is an immutable {@link java.util.HashMap}. * * @see #asMap(java.util.Map, java.util.List, Function) */ public static <K, V> Map<K, V> asMap(List<V> values, Function<V, K> keyGen) { return java.util.Collections.unmodifiableMap(asMap(new HashMap<K, V>(), values, keyGen)); }
@Override public <M extends Iterable<A>> ListMonadic<A> concat(M bs) { return mlist(appendToM(Monadics.<A> newListBuilder(), as, bs)); }
/** * Waits for the result of a created barrier for <code>jobs</code>, using <code>registry</code> to poll for the * outcome of the monitored jobs using the default polling interval. * * @param reg * the service registry * @param timeout * the maximum amount of time to wait * @param jobs * the jobs to monitor * @return the job barrier result */ public static JobBarrier.Result waitForJobs(ServiceRegistry reg, long timeout, Collection<Job> jobs) { return waitForJobs(null, reg, timeout, toArray(Job.class, jobs)); }
@Override public List<A> value() { return java.util.Collections.unmodifiableList(toList(as)); } };
@Override public <B> ListMonadic<B> bind(Function<? super A, ? extends Iterable<B>> f) { final List<B> target = newListBuilder(); for (A a : as) appendTo(target, f.apply(a)); return mlist(target); }
@Override public List<A> apply(MediaPackageElement mpe) { return type.isAssignableFrom(mpe.getClass()) ? list((A) mpe) : (List<A>) NIL; } };
protected ProcessExecutor(String[] commandLine, boolean redirectErrorStream) { this.commandLine = commandLine; this.redirectErrorStream = redirectErrorStream; this.environment = map(); }
/** * Waits for the result of a created barrier for <code>jobs</code>, using <code>registry</code> to poll for the * outcome of the monitored jobs using the default polling interval. The * <code>waiter</code> is the job which is waiting for the other jobs to finish. * * @param waiter * the job waiting for the other jobs to finish * @param reg * the service registry * @param jobs * the jobs to monitor * @return the job barrier result */ public static JobBarrier.Result waitForJobs(Job waiter, ServiceRegistry reg, Collection<Job> jobs) { return waitForJobs(waiter, reg, toArray(Job.class, jobs)); }