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

207 lines
6.8 KiB
Java

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<T> {
public abstract Iterable<T> children(T t);
@Deprecated
public static <T> TreeTraverser<T> using(Function<T, ? extends Iterable<T>> function) {
Preconditions.checkNotNull(function);
return new TreeTraverser<T>(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<T> children(T t) {
return (Iterable) this.val$nodeToChildrenFunction.apply(t);
}
};
}
@Deprecated
public final FluentIterable<T> preOrderTraversal(T t) {
Preconditions.checkNotNull(t);
return new FluentIterable<T>(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<T> iterator() {
return this.this$0.preOrderIterator(this.val$root);
}
};
}
UnmodifiableIterator<T> 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<T> {
private final Deque<Iterator<T>> 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<T> last = this.stack.getLast();
T t = (T) Preconditions.checkNotNull(last.next());
if (!last.hasNext()) {
this.stack.removeLast();
}
Iterator<T> it = this.this$0.children(t).iterator();
if (it.hasNext()) {
this.stack.addLast(it);
}
return t;
}
}
@Deprecated
public final FluentIterable<T> postOrderTraversal(T t) {
Preconditions.checkNotNull(t);
return new FluentIterable<T>(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<T> iterator() {
return this.this$0.postOrderIterator(this.val$root);
}
};
}
UnmodifiableIterator<T> 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<T> {
final Iterator<T> childIterator;
final T root;
PostOrderNode(T t, Iterator<T> 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<T> {
private final ArrayDeque<PostOrderNode<T>> stack;
final TreeTraverser this$0;
PostOrderIterator(TreeTraverser treeTraverser, T t) {
this.this$0 = treeTraverser;
ArrayDeque<PostOrderNode<T>> 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<T> 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<T> expand(T t) {
return new PostOrderNode<>(t, this.this$0.children(t).iterator());
}
}
@Deprecated
public final FluentIterable<T> breadthFirstTraversal(T t) {
Preconditions.checkNotNull(t);
return new FluentIterable<T>(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<T> 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<T> implements PeekingIterator<T> {
private final Queue<T> 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;
}
}
}