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 implements Iterable { private final Optional> iterableDelegate; /* JADX INFO: Access modifiers changed from: protected */ public FluentIterable() { this.iterableDelegate = Optional.absent(); } FluentIterable(Iterable iterable) { Preconditions.checkNotNull(iterable); this.iterableDelegate = Optional.fromNullable(this == iterable ? null : iterable); } private Iterable getDelegate() { return this.iterableDelegate.or((Optional>) this); } public static FluentIterable from(Iterable iterable) { if (iterable instanceof FluentIterable) { return (FluentIterable) iterable; } return new FluentIterable(iterable, iterable) { // from class: com.google.common.collect.FluentIterable.1 final Iterable val$iterable; { this.val$iterable = iterable; } @Override // java.lang.Iterable public Iterator iterator() { return this.val$iterable.iterator(); } }; } public static FluentIterable from(E[] eArr) { return from(Arrays.asList(eArr)); } @Deprecated public static FluentIterable from(FluentIterable fluentIterable) { return (FluentIterable) Preconditions.checkNotNull(fluentIterable); } public static FluentIterable concat(Iterable iterable, Iterable iterable2) { return concatNoDefensiveCopy(iterable, iterable2); } public static FluentIterable concat(Iterable iterable, Iterable iterable2, Iterable iterable3) { return concatNoDefensiveCopy(iterable, iterable2, iterable3); } public static FluentIterable concat(Iterable iterable, Iterable iterable2, Iterable iterable3, Iterable iterable4) { return concatNoDefensiveCopy(iterable, iterable2, iterable3, iterable4); } public static FluentIterable concat(Iterable... iterableArr) { return concatNoDefensiveCopy((Iterable[]) Arrays.copyOf(iterableArr, iterableArr.length)); } public static FluentIterable concat(Iterable> iterable) { Preconditions.checkNotNull(iterable); return new FluentIterable(iterable) { // from class: com.google.common.collect.FluentIterable.2 final Iterable val$inputs; { this.val$inputs = iterable; } @Override // java.lang.Iterable public Iterator iterator() { return Iterators.concat(Iterators.transform(this.val$inputs.iterator(), Iterables.toIterator())); } }; } private static FluentIterable concatNoDefensiveCopy(Iterable... iterableArr) { for (Iterable 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 extends FluentIterable { final Iterable[] val$inputs; AnonymousClass3(Iterable[] iterableArr) { this.val$inputs = iterableArr; } @Override // java.lang.Iterable public Iterator iterator() { return Iterators.concat(new AbstractIndexedListIterator>(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 get(int i) { return this.this$0.val$inputs[i].iterator(); } }); } } public static FluentIterable of() { return from(ImmutableList.of()); } public static FluentIterable 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 cycle() { return from(Iterables.cycle(getDelegate())); } public final FluentIterable append(Iterable iterable) { return concat(getDelegate(), iterable); } public final FluentIterable append(E... eArr) { return concat(getDelegate(), Arrays.asList(eArr)); } public final FluentIterable filter(Predicate predicate) { return from(Iterables.filter(getDelegate(), predicate)); } public final FluentIterable filter(Class cls) { return from(Iterables.filter((Iterable) getDelegate(), (Class) cls)); } public final boolean anyMatch(Predicate predicate) { return Iterables.any(getDelegate(), predicate); } public final boolean allMatch(Predicate predicate) { return Iterables.all(getDelegate(), predicate); } public final Optional firstMatch(Predicate predicate) { return Iterables.tryFind(getDelegate(), predicate); } public final FluentIterable transform(Function function) { return from(Iterables.transform(getDelegate(), function)); } /* JADX WARN: Multi-variable type inference failed */ public FluentIterable transformAndConcat(Function> function) { return concat(transform(function)); } public final Optional first() { Iterator it = getDelegate().iterator(); return it.hasNext() ? Optional.of(it.next()) : Optional.absent(); } public final Optional last() { E next; Iterable 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 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 skip(int i) { return from(Iterables.skip(getDelegate(), i)); } public final FluentIterable limit(int i) { return from(Iterables.limit(getDelegate(), i)); } public final boolean isEmpty() { return !getDelegate().iterator().hasNext(); } public final ImmutableList toList() { return ImmutableList.copyOf(getDelegate()); } public final ImmutableList toSortedList(Comparator comparator) { return Ordering.from(comparator).immutableSortedCopy(getDelegate()); } public final ImmutableSet toSet() { return ImmutableSet.copyOf(getDelegate()); } public final ImmutableSortedSet toSortedSet(Comparator comparator) { return ImmutableSortedSet.copyOf(comparator, getDelegate()); } public final ImmutableMultiset toMultiset() { return ImmutableMultiset.copyOf(getDelegate()); } public final ImmutableMap toMap(Function function) { return Maps.toMap(getDelegate(), function); } public final ImmutableListMultimap index(Function function) { return Multimaps.index(getDelegate(), function); } public final ImmutableMap uniqueIndex(Function function) { return Maps.uniqueIndex(getDelegate(), function); } public final E[] toArray(Class cls) { return (E[]) Iterables.toArray(getDelegate(), cls); } public final > C copyInto(C c) { Preconditions.checkNotNull(c); Iterable delegate = getDelegate(); if (delegate instanceof Collection) { c.addAll((Collection) delegate); } else { Iterator 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 implements Function, FluentIterable> { private FromIterableFunction() { } @Override // com.google.common.base.Function public FluentIterable apply(Iterable iterable) { return FluentIterable.from(iterable); } } }