Permalink
Browse files

Use Deque instead of Stack

  • Loading branch information...
1 parent 9747ed9 commit a85cfdef3ede0c6ecabab6454c365cd23655440f @aslakhellesoy aslakhellesoy committed May 1, 2012
Showing with 7 additions and 6 deletions.
  1. +7 −6 core/src/main/java/cucumber/io/FlatteningIterator.java
@@ -1,10 +1,11 @@
package cucumber.io;
import java.lang.reflect.Array;
+import java.util.ArrayDeque;
import java.util.Arrays;
+import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import java.util.Stack;
/**
* An iterator that 'flattens out' collections, iterators, arrays, etc.
@@ -31,7 +32,7 @@
/* This stack stores all the iterators found so far. The head of the stack is
* the iterator which we are currently progressing through */
- private final Stack<Iterator<?>> iterators = new Stack<Iterator<?>>();
+ private final Deque<Iterator<?>> iterators = new ArrayDeque<Iterator<?>>();
// Storage field for the next element to be returned. blank when the next element
// is currently unknown.
@@ -43,20 +44,20 @@ public FlatteningIterator(Object... objects) {
}
public void push(Iterator<?> iterator) {
- iterators.push(iterator);
+ iterators.addFirst(iterator);
}
public void remove() {
throw new UnsupportedOperationException();
}
private void moveToNext() {
- if ((next == blank) && !this.iterators.empty()) {
+ if ((next == blank) && !this.iterators.isEmpty()) {
if (!iterators.peek().hasNext()) {
- iterators.pop();
+ iterators.removeFirst();
moveToNext();
} else {
- final Object next = iterators.peek().next();
+ final Object next = iterators.peekFirst().next();
if (next instanceof Iterator) {
push((Iterator<?>) next);
moveToNext();

0 comments on commit a85cfde

Please sign in to comment.