4545public final class ApiFutures {
4646 private ApiFutures () {}
4747
48- /*
49- * @deprecated Use {@linkplain #addCallback(ApiFuture, ApiFutureCallback, Executor) the
50- * overload that requires an executor}. For identical behavior, pass {@link
51- * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
52- * another executor would be safer.
48+ /**
49+ * Registers a callback to be run when the {@link ApiFuture}'s computation is complete or, if the
50+ * computation is already complete, immediately.
51+ *
52+ * @param future The future attach the callback to
53+ * @param callback The callback to invoke when future is completed
54+ * @deprecated Use {@linkplain #addCallback(ApiFuture, ApiFutureCallback, Executor) the overload
55+ * that requires an executor}. For identical behavior, pass {@link
56+ * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
57+ * another executor would be safer.
5358 */
5459 @ Deprecated
5560 public static <V > void addCallback (
5661 final ApiFuture <V > future , final ApiFutureCallback <? super V > callback ) {
5762 addCallback (future , callback , directExecutor ());
5863 }
5964
65+ /**
66+ * Registers a callback to be run when the {@link ApiFuture}'s computation is complete or, if the
67+ * computation is already complete, immediately.
68+ *
69+ * <p>Note that this method is a delegate of {@link Futures#addCallback(ListenableFuture,
70+ * FutureCallback, Executor)}.
71+ *
72+ * @param future The future attach the callback to
73+ * @param callback The callback to invoke when future is completed
74+ * @param executor The executor to run callback when the future completes
75+ * @see Futures#addCallback(ListenableFuture, FutureCallback, Executor)
76+ */
6077 public static <V > void addCallback (
6178 final ApiFuture <V > future , final ApiFutureCallback <? super V > callback , Executor executor ) {
6279 Futures .addCallback (
@@ -75,11 +92,20 @@ public void onSuccess(V v) {
7592 executor );
7693 }
7794
78- /*
79- * @deprecated Use {@linkplain #catching(ApiFuture, Class, ApiFunction, Executor) the
80- * overload that requires an executor}. For identical behavior, pass {@link
81- * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
82- * another executor would be safer.
95+ /**
96+ * Returns an {@link ApiFuture} whose result is taken from the given primary input or, if the
97+ * primary input fails with the given exceptionType, from the result provided by the callback.
98+ *
99+ * @param input The primary input {@code ApiFuture}
100+ * @param exceptionType The exception type that triggers use of {@code fallback}
101+ * @param callback The {@link ApiFunction} to be called if input fails with the expected exception
102+ * type
103+ * @return A future whose result is taken either from the given {@code input} or by the {@code
104+ * callback}
105+ * @deprecated Use {@linkplain #catching(ApiFuture, Class, ApiFunction, Executor) the overload
106+ * that requires an executor}. For identical behavior, pass {@link
107+ * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
108+ * another executor would be safer.
83109 */
84110 @ Deprecated
85111 public static <V , X extends Throwable > ApiFuture <V > catching (
@@ -89,6 +115,22 @@ public static <V, X extends Throwable> ApiFuture<V> catching(
89115 return catching (input , exceptionType , callback , directExecutor ());
90116 }
91117
118+ /**
119+ * Returns an {@link ApiFuture} whose result is taken from the given primary input or, if the
120+ * primary input fails with the given exceptionType, from the result provided by the callback.
121+ *
122+ * <p>Note that this method is a delegate of {@link Futures#catching(ListenableFuture, Class,
123+ * Function, Executor)}.
124+ *
125+ * @param input The primary input {@code ApiFuture}
126+ * @param exceptionType The exception type that triggers use of {@code fallback}
127+ * @param callback The {@link ApiFunction} to be called if input fails with the expected exception
128+ * type
129+ * @param executor The executor that runs {@code fallback} if {@code input} fails
130+ * @return A future whose result is taken either from the given {@code input} or by the {@code
131+ * callback}
132+ * @see Futures#catching(ListenableFuture, Class, Function, Executor)
133+ */
92134 public static <V , X extends Throwable > ApiFuture <V > catching (
93135 ApiFuture <? extends V > input ,
94136 Class <X > exceptionType ,
@@ -103,6 +145,22 @@ public static <V, X extends Throwable> ApiFuture<V> catching(
103145 return new ListenableFutureToApiFuture <V >(catchingFuture );
104146 }
105147
148+ /**
149+ * Returns a {@link ApiFuture} whose result is taken from the given primary input or, if the
150+ * primary input fails with the given exceptionType, from the result provided by the callback.
151+ *
152+ * <p>Note that this method is a delegate of {@link Futures#catchingAsync(ListenableFuture, Class,
153+ * AsyncFunction, Executor)}
154+ *
155+ * @param input The primary input {@code ApiFuture}
156+ * @param exceptionType The exception type that triggers use of {@code fallback}.
157+ * @param callback The {@link ApiAsyncFunction} to be called if {@code input} fails with the
158+ * expected * exception type.
159+ * @param executor The executor that runs {@code fallback} if {@code input} fails
160+ * @return A future whose result is taken either from the given {@code input} or by the {@code
161+ * callback}
162+ * @see Futures#catchingAsync(ListenableFuture, Class, AsyncFunction, Executor)
163+ */
106164 @ BetaApi
107165 public static <V , X extends Throwable > ApiFuture <V > catchingAsync (
108166 ApiFuture <V > input ,
@@ -124,30 +182,78 @@ public ListenableFuture<V> apply(X exception) throws Exception {
124182 return new ListenableFutureToApiFuture <>(catchingFuture );
125183 }
126184
185+ /**
186+ * Creates a {@code ApiFuture} which has its value set immediately upon construction.
187+ *
188+ * <p>Note that this method is a delegate of {@link Futures#immediateFuture(Object)}.
189+ *
190+ * @param value The value set to the {@code ApiFuture} upon construction
191+ * @return A future that holds {@code value}
192+ * @see Futures#immediateFuture(Object)
193+ */
127194 public static <V > ApiFuture <V > immediateFuture (V value ) {
128195 return new ListenableFutureToApiFuture <>(Futures .<V >immediateFuture (value ));
129196 }
130197
198+ /**
199+ * Returns a {@code ApiFuture} which has an exception set immediately upon construction.
200+ *
201+ * <p>Note that this method is a delegate of {@link Futures#immediateFailedFuture(Throwable)}.
202+ *
203+ * @param throwable The exception set to the {@code ApiFuture} upon construction
204+ * @return A future that holds an exception
205+ * @see Futures#immediateFailedFuture(Throwable)
206+ */
131207 public static <V > ApiFuture <V > immediateFailedFuture (Throwable throwable ) {
132208 return new ListenableFutureToApiFuture <V >(Futures .<V >immediateFailedFuture (throwable ));
133209 }
134210
211+ /**
212+ * Creates a {@code ApiFuture} which is cancelled immediately upon construction, so that {@code
213+ * isCancelled()} always returns {@code true}.
214+ *
215+ * <p>Note that this method is a delegate of {@link Futures#immediateCancelledFuture()}.
216+ *
217+ * @return A cancelled future
218+ * @see Futures#immediateCancelledFuture()
219+ */
135220 public static <V > ApiFuture <V > immediateCancelledFuture () {
136221 return new ListenableFutureToApiFuture <V >(Futures .<V >immediateCancelledFuture ());
137222 }
138223
139- /*
140- * @deprecated Use {@linkplain #transform(ApiFuture, ApiFunction, Executor) the
141- * overload that requires an executor}. For identical behavior, pass {@link
142- * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
143- * another executor would be safer.
224+ /**
225+ * Returns a new {@code ApiFuture} whose result is derived from the result of the given {@code
226+ * ApiFuture}.
227+ *
228+ * @param input The future to transform
229+ * @param function A Function to transform the results of the provided future to the results of
230+ * the returned future
231+ * @return A future that holds result of the transformation
232+ * @deprecated Use {@linkplain #transform(ApiFuture, ApiFunction, Executor) the overload that
233+ * requires an executor}. For identical behavior, pass {@link
234+ * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
235+ * another executor would be safer.
144236 */
145237 @ Deprecated
146238 public static <V , X > ApiFuture <X > transform (
147239 ApiFuture <? extends V > input , final ApiFunction <? super V , ? extends X > function ) {
148240 return transform (input , function , directExecutor ());
149241 }
150242
243+ /**
244+ * Returns a new {@code ApiFuture} whose result is derived from the result of the given {@code
245+ * ApiFuture}.
246+ *
247+ * <p>Note that this method is a delegate of {@link Futures#transform(ListenableFuture, Function,
248+ * Executor)}.
249+ *
250+ * @param input The future to transform
251+ * @param function A Function to transform the results of the provided future to the results of
252+ * the returned future.
253+ * @param executor Executor to run the function in.
254+ * @return A future that holds result of the transformation
255+ * @see Futures#transform(ListenableFuture, Function, Executor)
256+ */
151257 public static <V , X > ApiFuture <X > transform (
152258 ApiFuture <? extends V > input ,
153259 final ApiFunction <? super V , ? extends X > function ,
@@ -159,6 +265,18 @@ public static <V, X> ApiFuture<X> transform(
159265 executor ));
160266 }
161267
268+ /**
269+ * Creates a new {@code ApiFuture} whose value is a list containing the values of all its input
270+ * futures, if all succeed.
271+ *
272+ * <p>The list of results is in the same order as the input list.
273+ *
274+ * <p>Note that this method is a delegate of {@link Futures#allAsList(Iterable)}.
275+ *
276+ * @param futures Futures to combine
277+ * @return A future that provides a list of the results of the component futures
278+ * @see Futures#allAsList(Iterable)
279+ */
162280 public static <V > ApiFuture <List <V >> allAsList (
163281 Iterable <? extends ApiFuture <? extends V >> futures ) {
164282 return new ListenableFutureToApiFuture <>(
@@ -172,6 +290,21 @@ public ListenableFuture<? extends V> apply(ApiFuture<? extends V> apiFuture) {
172290 })));
173291 }
174292
293+ /**
294+ * Creates a new {@code ApiFuture} whose value is a list containing the values of all its
295+ * successful input futures. The list of results is in the same order as the input list, and if
296+ * any of the provided futures fails or is canceled, its corresponding position will contain
297+ * {@code null} (which is indistinguishable from the future having a successful value of {@code
298+ * null}).
299+ *
300+ * <p>The list of results is in the same order as the input list.
301+ *
302+ * <p>Note that this method is a delegate of {@link Futures#successfulAsList(Iterable)}.
303+ *
304+ * @param futures Futures to combine
305+ * @return A future that provides a list of the results of the component futures
306+ * @see Futures#successfulAsList(Iterable)
307+ */
175308 @ BetaApi
176309 public static <V > ApiFuture <List <V >> successfulAsList (
177310 Iterable <? extends ApiFuture <? extends V >> futures ) {
@@ -186,18 +319,43 @@ public ListenableFuture<? extends V> apply(ApiFuture<? extends V> apiFuture) {
186319 })));
187320 }
188321
189- /*
190- * @deprecated Use {@linkplain #transformAsync(ApiFuture, ApiFunction, Executor) the
191- * overload that requires an executor}. For identical behavior, pass {@link
192- * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
193- * another executor would be safer.
322+ /**
323+ * Returns a new {@code ApiFuture} whose result is asynchronously derived from the result of the
324+ * given {@code ApiFuture}. If the given {@code Future} fails, the returned {@code ApiFuture}
325+ * fails with the same exception (and the function is not invoked).
326+ *
327+ * @param input The future to transform
328+ * @param function A function to transform the result of the input future to the result of the
329+ * output future
330+ * @return A future that holds result of the function (if the input succeeded) or the original
331+ * input's failure (if not)
332+ * @deprecated Use {@linkplain #transformAsync(ApiFuture, ApiAsyncFunction, Executor)}, the
333+ * overload that requires an executor. For identical behavior, pass {@link
334+ * com.google.common.util.concurrent.MoreExecutors#directExecutor}, but consider whether
335+ * another executor would be safer.
194336 */
195337 @ Deprecated
196338 public static <I , O > ApiFuture <O > transformAsync (
197339 ApiFuture <I > input , final ApiAsyncFunction <I , O > function ) {
198340 return transformAsync (input , function , directExecutor ());
199341 }
200342
343+ /**
344+ * Returns a new {@code ApiFuture} whose result is asynchronously derived from the result of the
345+ * given {@code ApiFuture}. If the given {@code Future} fails, the returned {@code ApiFuture}
346+ * fails with the same exception (and the function is not invoked).
347+ *
348+ * <p>Note that this method is a delegate of {@link Futures#transformAsync(ListenableFuture,
349+ * AsyncFunction, Executor)}.
350+ *
351+ * @param input The future to transform
352+ * @param function A function to transform the result of the input future to the result of the
353+ * output future
354+ * @param executor Executor to run the function in.
355+ * @return A future that holds result of the function (if the input succeeded) or the original
356+ * input's failure (if not)
357+ * @see Futures#transformAsync(ListenableFuture, AsyncFunction, Executor)
358+ */
201359 public static <I , O > ApiFuture <O > transformAsync (
202360 ApiFuture <I > input , final ApiAsyncFunction <I , O > function , Executor executor ) {
203361 ListenableFuture <I > listenableInput = listenableFutureForApiFuture (input );
0 commit comments