mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
handle null roots
This commit is contained in:
@@ -66,7 +66,7 @@ public abstract class TreeTraverser<T> {
|
||||
* iteration is in progress or when the iterators generated by {@link #children} are advanced.
|
||||
*/
|
||||
@NotNull
|
||||
public final JBIterable<T> preOrderTraversal(@NotNull final T root) {
|
||||
public final JBIterable<T> preOrderTraversal(@Nullable final T root) {
|
||||
return new JBIterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
@@ -96,7 +96,7 @@ public abstract class TreeTraverser<T> {
|
||||
* iteration is in progress or when the iterators generated by {@link #children} are advanced.
|
||||
*/
|
||||
@NotNull
|
||||
public final JBIterable<T> postOrderTraversal(@NotNull final T root) {
|
||||
public final JBIterable<T> postOrderTraversal(@Nullable final T root) {
|
||||
return new JBIterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
@@ -113,7 +113,7 @@ public abstract class TreeTraverser<T> {
|
||||
* iteration is in progress or when the iterators generated by {@link #children} are advanced.
|
||||
*/
|
||||
@NotNull
|
||||
public final JBIterable<T> breadthFirstTraversal(@NotNull final T root) {
|
||||
public final JBIterable<T> breadthFirstTraversal(@Nullable final T root) {
|
||||
return new JBIterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
@@ -172,8 +172,10 @@ public abstract class TreeTraverser<T> {
|
||||
|
||||
int doneCount;
|
||||
|
||||
PreOrderIterator(@NotNull T root) {
|
||||
stack.addLast(Pair.<T, Iterator<T>>create(null, new SingletonIterator<T>(root)));
|
||||
PreOrderIterator(@Nullable T root) {
|
||||
if (root != null) {
|
||||
stack.addLast(Pair.<T, Iterator<T>>create(null, new SingletonIterator<T>(root)));
|
||||
}
|
||||
}
|
||||
|
||||
PreOrderIterator(@NotNull Iterable<T> roots) {
|
||||
@@ -206,8 +208,10 @@ public abstract class TreeTraverser<T> {
|
||||
|
||||
private final class PostOrderIterator extends DfsIterator<T> {
|
||||
|
||||
PostOrderIterator(T root) {
|
||||
stack.addLast(Pair.create(root, children(root).iterator()));
|
||||
PostOrderIterator(@Nullable T root) {
|
||||
if (root != null) {
|
||||
stack.addLast(Pair.create(root, children(root).iterator()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,8 +234,10 @@ public abstract class TreeTraverser<T> {
|
||||
private final class BreadthFirstIterator extends Itr<T> {
|
||||
final Deque<T> queue = new ArrayDeque<T>();
|
||||
|
||||
BreadthFirstIterator(@NotNull T root) {
|
||||
queue.add(root);
|
||||
BreadthFirstIterator(@Nullable T root) {
|
||||
if (root != null) {
|
||||
queue.add(root);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user