class FutureUtils {

	public static <IN, OUT> CompletableFuture<OUT> thenApplyAsyncIfNotDone(
		CompletableFuture<IN> completableFuture,
		Executor executor,
		Function<? super IN, ? extends OUT> applyFun) {
		return completableFuture.isDone() ?
			completableFuture.thenApply(applyFun) :
			completableFuture.thenApplyAsync(applyFun, executor);
	}

}