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