jimu-decompiled/sources/com/google/common/collect/Iterables.java
2025-05-13 19:24:51 +02:00

148 lines
5.4 KiB
Java

package com.google.common.collect;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/* loaded from: classes.dex */
public final class Iterables {
static <T> T[] a(Iterable<? extends T> iterable, T[] tArr) {
return (T[]) a(iterable).toArray(tArr);
}
public static <T> Iterable<T> b(final Iterable<T> iterable, final Predicate<? super T> predicate) {
Preconditions.a(iterable);
Preconditions.a(predicate);
return new FluentIterable<T>() { // from class: com.google.common.collect.Iterables.4
@Override // java.lang.Iterable
public Iterator<T> iterator() {
return Iterators.b((Iterator) iterable.iterator(), predicate);
}
};
}
public static <T> T c(Iterable<T> iterable) {
return (T) Iterators.e(iterable.iterator());
}
public static boolean d(Iterable<?> iterable) {
return iterable instanceof Collection ? ((Collection) iterable).isEmpty() : !iterable.iterator().hasNext();
}
static Object[] e(Iterable<?> iterable) {
return a(iterable).toArray();
}
public static String f(Iterable<?> iterable) {
return Iterators.i(iterable.iterator());
}
private static <E> Collection<E> a(Iterable<E> iterable) {
return iterable instanceof Collection ? (Collection) iterable : Lists.a(iterable.iterator());
}
public static <T> T b(Iterable<T> iterable) {
if (iterable instanceof List) {
List list = (List) iterable;
if (!list.isEmpty()) {
return (T) a(list);
}
throw new NoSuchElementException();
}
return (T) Iterators.d(iterable.iterator());
}
public static <T> boolean a(Collection<T> collection, Iterable<? extends T> iterable) {
if (iterable instanceof Collection) {
return collection.addAll(Collections2.a(iterable));
}
Preconditions.a(iterable);
return Iterators.a(collection, iterable.iterator());
}
public static <T> Iterable<T> a(Iterable<? extends T> iterable, Iterable<? extends T> iterable2) {
return FluentIterable.a(iterable, iterable2);
}
public static <T> boolean a(Iterable<T> iterable, Predicate<? super T> predicate) {
return Iterators.a(iterable.iterator(), predicate);
}
public static <F, T> Iterable<T> a(final Iterable<F> iterable, final Function<? super F, ? extends T> function) {
Preconditions.a(iterable);
Preconditions.a(function);
return new FluentIterable<T>() { // from class: com.google.common.collect.Iterables.6
@Override // java.lang.Iterable
public Iterator<T> iterator() {
return Iterators.a(iterable.iterator(), function);
}
};
}
public static <T> T a(Iterable<? extends T> iterable, T t) {
return (T) Iterators.b(iterable.iterator(), t);
}
private static <T> T a(List<T> list) {
return list.get(list.size() - 1);
}
public static <T> Iterable<T> a(final Iterable<T> iterable, final int i) {
Preconditions.a(iterable);
Preconditions.a(i >= 0, "number to skip cannot be negative");
if (iterable instanceof List) {
final List list = (List) iterable;
return new FluentIterable<T>() { // from class: com.google.common.collect.Iterables.7
@Override // java.lang.Iterable
public Iterator<T> iterator() {
int min = Math.min(list.size(), i);
List list2 = list;
return list2.subList(min, list2.size()).iterator();
}
};
}
return new FluentIterable<T>() { // from class: com.google.common.collect.Iterables.8
@Override // java.lang.Iterable
public Iterator<T> iterator() {
final Iterator<T> it = iterable.iterator();
Iterators.a((Iterator<?>) it, i);
return new Iterator<T>(this) { // from class: com.google.common.collect.Iterables.8.1
boolean a = true;
@Override // java.util.Iterator
public boolean hasNext() {
return it.hasNext();
}
@Override // java.util.Iterator
public T next() {
T t = (T) it.next();
this.a = false;
return t;
}
@Override // java.util.Iterator
public void remove() {
CollectPreconditions.a(!this.a);
it.remove();
}
};
}
};
}
static <T> Function<Iterable<? extends T>, Iterator<? extends T>> a() {
return new Function<Iterable<? extends T>, Iterator<? extends T>>() { // from class: com.google.common.collect.Iterables.13
@Override // com.google.common.base.Function
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Iterator<? extends T> apply(Iterable<? extends T> iterable) {
return iterable.iterator();
}
};
}
}