what-the-bank/sources/com/google/common/util/concurrent/CollectionFuture.java

85 lines
3.0 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
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<V, C> extends AggregateFuture<V, C> {
private List<Present<V>> values;
abstract C combine(List<Present<V>> list);
CollectionFuture(ImmutableCollection<? extends ListenableFuture<? extends V>> immutableCollection, boolean z) {
super(immutableCollection, z, true);
List<Present<V>> newArrayListWithCapacity;
if (immutableCollection.isEmpty()) {
newArrayListWithCapacity = ImmutableList.of();
} else {
newArrayListWithCapacity = Lists.newArrayListWithCapacity(immutableCollection.size());
}
List<Present<V>> 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<Present<V>> list = this.values;
if (list != null) {
list.set(i, new Present<>(v));
}
}
@Override // com.google.common.util.concurrent.AggregateFuture
final void handleAllCompleted() {
List<Present<V>> 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<V> extends CollectionFuture<V, List<V>> {
/* JADX INFO: Access modifiers changed from: package-private */
public ListFuture(ImmutableCollection<? extends ListenableFuture<? extends V>> immutableCollection, boolean z) {
super(immutableCollection, z);
init();
}
@Override // com.google.common.util.concurrent.CollectionFuture
public final List<V> combine(List<Present<V>> list) {
ArrayList newArrayListWithCapacity = Lists.newArrayListWithCapacity(list.size());
Iterator<Present<V>> it = list.iterator();
while (it.hasNext()) {
Present<V> 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> {
V value;
Present(V v) {
this.value = v;
}
}
}