Skip to content

Commit

Permalink
Merge 999dd53 into d95b3f5
Browse files Browse the repository at this point in the history
  • Loading branch information
spkrka committed Dec 10, 2015
2 parents d95b3f5 + 999dd53 commit 3beaa82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/spotify/futures/FuturesExtra.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public ListenableFuture<A> apply(B value) throws Exception {
* @return a new future with the result of the first completing future.
* @throws NullPointerException if the {@param futures} is null
*/
public static <T> ListenableFuture<T> select(final List<ListenableFuture<T>> futures) {
public static <T> ListenableFuture<T> select(final List<? extends ListenableFuture<T>> futures) {
Preconditions.checkNotNull(futures);
if (futures.isEmpty()) {
return Futures.immediateFailedFuture(new NoSuchElementException("List is empty"));
Expand Down Expand Up @@ -590,12 +590,12 @@ public interface AsyncFunction6<Z, A, B, C, D, E, F> {
ListenableFuture<Z> apply(A a, B b, C c, D d, E e, F f) throws Exception;
}

private static <Z> ListenableFuture<Z> transform(final List<ListenableFuture<?>> inputs,
private static <Z> ListenableFuture<Z> transform(final List<? extends ListenableFuture<?>> inputs,
final Function<List<Object>, Z> function) {
return Futures.transform(Futures.allAsList(inputs), function);
}

private static <Z> ListenableFuture<Z> transform(final List<ListenableFuture<?>> inputs,
private static <Z> ListenableFuture<Z> transform(final List<? extends ListenableFuture<?>> inputs,
final AsyncFunction<List<Object>, Z> function) {
return Futures.transform(Futures.allAsList(inputs), function);
}
Expand All @@ -606,7 +606,7 @@ private static <Z> ListenableFuture<Z> transform(final List<ListenableFuture<?>>
* the join is accessed.</p>
* @see #join(ListenableFuture...)
*/
public static <T> ListenableFuture<JoinedResults> join(List<ListenableFuture<T>> inputs) {
public static ListenableFuture<JoinedResults> join(List<? extends ListenableFuture<?>> inputs) {
return Futures.transform(Futures.allAsList(inputs), new JoinedResults.Transform(inputs));
}

Expand All @@ -626,7 +626,7 @@ public static <T> ListenableFuture<JoinedResults> join(List<ListenableFuture<T>>
* </pre>
*/
public static ListenableFuture<JoinedResults> join(ListenableFuture<?>... inputs) {
List<ListenableFuture<?>> list = Arrays.asList(inputs);
List<? extends ListenableFuture<?>> list = Arrays.asList(inputs);
return Futures.transform(Futures.allAsList(list), new JoinedResults.Transform(list));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/spotify/futures/JoinedResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public <T> T get(ListenableFuture<T> future) {
return t;
}

static class Transform<T> implements Function<List<Object>, JoinedResults> {
private final List<ListenableFuture<T>> futures;
public Transform(List<ListenableFuture<T>> list) {
static class Transform implements Function<List<Object>, JoinedResults> {
private final List<? extends ListenableFuture<?>> futures;
public Transform(List<? extends ListenableFuture<?>> list) {
futures = ImmutableList.copyOf(list);
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/spotify/futures/jdk7/JoinedResultsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.spotify.futures.jdk7;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -26,6 +27,7 @@

import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;

import com.spotify.futures.FuturesExtra;
import com.spotify.futures.JoinedResults;
Expand Down Expand Up @@ -55,6 +57,24 @@ public void testWithList() throws Exception {
assertEquals("b", joined.get(futureB));
}

@Test
public void testWithListOfSpecific() throws Exception {
SettableFuture<String> futureA = SettableFuture.create();
SettableFuture<String> futureB = SettableFuture.create();
List<SettableFuture<String>> list = Arrays.asList(futureA, futureB);

final ListenableFuture<JoinedResults> joinFuture = FuturesExtra.join(list);
assertFalse(joinFuture.isDone());

futureA.set("a");
futureB.set("b");

JoinedResults joined = joinFuture.get();

assertEquals("a", joined.get(futureA));
assertEquals("b", joined.get(futureB));
}

@Test
public void testNullTypes() throws Exception {
ListenableFuture<String> nullable = Futures.immediateFuture(null);
Expand Down

0 comments on commit 3beaa82

Please sign in to comment.