public static <U,T> Task<T> transformMultiple(Map flags, final Function<List<U>,T> transformer, List<? extends TaskAdaptable<U>> tasks) { if (tasks.size()==1) { return transform(flags, tasks.get(0), new Function<U,T>() { @Override @Nullable public T apply(@Nullable U input) { return transformer.apply(ImmutableList.of(input)); } }); } return transform(flags, new ParallelTask<U>(tasks), transformer); }
/** @see #transform(Task, Function) */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <U,T> Task<T> transform(Task<U> task, Closure transformer) { return transform(task, GroovyJavaMethods.functionFromClosure(transformer)); }
/** * Returns a {@link Task} which waits for the result of first parameter, then applies the function in the second * parameter to it, returning that result. * * Particular useful in Entity configuration where config will block until Tasks have completed, * allowing for example an {@link #attributeWhenReady(Entity, AttributeSensor, Predicate)} expression to be * passed in the first argument then transformed by the function in the second argument to generate * the value that is used for the configuration */ public static <U,T> Task<T> transform(final Task<U> task, final Function<U,T> transformer) { return transform(MutableMap.of("displayName", "transforming "+task), task, transformer); }