345 |
|
/** |
346 |
|
* Reports result using Future.get conventions. |
347 |
|
*/ |
348 |
< |
private static <T> T reportGet(Object r) |
348 |
> |
private static Object reportGet(Object r) |
349 |
|
throws InterruptedException, ExecutionException { |
350 |
|
if (r == null) // by convention below, null means interrupted |
351 |
|
throw new InterruptedException(); |
360 |
|
x = cause; |
361 |
|
throw new ExecutionException(x); |
362 |
|
} |
363 |
< |
@SuppressWarnings("unchecked") T t = (T) r; |
364 |
< |
return t; |
363 |
> |
return r; |
364 |
|
} |
365 |
|
|
366 |
|
/** |
367 |
|
* Decodes outcome to return result or throw unchecked exception. |
368 |
|
*/ |
369 |
< |
private static <T> T reportJoin(Object r) { |
369 |
> |
private static Object reportJoin(Object r) { |
370 |
|
if (r instanceof AltResult) { |
371 |
|
Throwable x; |
372 |
|
if ((x = ((AltResult)r).ex) == null) |
377 |
|
throw (CompletionException)x; |
378 |
|
throw new CompletionException(x); |
379 |
|
} |
380 |
< |
@SuppressWarnings("unchecked") T t = (T) r; |
382 |
< |
return t; |
380 |
> |
return r; |
381 |
|
} |
382 |
|
|
383 |
|
/* ------------- Async task preliminaries -------------- */ |
2012 |
|
* @throws InterruptedException if the current thread was interrupted |
2013 |
|
* while waiting |
2014 |
|
*/ |
2015 |
+ |
@SuppressWarnings("unchecked") |
2016 |
|
public T get() throws InterruptedException, ExecutionException { |
2017 |
|
Object r; |
2018 |
< |
return reportGet((r = result) == null ? waitingGet(true) : r); |
2018 |
> |
return (T) reportGet((r = result) == null ? waitingGet(true) : r); |
2019 |
|
} |
2020 |
|
|
2021 |
|
/** |
2031 |
|
* while waiting |
2032 |
|
* @throws TimeoutException if the wait timed out |
2033 |
|
*/ |
2034 |
+ |
@SuppressWarnings("unchecked") |
2035 |
|
public T get(long timeout, TimeUnit unit) |
2036 |
|
throws InterruptedException, ExecutionException, TimeoutException { |
2037 |
|
Object r; |
2038 |
|
long nanos = unit.toNanos(timeout); |
2039 |
< |
return reportGet((r = result) == null ? timedGet(nanos) : r); |
2039 |
> |
return (T) reportGet((r = result) == null ? timedGet(nanos) : r); |
2040 |
|
} |
2041 |
|
|
2042 |
|
/** |
2053 |
|
* @throws CompletionException if this future completed |
2054 |
|
* exceptionally or a completion computation threw an exception |
2055 |
|
*/ |
2056 |
+ |
@SuppressWarnings("unchecked") |
2057 |
|
public T join() { |
2058 |
|
Object r; |
2059 |
< |
return reportJoin((r = result) == null ? waitingGet(false) : r); |
2059 |
> |
return (T) reportJoin((r = result) == null ? waitingGet(false) : r); |
2060 |
|
} |
2061 |
|
|
2062 |
|
/** |
2069 |
|
* @throws CompletionException if this future completed |
2070 |
|
* exceptionally or a completion computation threw an exception |
2071 |
|
*/ |
2072 |
+ |
@SuppressWarnings("unchecked") |
2073 |
|
public T getNow(T valueIfAbsent) { |
2074 |
|
Object r; |
2075 |
< |
return ((r = result) == null) ? valueIfAbsent : reportJoin(r); |
2075 |
> |
return ((r = result) == null) ? valueIfAbsent : (T) reportJoin(r); |
2076 |
|
} |
2077 |
|
|
2078 |
|
/** |