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.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.SortedSet; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes3.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) { this.iterableDelegate = Optional.of(iterable); } private Iterable getDelegate() { return this.iterableDelegate.or((Optional>) this); } public static FluentIterable from(final Iterable iterable) { if (iterable instanceof FluentIterable) { return (FluentIterable) iterable; } return new FluentIterable(iterable) { // from class: com.google.common.collect.FluentIterable.1 @Override // java.lang.Iterable public Iterator iterator() { return 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(final Iterable> iterable) { Preconditions.checkNotNull(iterable); return new FluentIterable() { // from class: com.google.common.collect.FluentIterable.2 @Override // java.lang.Iterable public Iterator iterator() { return Iterators.concat(Iterators.transform(iterable.iterator(), Iterables.toIterator())); } }; } private static FluentIterable concatNoDefensiveCopy(final Iterable... iterableArr) { for (Iterable iterable : iterableArr) { Preconditions.checkNotNull(iterable); } return new FluentIterable() { // from class: com.google.common.collect.FluentIterable.3 @Override // java.lang.Iterable public Iterator iterator() { return Iterators.concat(new AbstractIndexedListIterator>(iterableArr.length) { // from class: com.google.common.collect.FluentIterable.3.1 @Override // com.google.common.collect.AbstractIndexedListIterator public Iterator get(int i) { return iterableArr[i].iterator(); } }); } }; } public static FluentIterable of() { return from(Collections.emptyList()); } public static FluentIterable of(@ParametricNullness 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(@CheckForNull 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); } @ParametricNullness public final E get(int i) { return (E) Iterables.get(getDelegate(), i); } /* loaded from: classes3.dex */ private static class FromIterableFunction implements Function, FluentIterable> { private FromIterableFunction() { } @Override // com.google.common.base.Function public FluentIterable apply(Iterable iterable) { return FluentIterable.from(iterable); } } }