Skip to content

Commit

Permalink
More generics fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka committed Nov 6, 2015
1 parent 3e30cc3 commit ab6d452
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/spotify/futures/CompletableFuturesExtra.java
Expand Up @@ -97,14 +97,14 @@ public static <T> CompletableFuture<T> exceptionallyCompletedFuture(Throwable th
*/
public static <T, U> CompletionStage<U> handleCompose(
CompletionStage<T> future,
final BiFunction<? super T, Throwable, ? extends CompletionStage<? extends U>> fn) {
final BiFunction<? super T, Throwable, ? extends CompletionStage<U>> fn) {

final CompletableFuture<U> result = new CompletableFuture<U>();

future.whenComplete(new BiConsumer<T, Throwable>() {
@Override
public void accept(T value, Throwable throwable) {
final CompletionStage<? extends U> newStage;
final CompletionStage<U> newStage;
try {
newStage = fn.apply(value, throwable);
} catch (Throwable e) {
Expand Down Expand Up @@ -149,10 +149,10 @@ public void accept(U value, Throwable throwable) {
*/
public static <T> CompletionStage<T> exceptionallyCompose(
CompletionStage<T> future,
final Function<Throwable, ? extends CompletionStage<? extends T>> fn) {
return handleCompose(future, new BiFunction<T, Throwable, CompletionStage<? extends T>>() {
final Function<Throwable, ? extends CompletionStage<T>> fn) {
return handleCompose(future, new BiFunction<T, Throwable, CompletionStage<T>>() {
@Override
public CompletionStage<? extends T> apply(T value, Throwable throwable) {
public CompletionStage<T> apply(T value, Throwable throwable) {
if (throwable != null) {
return fn.apply(throwable);
} else {
Expand All @@ -169,12 +169,12 @@ public CompletionStage<? extends T> apply(T value, Throwable throwable) {
* @return the completion stage of a value
*/
public static <T> CompletionStage<T> dereference(
CompletionStage<? extends CompletionStage<? extends T>> future) {
CompletionStage<? extends CompletionStage<T>> future) {
return handleCompose(future,
new BiFunction<CompletionStage<? extends T>, Throwable, CompletionStage<? extends T>>() {
new BiFunction<CompletionStage<T>, Throwable, CompletionStage<T>>() {
@Override
public CompletionStage<? extends T> apply(
CompletionStage<? extends T> value, Throwable throwable) {
public CompletionStage<T> apply(
CompletionStage<T> value, Throwable throwable) {
return value;
}
});
Expand Down
Expand Up @@ -232,9 +232,9 @@ public CompletionStage<String> apply(Throwable throwable) {
public void testHandleCompose() throws Exception {
final CompletionStage<String> future = CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalArgumentException());

final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<? extends String>>() {
final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<String>>() {
@Override
public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public CompletionStage<String> apply(String s, Throwable throwable) {
return CompletableFuture.completedFuture("hello");
}
});
Expand All @@ -247,9 +247,9 @@ public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public void testHandleComposeFailure() throws Exception {
final CompletionStage<String> future = CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalArgumentException());

final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<? extends String>>() {
final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<String>>() {
@Override
public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public CompletionStage<String> apply(String s, Throwable throwable) {
return CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalStateException());
}
});
Expand All @@ -261,9 +261,9 @@ public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public void testHandleComposeThrows() throws Exception {
final CompletionStage<String> future = CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalArgumentException());

final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<? extends String>>() {
final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<String>>() {
@Override
public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public CompletionStage<String> apply(String s, Throwable throwable) {
throw new IllegalStateException();
}
});
Expand All @@ -275,9 +275,9 @@ public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public void testHandleComposeReturnsNull() throws Exception {
final CompletionStage<String> future = CompletableFuturesExtra.exceptionallyCompletedFuture(new IllegalArgumentException());

final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<? extends String>>() {
final CompletionStage<String> composed = CompletableFuturesExtra.handleCompose(future, new BiFunction<String, Throwable, CompletionStage<String>>() {
@Override
public CompletionStage<? extends String> apply(String s, Throwable throwable) {
public CompletionStage<String> apply(String s, Throwable throwable) {
return null;
}
});
Expand Down

0 comments on commit ab6d452

Please sign in to comment.