package com.google.common.util.concurrent; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.util.concurrent.AggregateFuture; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /* loaded from: classes2.dex */ abstract class CollectionFuture extends AggregateFuture { private List> values; abstract C combine(List> list); CollectionFuture(ImmutableCollection> immutableCollection, boolean z) { super(immutableCollection, z, true); List> newArrayListWithCapacity; if (immutableCollection.isEmpty()) { newArrayListWithCapacity = ImmutableList.of(); } else { newArrayListWithCapacity = Lists.newArrayListWithCapacity(immutableCollection.size()); } List> list = newArrayListWithCapacity; for (int i = 0; i < immutableCollection.size(); i++) { list.add(null); } this.values = list; } @Override // com.google.common.util.concurrent.AggregateFuture final void collectOneValue(int i, V v) { List> list = this.values; if (list != null) { list.set(i, new Present<>(v)); } } @Override // com.google.common.util.concurrent.AggregateFuture final void handleAllCompleted() { List> list = this.values; if (list != null) { set(combine(list)); } } @Override // com.google.common.util.concurrent.AggregateFuture void releaseResources(AggregateFuture.ReleaseResourcesReason releaseResourcesReason) { super.releaseResources(releaseResourcesReason); this.values = null; } /* loaded from: classes2.dex */ static final class ListFuture extends CollectionFuture> { /* JADX INFO: Access modifiers changed from: package-private */ public ListFuture(ImmutableCollection> immutableCollection, boolean z) { super(immutableCollection, z); init(); } @Override // com.google.common.util.concurrent.CollectionFuture public final List combine(List> list) { ArrayList newArrayListWithCapacity = Lists.newArrayListWithCapacity(list.size()); Iterator> it = list.iterator(); while (it.hasNext()) { Present next = it.next(); newArrayListWithCapacity.add(next != null ? next.value : null); } return Collections.unmodifiableList(newArrayListWithCapacity); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class Present { V value; Present(V v) { this.value = v; } } }