what-the-bank/sources/com/google/common/collect/FluentIterable.java

297 lines
9.8 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
/* loaded from: classes2.dex */
public abstract class FluentIterable<E> implements Iterable<E> {
private final Optional<Iterable<E>> iterableDelegate;
/* JADX INFO: Access modifiers changed from: protected */
public FluentIterable() {
this.iterableDelegate = Optional.absent();
}
FluentIterable(Iterable<E> iterable) {
Preconditions.checkNotNull(iterable);
this.iterableDelegate = Optional.fromNullable(this == iterable ? null : iterable);
}
private Iterable<E> getDelegate() {
return this.iterableDelegate.or((Optional<Iterable<E>>) this);
}
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
if (iterable instanceof FluentIterable) {
return (FluentIterable) iterable;
}
return new FluentIterable<E>(iterable, iterable) { // from class: com.google.common.collect.FluentIterable.1
final Iterable val$iterable;
{
this.val$iterable = iterable;
}
@Override // java.lang.Iterable
public Iterator<E> iterator() {
return this.val$iterable.iterator();
}
};
}
public static <E> FluentIterable<E> from(E[] eArr) {
return from(Arrays.asList(eArr));
}
@Deprecated
public static <E> FluentIterable<E> from(FluentIterable<E> fluentIterable) {
return (FluentIterable) Preconditions.checkNotNull(fluentIterable);
}
public static <T> FluentIterable<T> concat(Iterable<? extends T> iterable, Iterable<? extends T> iterable2) {
return concatNoDefensiveCopy(iterable, iterable2);
}
public static <T> FluentIterable<T> concat(Iterable<? extends T> iterable, Iterable<? extends T> iterable2, Iterable<? extends T> iterable3) {
return concatNoDefensiveCopy(iterable, iterable2, iterable3);
}
public static <T> FluentIterable<T> concat(Iterable<? extends T> iterable, Iterable<? extends T> iterable2, Iterable<? extends T> iterable3, Iterable<? extends T> iterable4) {
return concatNoDefensiveCopy(iterable, iterable2, iterable3, iterable4);
}
public static <T> FluentIterable<T> concat(Iterable<? extends T>... iterableArr) {
return concatNoDefensiveCopy((Iterable[]) Arrays.copyOf(iterableArr, iterableArr.length));
}
public static <T> FluentIterable<T> concat(Iterable<? extends Iterable<? extends T>> iterable) {
Preconditions.checkNotNull(iterable);
return new FluentIterable<T>(iterable) { // from class: com.google.common.collect.FluentIterable.2
final Iterable val$inputs;
{
this.val$inputs = iterable;
}
@Override // java.lang.Iterable
public Iterator<T> iterator() {
return Iterators.concat(Iterators.transform(this.val$inputs.iterator(), Iterables.toIterator()));
}
};
}
private static <T> FluentIterable<T> concatNoDefensiveCopy(Iterable<? extends T>... iterableArr) {
for (Iterable<? extends T> iterable : iterableArr) {
Preconditions.checkNotNull(iterable);
}
return new AnonymousClass3(iterableArr);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: Add missing generic type declarations: [T] */
/* renamed from: com.google.common.collect.FluentIterable$3, reason: invalid class name */
/* loaded from: classes2.dex */
public class AnonymousClass3<T> extends FluentIterable<T> {
final Iterable[] val$inputs;
AnonymousClass3(Iterable[] iterableArr) {
this.val$inputs = iterableArr;
}
@Override // java.lang.Iterable
public Iterator<T> iterator() {
return Iterators.concat(new AbstractIndexedListIterator<Iterator<? extends T>>(this, this.val$inputs.length) { // from class: com.google.common.collect.FluentIterable.3.1
final AnonymousClass3 this$0;
{
this.this$0 = this;
}
@Override // com.google.common.collect.AbstractIndexedListIterator
public Iterator<? extends T> get(int i) {
return this.this$0.val$inputs[i].iterator();
}
});
}
}
public static <E> FluentIterable<E> of() {
return from(ImmutableList.of());
}
public static <E> FluentIterable<E> of(E e, E... eArr) {
return from(Lists.asList(e, eArr));
}
public String toString() {
return Iterables.toString(getDelegate());
}
public final int size() {
return Iterables.size(getDelegate());
}
public final boolean contains(Object obj) {
return Iterables.contains(getDelegate(), obj);
}
public final FluentIterable<E> cycle() {
return from(Iterables.cycle(getDelegate()));
}
public final FluentIterable<E> append(Iterable<? extends E> iterable) {
return concat(getDelegate(), iterable);
}
public final FluentIterable<E> append(E... eArr) {
return concat(getDelegate(), Arrays.asList(eArr));
}
public final FluentIterable<E> filter(Predicate<? super E> predicate) {
return from(Iterables.filter(getDelegate(), predicate));
}
public final <T> FluentIterable<T> filter(Class<T> cls) {
return from(Iterables.filter((Iterable<?>) getDelegate(), (Class) cls));
}
public final boolean anyMatch(Predicate<? super E> predicate) {
return Iterables.any(getDelegate(), predicate);
}
public final boolean allMatch(Predicate<? super E> predicate) {
return Iterables.all(getDelegate(), predicate);
}
public final Optional<E> firstMatch(Predicate<? super E> predicate) {
return Iterables.tryFind(getDelegate(), predicate);
}
public final <T> FluentIterable<T> transform(Function<? super E, T> function) {
return from(Iterables.transform(getDelegate(), function));
}
/* JADX WARN: Multi-variable type inference failed */
public <T> FluentIterable<T> transformAndConcat(Function<? super E, ? extends Iterable<? extends T>> function) {
return concat(transform(function));
}
public final Optional<E> first() {
Iterator<E> it = getDelegate().iterator();
return it.hasNext() ? Optional.of(it.next()) : Optional.absent();
}
public final Optional<E> last() {
E next;
Iterable<E> delegate = getDelegate();
if (delegate instanceof List) {
List list = (List) delegate;
if (list.isEmpty()) {
return Optional.absent();
}
return Optional.of(list.get(list.size() - 1));
}
Iterator<E> it = delegate.iterator();
if (!it.hasNext()) {
return Optional.absent();
}
if (delegate instanceof SortedSet) {
return Optional.of(((SortedSet) delegate).last());
}
do {
next = it.next();
} while (it.hasNext());
return Optional.of(next);
}
public final FluentIterable<E> skip(int i) {
return from(Iterables.skip(getDelegate(), i));
}
public final FluentIterable<E> limit(int i) {
return from(Iterables.limit(getDelegate(), i));
}
public final boolean isEmpty() {
return !getDelegate().iterator().hasNext();
}
public final ImmutableList<E> toList() {
return ImmutableList.copyOf(getDelegate());
}
public final ImmutableList<E> toSortedList(Comparator<? super E> comparator) {
return Ordering.from(comparator).immutableSortedCopy(getDelegate());
}
public final ImmutableSet<E> toSet() {
return ImmutableSet.copyOf(getDelegate());
}
public final ImmutableSortedSet<E> toSortedSet(Comparator<? super E> comparator) {
return ImmutableSortedSet.copyOf(comparator, getDelegate());
}
public final ImmutableMultiset<E> toMultiset() {
return ImmutableMultiset.copyOf(getDelegate());
}
public final <V> ImmutableMap<E, V> toMap(Function<? super E, V> function) {
return Maps.toMap(getDelegate(), function);
}
public final <K> ImmutableListMultimap<K, E> index(Function<? super E, K> function) {
return Multimaps.index(getDelegate(), function);
}
public final <K> ImmutableMap<K, E> uniqueIndex(Function<? super E, K> function) {
return Maps.uniqueIndex(getDelegate(), function);
}
public final E[] toArray(Class<E> cls) {
return (E[]) Iterables.toArray(getDelegate(), cls);
}
public final <C extends Collection<? super E>> C copyInto(C c) {
Preconditions.checkNotNull(c);
Iterable<E> delegate = getDelegate();
if (delegate instanceof Collection) {
c.addAll((Collection) delegate);
} else {
Iterator<E> it = delegate.iterator();
while (it.hasNext()) {
c.add(it.next());
}
}
return c;
}
public final String join(Joiner joiner) {
return joiner.join(this);
}
public final E get(int i) {
return (E) Iterables.get(getDelegate(), i);
}
/* loaded from: classes2.dex */
static class FromIterableFunction<E> implements Function<Iterable<E>, FluentIterable<E>> {
private FromIterableFunction() {
}
@Override // com.google.common.base.Function
public FluentIterable<E> apply(Iterable<E> iterable) {
return FluentIterable.from(iterable);
}
}
}