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

949 lines
31 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.primitives.Ints;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
/* loaded from: classes2.dex */
public final class Iterators {
private Iterators() {
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <T> UnmodifiableIterator<T> emptyIterator() {
return emptyListIterator();
}
static <T> UnmodifiableListIterator<T> emptyListIterator() {
return (UnmodifiableListIterator<T>) ArrayItr.EMPTY;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public enum EmptyModifiableIterator implements Iterator<Object> {
INSTANCE;
@Override // java.util.Iterator
public final boolean hasNext() {
return false;
}
@Override // java.util.Iterator
public final Object next() {
throw new NoSuchElementException();
}
@Override // java.util.Iterator
public final void remove() {
CollectPreconditions.checkRemove(false);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <T> Iterator<T> emptyModifiableIterator() {
return EmptyModifiableIterator.INSTANCE;
}
public static <T> UnmodifiableIterator<T> unmodifiableIterator(Iterator<? extends T> it) {
Preconditions.checkNotNull(it);
if (it instanceof UnmodifiableIterator) {
return (UnmodifiableIterator) it;
}
return new UnmodifiableIterator<T>(it) { // from class: com.google.common.collect.Iterators.1
final Iterator val$iterator;
{
this.val$iterator = it;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.val$iterator.hasNext();
}
@Override // java.util.Iterator
public T next() {
return (T) this.val$iterator.next();
}
};
}
@Deprecated
public static <T> UnmodifiableIterator<T> unmodifiableIterator(UnmodifiableIterator<T> unmodifiableIterator) {
return (UnmodifiableIterator) Preconditions.checkNotNull(unmodifiableIterator);
}
public static int size(Iterator<?> it) {
long j = 0;
while (it.hasNext()) {
it.next();
j++;
}
return Ints.saturatedCast(j);
}
/* JADX WARN: Code restructure failed: missing block: B:12:0x0021, code lost:
return false;
*/
/* JADX WARN: Code restructure failed: missing block: B:14:0x0014, code lost:
if (r2.hasNext() == false) goto L19;
*/
/* JADX WARN: Code restructure failed: missing block: B:16:0x001e, code lost:
if (r3.equals(r2.next()) == false) goto L21;
*/
/* JADX WARN: Code restructure failed: missing block: B:18:0x0020, code lost:
return true;
*/
/* JADX WARN: Code restructure failed: missing block: B:21:?, code lost:
return false;
*/
/* JADX WARN: Code restructure failed: missing block: B:2:0x0001, code lost:
if (r3 == null) goto L4;
*/
/* JADX WARN: Code restructure failed: missing block: B:4:0x0007, code lost:
if (r2.hasNext() == false) goto L16;
*/
/* JADX WARN: Code restructure failed: missing block: B:6:0x000d, code lost:
if (r2.next() != null) goto L18;
*/
/* JADX WARN: Code restructure failed: missing block: B:8:0x000f, code lost:
return true;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static boolean contains(java.util.Iterator<?> r2, java.lang.Object r3) {
/*
r0 = 1
if (r3 != 0) goto L10
L3:
boolean r3 = r2.hasNext()
if (r3 == 0) goto L21
java.lang.Object r3 = r2.next()
if (r3 != 0) goto L3
return r0
L10:
boolean r1 = r2.hasNext()
if (r1 == 0) goto L21
java.lang.Object r1 = r2.next()
boolean r1 = r3.equals(r1)
if (r1 == 0) goto L10
return r0
L21:
r2 = 0
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.collect.Iterators.contains(java.util.Iterator, java.lang.Object):boolean");
}
public static boolean removeAll(Iterator<?> it, Collection<?> collection) {
Preconditions.checkNotNull(collection);
boolean z = false;
while (it.hasNext()) {
if (collection.contains(it.next())) {
it.remove();
z = true;
}
}
return z;
}
public static <T> boolean removeIf(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(predicate);
boolean z = false;
while (it.hasNext()) {
if (predicate.apply(it.next())) {
it.remove();
z = true;
}
}
return z;
}
public static boolean retainAll(Iterator<?> it, Collection<?> collection) {
Preconditions.checkNotNull(collection);
boolean z = false;
while (it.hasNext()) {
if (!collection.contains(it.next())) {
it.remove();
z = true;
}
}
return z;
}
public static boolean elementsEqual(Iterator<?> it, Iterator<?> it2) {
while (it.hasNext()) {
if (!it2.hasNext() || !Objects.equal(it.next(), it2.next())) {
return false;
}
}
return !it2.hasNext();
}
public static String toString(Iterator<?> it) {
StringBuilder sb = new StringBuilder("[");
boolean z = true;
while (it.hasNext()) {
if (!z) {
sb.append(", ");
}
sb.append(it.next());
z = false;
}
sb.append(']');
return sb.toString();
}
public static <T> T getOnlyElement(Iterator<T> it) {
T next = it.next();
if (!it.hasNext()) {
return next;
}
StringBuilder sb = new StringBuilder("expected one element but was: <");
sb.append(next);
for (int i = 0; i < 4 && it.hasNext(); i++) {
sb.append(", ");
sb.append(it.next());
}
if (it.hasNext()) {
sb.append(", ...");
}
sb.append(UrlTreeKt.configurablePathSegmentSuffixChar);
throw new IllegalArgumentException(sb.toString());
}
public static <T> T getOnlyElement(Iterator<? extends T> it, T t) {
return it.hasNext() ? (T) getOnlyElement(it) : t;
}
public static <T> T[] toArray(Iterator<? extends T> it, Class<T> cls) {
return (T[]) Iterables.toArray(Lists.newArrayList(it), cls);
}
public static <T> boolean addAll(Collection<T> collection, Iterator<? extends T> it) {
Preconditions.checkNotNull(collection);
Preconditions.checkNotNull(it);
boolean z = false;
while (it.hasNext()) {
z |= collection.add(it.next());
}
return z;
}
public static int frequency(Iterator<?> it, Object obj) {
int i = 0;
while (contains(it, obj)) {
i++;
}
return i;
}
public static <T> Iterator<T> cycle(Iterable<T> iterable) {
Preconditions.checkNotNull(iterable);
return new Iterator<T>(iterable) { // from class: com.google.common.collect.Iterators.2
Iterator<T> iterator = Iterators.emptyModifiableIterator();
final Iterable val$iterable;
{
this.val$iterable = iterable;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.iterator.hasNext() || this.val$iterable.iterator().hasNext();
}
@Override // java.util.Iterator
public T next() {
if (!this.iterator.hasNext()) {
Iterator<T> it = this.val$iterable.iterator();
this.iterator = it;
if (!it.hasNext()) {
throw new NoSuchElementException();
}
}
return this.iterator.next();
}
@Override // java.util.Iterator
public void remove() {
this.iterator.remove();
}
};
}
@SafeVarargs
public static <T> Iterator<T> cycle(T... tArr) {
return cycle(Lists.newArrayList(tArr));
}
private static <T> Iterator<T> consumingForArray(T... tArr) {
return new UnmodifiableIterator<T>(tArr) { // from class: com.google.common.collect.Iterators.3
int index = 0;
final Object[] val$elements;
{
this.val$elements = tArr;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.index < this.val$elements.length;
}
@Override // java.util.Iterator
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object[] objArr = this.val$elements;
int i = this.index;
T t = (T) objArr[i];
objArr[i] = null;
this.index = i + 1;
return t;
}
};
}
public static <T> Iterator<T> concat(Iterator<? extends T> it, Iterator<? extends T> it2) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(it2);
return concat(consumingForArray(it, it2));
}
public static <T> Iterator<T> concat(Iterator<? extends T> it, Iterator<? extends T> it2, Iterator<? extends T> it3) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(it2);
Preconditions.checkNotNull(it3);
return concat(consumingForArray(it, it2, it3));
}
public static <T> Iterator<T> concat(Iterator<? extends T> it, Iterator<? extends T> it2, Iterator<? extends T> it3, Iterator<? extends T> it4) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(it2);
Preconditions.checkNotNull(it3);
Preconditions.checkNotNull(it4);
return concat(consumingForArray(it, it2, it3, it4));
}
public static <T> Iterator<T> concat(Iterator<? extends T>... itArr) {
return concatNoDefensiveCopy((Iterator[]) Arrays.copyOf(itArr, itArr.length));
}
public static <T> Iterator<T> concat(Iterator<? extends Iterator<? extends T>> it) {
return new ConcatenatedIterator(it);
}
static <T> Iterator<T> concatNoDefensiveCopy(Iterator<? extends T>... itArr) {
for (Iterator it : (Iterator[]) Preconditions.checkNotNull(itArr)) {
Preconditions.checkNotNull(it);
}
return concat(consumingForArray(itArr));
}
public static <T> UnmodifiableIterator<List<T>> partition(Iterator<T> it, int i) {
return partitionImpl(it, i, false);
}
public static <T> UnmodifiableIterator<List<T>> paddedPartition(Iterator<T> it, int i) {
return partitionImpl(it, i, true);
}
private static <T> UnmodifiableIterator<List<T>> partitionImpl(Iterator<T> it, int i, boolean z) {
Preconditions.checkNotNull(it);
Preconditions.checkArgument(i > 0);
return new UnmodifiableIterator<List<T>>(it, i, z) { // from class: com.google.common.collect.Iterators.4
final Iterator val$iterator;
final boolean val$pad;
final int val$size;
{
this.val$iterator = it;
this.val$size = i;
this.val$pad = z;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.val$iterator.hasNext();
}
@Override // java.util.Iterator
public List<T> next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object[] objArr = new Object[this.val$size];
int i2 = 0;
while (i2 < this.val$size && this.val$iterator.hasNext()) {
objArr[i2] = this.val$iterator.next();
i2++;
}
for (int i3 = i2; i3 < this.val$size; i3++) {
objArr[i3] = null;
}
List<T> unmodifiableList = Collections.unmodifiableList(Arrays.asList(objArr));
return (this.val$pad || i2 == this.val$size) ? unmodifiableList : unmodifiableList.subList(0, i2);
}
};
}
public static <T> UnmodifiableIterator<T> filter(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(predicate);
return new AbstractIterator<T>(it, predicate) { // from class: com.google.common.collect.Iterators.5
final Predicate val$retainIfTrue;
final Iterator val$unfiltered;
{
this.val$unfiltered = it;
this.val$retainIfTrue = predicate;
}
@Override // com.google.common.collect.AbstractIterator
protected T computeNext() {
while (this.val$unfiltered.hasNext()) {
T t = (T) this.val$unfiltered.next();
if (this.val$retainIfTrue.apply(t)) {
return t;
}
}
return endOfData();
}
};
}
public static <T> UnmodifiableIterator<T> filter(Iterator<?> it, Class<T> cls) {
return filter(it, Predicates.instanceOf(cls));
}
public static <T> boolean any(Iterator<T> it, Predicate<? super T> predicate) {
return indexOf(it, predicate) != -1;
}
public static <T> boolean all(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(predicate);
while (it.hasNext()) {
if (!predicate.apply(it.next())) {
return false;
}
}
return true;
}
public static <T> T find(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(predicate);
while (it.hasNext()) {
T next = it.next();
if (predicate.apply(next)) {
return next;
}
}
throw new NoSuchElementException();
}
/* JADX WARN: Type inference failed for: r0v1, types: [T, java.lang.Object] */
public static <T> T find(Iterator<? extends T> it, Predicate<? super T> predicate, T t) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(predicate);
while (it.hasNext()) {
T next = it.next();
if (predicate.apply(next)) {
return next;
}
}
return t;
}
public static <T> Optional<T> tryFind(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(it);
Preconditions.checkNotNull(predicate);
while (it.hasNext()) {
T next = it.next();
if (predicate.apply(next)) {
return Optional.of(next);
}
}
return Optional.absent();
}
public static <T> int indexOf(Iterator<T> it, Predicate<? super T> predicate) {
Preconditions.checkNotNull(predicate, "predicate");
int i = 0;
while (it.hasNext()) {
if (predicate.apply(it.next())) {
return i;
}
i++;
}
return -1;
}
public static <F, T> Iterator<T> transform(Iterator<F> it, Function<? super F, ? extends T> function) {
Preconditions.checkNotNull(function);
return new TransformedIterator<F, T>(it, function) { // from class: com.google.common.collect.Iterators.6
final Function val$function;
{
this.val$function = function;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // com.google.common.collect.TransformedIterator
public T transform(F f) {
return (T) this.val$function.apply(f);
}
};
}
public static <T> T get(Iterator<T> it, int i) {
checkNonnegative(i);
int advance = advance(it, i);
if (!it.hasNext()) {
StringBuilder sb = new StringBuilder(91);
sb.append("position (");
sb.append(i);
sb.append(") must be less than the number of elements that remained (");
sb.append(advance);
sb.append(")");
throw new IndexOutOfBoundsException(sb.toString());
}
return it.next();
}
public static <T> T get(Iterator<? extends T> it, int i, T t) {
checkNonnegative(i);
advance(it, i);
return (T) getNext(it, t);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static void checkNonnegative(int i) {
if (i >= 0) {
return;
}
StringBuilder sb = new StringBuilder(43);
sb.append("position (");
sb.append(i);
sb.append(") must not be negative");
throw new IndexOutOfBoundsException(sb.toString());
}
public static <T> T getNext(Iterator<? extends T> it, T t) {
return it.hasNext() ? it.next() : t;
}
public static <T> T getLast(Iterator<T> it) {
T next;
do {
next = it.next();
} while (it.hasNext());
return next;
}
public static <T> T getLast(Iterator<? extends T> it, T t) {
return it.hasNext() ? (T) getLast(it) : t;
}
public static int advance(Iterator<?> it, int i) {
Preconditions.checkNotNull(it);
int i2 = 0;
Preconditions.checkArgument(i >= 0, "numberToAdvance must be nonnegative");
while (i2 < i && it.hasNext()) {
it.next();
i2++;
}
return i2;
}
public static <T> Iterator<T> limit(Iterator<T> it, int i) {
Preconditions.checkNotNull(it);
Preconditions.checkArgument(i >= 0, "limit is negative");
return new Iterator<T>(i, it) { // from class: com.google.common.collect.Iterators.7
private int count;
final Iterator val$iterator;
final int val$limitSize;
{
this.val$limitSize = i;
this.val$iterator = it;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.count < this.val$limitSize && this.val$iterator.hasNext();
}
@Override // java.util.Iterator
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
this.count++;
return (T) this.val$iterator.next();
}
@Override // java.util.Iterator
public void remove() {
this.val$iterator.remove();
}
};
}
public static <T> Iterator<T> consumingIterator(Iterator<T> it) {
Preconditions.checkNotNull(it);
return new UnmodifiableIterator<T>(it) { // from class: com.google.common.collect.Iterators.8
final Iterator val$iterator;
{
this.val$iterator = it;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.val$iterator.hasNext();
}
@Override // java.util.Iterator
public T next() {
T t = (T) this.val$iterator.next();
this.val$iterator.remove();
return t;
}
public String toString() {
return "Iterators.consumingIterator(...)";
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <T> T pollNext(Iterator<T> it) {
if (!it.hasNext()) {
return null;
}
T next = it.next();
it.remove();
return next;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static void clear(Iterator<?> it) {
Preconditions.checkNotNull(it);
while (it.hasNext()) {
it.next();
it.remove();
}
}
@SafeVarargs
public static <T> UnmodifiableIterator<T> forArray(T... tArr) {
return forArray(tArr, 0, tArr.length, 0);
}
static <T> UnmodifiableListIterator<T> forArray(T[] tArr, int i, int i2, int i3) {
Preconditions.checkArgument(i2 >= 0);
Preconditions.checkPositionIndexes(i, i + i2, tArr.length);
Preconditions.checkPositionIndex(i3, i2);
if (i2 == 0) {
return emptyListIterator();
}
return new ArrayItr(tArr, i, i2, i3);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class ArrayItr<T> extends AbstractIndexedListIterator<T> {
static final UnmodifiableListIterator<Object> EMPTY = new ArrayItr(new Object[0], 0, 0, 0);
private final T[] array;
private final int offset;
ArrayItr(T[] tArr, int i, int i2, int i3) {
super(i2, i3);
this.array = tArr;
this.offset = i;
}
@Override // com.google.common.collect.AbstractIndexedListIterator
protected final T get(int i) {
return this.array[this.offset + i];
}
}
public static <T> UnmodifiableIterator<T> singletonIterator(T t) {
return new UnmodifiableIterator<T>(t) { // from class: com.google.common.collect.Iterators.9
boolean done;
final Object val$value;
{
this.val$value = t;
}
@Override // java.util.Iterator
public T next() {
if (this.done) {
throw new NoSuchElementException();
}
this.done = true;
return (T) this.val$value;
}
@Override // java.util.Iterator
public boolean hasNext() {
return !this.done;
}
};
}
public static <T> UnmodifiableIterator<T> forEnumeration(Enumeration<T> enumeration) {
Preconditions.checkNotNull(enumeration);
return new UnmodifiableIterator<T>(enumeration) { // from class: com.google.common.collect.Iterators.10
final Enumeration val$enumeration;
{
this.val$enumeration = enumeration;
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.val$enumeration.hasMoreElements();
}
@Override // java.util.Iterator
public T next() {
return (T) this.val$enumeration.nextElement();
}
};
}
public static <T> Enumeration<T> asEnumeration(Iterator<T> it) {
Preconditions.checkNotNull(it);
return new Enumeration<T>(it) { // from class: com.google.common.collect.Iterators.11
final Iterator val$iterator;
{
this.val$iterator = it;
}
@Override // java.util.Enumeration
public boolean hasMoreElements() {
return this.val$iterator.hasNext();
}
@Override // java.util.Enumeration
public T nextElement() {
return (T) this.val$iterator.next();
}
};
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class PeekingImpl<E> implements PeekingIterator<E> {
private boolean hasPeeked;
private final Iterator<? extends E> iterator;
private E peekedElement;
public PeekingImpl(Iterator<? extends E> it) {
this.iterator = (Iterator) Preconditions.checkNotNull(it);
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.hasPeeked || this.iterator.hasNext();
}
@Override // com.google.common.collect.PeekingIterator, java.util.Iterator
public E next() {
if (!this.hasPeeked) {
return this.iterator.next();
}
E e = this.peekedElement;
this.hasPeeked = false;
this.peekedElement = null;
return e;
}
@Override // com.google.common.collect.PeekingIterator, java.util.Iterator
public void remove() {
Preconditions.checkState(!this.hasPeeked, "Can't remove after you've peeked at next");
this.iterator.remove();
}
@Override // com.google.common.collect.PeekingIterator
public E peek() {
if (!this.hasPeeked) {
this.peekedElement = this.iterator.next();
this.hasPeeked = true;
}
return this.peekedElement;
}
}
public static <T> PeekingIterator<T> peekingIterator(Iterator<? extends T> it) {
if (it instanceof PeekingImpl) {
return (PeekingImpl) it;
}
return new PeekingImpl(it);
}
@Deprecated
public static <T> PeekingIterator<T> peekingIterator(PeekingIterator<T> peekingIterator) {
return (PeekingIterator) Preconditions.checkNotNull(peekingIterator);
}
public static <T> UnmodifiableIterator<T> mergeSorted(Iterable<? extends Iterator<? extends T>> iterable, Comparator<? super T> comparator) {
Preconditions.checkNotNull(iterable, "iterators");
Preconditions.checkNotNull(comparator, "comparator");
return new MergingIterator(iterable, comparator);
}
/* loaded from: classes2.dex */
static class MergingIterator<T> extends UnmodifiableIterator<T> {
final Queue<PeekingIterator<T>> queue;
public MergingIterator(Iterable<? extends Iterator<? extends T>> iterable, Comparator<? super T> comparator) {
this.queue = new PriorityQueue(2, new Comparator<PeekingIterator<T>>(this, comparator) { // from class: com.google.common.collect.Iterators.MergingIterator.1
final Comparator val$itemComparator;
{
this.val$itemComparator = comparator;
}
@Override // java.util.Comparator
public int compare(PeekingIterator<T> peekingIterator, PeekingIterator<T> peekingIterator2) {
return this.val$itemComparator.compare(peekingIterator.peek(), peekingIterator2.peek());
}
});
for (Iterator<? extends T> it : iterable) {
if (it.hasNext()) {
this.queue.add(Iterators.peekingIterator(it));
}
}
}
@Override // java.util.Iterator
public boolean hasNext() {
return !this.queue.isEmpty();
}
@Override // java.util.Iterator
public T next() {
PeekingIterator<T> remove = this.queue.remove();
T next = remove.next();
if (remove.hasNext()) {
this.queue.add(remove);
}
return next;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class ConcatenatedIterator<T> implements Iterator<T> {
private Iterator<? extends T> iterator = Iterators.emptyIterator();
private Deque<Iterator<? extends Iterator<? extends T>>> metaIterators;
private Iterator<? extends T> toRemove;
private Iterator<? extends Iterator<? extends T>> topMetaIterator;
ConcatenatedIterator(Iterator<? extends Iterator<? extends T>> it) {
this.topMetaIterator = (Iterator) Preconditions.checkNotNull(it);
}
private Iterator<? extends Iterator<? extends T>> getTopMetaIterator() {
while (true) {
Iterator<? extends Iterator<? extends T>> it = this.topMetaIterator;
if (it != null && it.hasNext()) {
return this.topMetaIterator;
}
Deque<Iterator<? extends Iterator<? extends T>>> deque = this.metaIterators;
if (deque == null || deque.isEmpty()) {
return null;
}
this.topMetaIterator = this.metaIterators.removeFirst();
}
}
@Override // java.util.Iterator
public boolean hasNext() {
while (!((Iterator) Preconditions.checkNotNull(this.iterator)).hasNext()) {
Iterator<? extends Iterator<? extends T>> topMetaIterator = getTopMetaIterator();
this.topMetaIterator = topMetaIterator;
if (topMetaIterator == null) {
return false;
}
Iterator<? extends T> next = topMetaIterator.next();
this.iterator = next;
if (next instanceof ConcatenatedIterator) {
ConcatenatedIterator concatenatedIterator = (ConcatenatedIterator) next;
this.iterator = concatenatedIterator.iterator;
if (this.metaIterators == null) {
this.metaIterators = new ArrayDeque();
}
this.metaIterators.addFirst(this.topMetaIterator);
if (concatenatedIterator.metaIterators != null) {
while (!concatenatedIterator.metaIterators.isEmpty()) {
this.metaIterators.addFirst(concatenatedIterator.metaIterators.removeLast());
}
}
this.topMetaIterator = concatenatedIterator.topMetaIterator;
}
}
return true;
}
@Override // java.util.Iterator
public T next() {
if (hasNext()) {
Iterator<? extends T> it = this.iterator;
this.toRemove = it;
return it.next();
}
throw new NoSuchElementException();
}
@Override // java.util.Iterator
public void remove() {
CollectPreconditions.checkRemove(this.toRemove != null);
this.toRemove.remove();
this.toRemove = null;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <T> ListIterator<T> cast(Iterator<T> it) {
return (ListIterator) it;
}
}