mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 17:42:33 -06:00
269 lines
9.1 KiB
Java
269 lines
9.1 KiB
Java
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<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) {
|
|
this.iterableDelegate = Optional.of(iterable);
|
|
}
|
|
|
|
private Iterable<E> getDelegate() {
|
|
return this.iterableDelegate.or((Optional<Iterable<E>>) this);
|
|
}
|
|
|
|
public static <E> FluentIterable<E> from(final Iterable<E> iterable) {
|
|
if (iterable instanceof FluentIterable) {
|
|
return (FluentIterable) iterable;
|
|
}
|
|
return new FluentIterable<E>(iterable) { // from class: com.google.common.collect.FluentIterable.1
|
|
@Override // java.lang.Iterable
|
|
public Iterator<E> iterator() {
|
|
return 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(final Iterable<? extends Iterable<? extends T>> iterable) {
|
|
Preconditions.checkNotNull(iterable);
|
|
return new FluentIterable<T>() { // from class: com.google.common.collect.FluentIterable.2
|
|
@Override // java.lang.Iterable
|
|
public Iterator<T> iterator() {
|
|
return Iterators.concat(Iterators.transform(iterable.iterator(), Iterables.toIterator()));
|
|
}
|
|
};
|
|
}
|
|
|
|
private static <T> FluentIterable<T> concatNoDefensiveCopy(final Iterable<? extends T>... iterableArr) {
|
|
for (Iterable<? extends T> iterable : iterableArr) {
|
|
Preconditions.checkNotNull(iterable);
|
|
}
|
|
return new FluentIterable<T>() { // from class: com.google.common.collect.FluentIterable.3
|
|
@Override // java.lang.Iterable
|
|
public Iterator<T> iterator() {
|
|
return Iterators.concat(new AbstractIndexedListIterator<Iterator<? extends T>>(iterableArr.length) { // from class: com.google.common.collect.FluentIterable.3.1
|
|
@Override // com.google.common.collect.AbstractIndexedListIterator
|
|
public Iterator<? extends T> get(int i) {
|
|
return iterableArr[i].iterator();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
public static <E> FluentIterable<E> of() {
|
|
return from(Collections.emptyList());
|
|
}
|
|
|
|
public static <E> FluentIterable<E> 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<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);
|
|
}
|
|
|
|
@ParametricNullness
|
|
public final E get(int i) {
|
|
return (E) Iterables.get(getDelegate(), i);
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private 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);
|
|
}
|
|
}
|
|
}
|