package com.google.common.collect; import com.google.common.base.Function; import com.google.common.base.Preconditions; import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; import java.util.Queue; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault @Deprecated /* loaded from: classes3.dex */ public abstract class TreeTraverser { public abstract Iterable children(T t); @Deprecated public static TreeTraverser using(final Function> function) { Preconditions.checkNotNull(function); return new TreeTraverser() { // from class: com.google.common.collect.TreeTraverser.1 @Override // com.google.common.collect.TreeTraverser public Iterable children(T t) { return (Iterable) Function.this.apply(t); } }; } @Deprecated public final FluentIterable preOrderTraversal(final T t) { Preconditions.checkNotNull(t); return new FluentIterable() { // from class: com.google.common.collect.TreeTraverser.2 /* JADX WARN: Multi-variable type inference failed */ @Override // java.lang.Iterable public UnmodifiableIterator iterator() { return TreeTraverser.this.preOrderIterator(t); } }; } UnmodifiableIterator preOrderIterator(T t) { return new PreOrderIterator(t); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public final class PreOrderIterator extends UnmodifiableIterator { private final Deque> stack; PreOrderIterator(T t) { ArrayDeque arrayDeque = new ArrayDeque(); this.stack = arrayDeque; arrayDeque.addLast(Iterators.singletonIterator(Preconditions.checkNotNull(t))); } @Override // java.util.Iterator public boolean hasNext() { return !this.stack.isEmpty(); } @Override // java.util.Iterator public T next() { Iterator last = this.stack.getLast(); T t = (T) Preconditions.checkNotNull(last.next()); if (!last.hasNext()) { this.stack.removeLast(); } Iterator it = TreeTraverser.this.children(t).iterator(); if (it.hasNext()) { this.stack.addLast(it); } return t; } } @Deprecated public final FluentIterable postOrderTraversal(final T t) { Preconditions.checkNotNull(t); return new FluentIterable() { // from class: com.google.common.collect.TreeTraverser.3 /* JADX WARN: Multi-variable type inference failed */ @Override // java.lang.Iterable public UnmodifiableIterator iterator() { return TreeTraverser.this.postOrderIterator(t); } }; } UnmodifiableIterator postOrderIterator(T t) { return new PostOrderIterator(t); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public static final class PostOrderNode { final Iterator childIterator; final T root; PostOrderNode(T t, Iterator it) { this.root = (T) Preconditions.checkNotNull(t); this.childIterator = (Iterator) Preconditions.checkNotNull(it); } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public final class PostOrderIterator extends AbstractIterator { private final ArrayDeque> stack; PostOrderIterator(T t) { ArrayDeque> arrayDeque = new ArrayDeque<>(); this.stack = arrayDeque; arrayDeque.addLast(expand(t)); } @Override // com.google.common.collect.AbstractIterator @CheckForNull protected T computeNext() { while (!this.stack.isEmpty()) { PostOrderNode last = this.stack.getLast(); if (last.childIterator.hasNext()) { this.stack.addLast(expand(last.childIterator.next())); } else { this.stack.removeLast(); return last.root; } } return endOfData(); } private PostOrderNode expand(T t) { return new PostOrderNode<>(t, TreeTraverser.this.children(t).iterator()); } } @Deprecated public final FluentIterable breadthFirstTraversal(final T t) { Preconditions.checkNotNull(t); return new FluentIterable() { // from class: com.google.common.collect.TreeTraverser.4 @Override // java.lang.Iterable public UnmodifiableIterator iterator() { return new BreadthFirstIterator(t); } }; } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes3.dex */ public final class BreadthFirstIterator extends UnmodifiableIterator implements PeekingIterator { private final Queue queue; BreadthFirstIterator(T t) { ArrayDeque arrayDeque = new ArrayDeque(); this.queue = arrayDeque; arrayDeque.add(t); } @Override // java.util.Iterator public boolean hasNext() { return !this.queue.isEmpty(); } @Override // com.google.common.collect.PeekingIterator public T peek() { return this.queue.element(); } @Override // java.util.Iterator, com.google.common.collect.PeekingIterator public T next() { T remove = this.queue.remove(); Iterables.addAll(this.queue, TreeTraverser.this.children(remove)); return remove; } } }