| 106 | } |
| 107 | |
| 108 | func (this *NestedIterator) Next() int { |
| 109 | current := this.stack.Peek() |
| 110 | for !current.List[current.Idx].IsInteger() { |
| 111 | next := &ListIndex{ |
| 112 | Idx: 0, |
| 113 | List: current.List[current.Idx].GetList(), |
| 114 | } |
| 115 | this.stack.Push(next) |
| 116 | |
| 117 | current.Idx++ |
| 118 | current = next |
| 119 | } |
| 120 | |
| 121 | value := current.List[current.Idx].GetInteger() |
| 122 | current.Idx++ |
| 123 | |
| 124 | if current.Idx == len(current.List) { |
| 125 | this.stack.Pop() |
| 126 | } |
| 127 | |
| 128 | return value |
| 129 | } |
| 130 | |
| 131 | func (this *NestedIterator) HasNext() bool { |
| 132 | return !this.stack.IsEmpty() && this.stack.Peek().Idx != len(this.stack.Peek().List) |