1 21 package com.db4o.foundation; 22 23 24 30 public class Queue4 { 31 private final class Queue4Iterator implements Iterator4 { 32 private boolean _active=false; 33 private List4 _current=null; 34 35 public Object current() { 36 return _current._element; 37 } 38 39 public boolean moveNext() { 40 if(!_active) { 41 _current=_last; 42 _active=true; 43 } 44 else { 45 if(_current!=null) { 46 _current=_current._next; 47 } 48 } 49 return _current!=null; 50 } 51 52 public void reset() { 53 _current=null; 54 _active=false; 55 } 56 } 57 58 private List4 _first; 59 private List4 _last; 60 61 public final void add(Object obj) { 62 List4 ce = new List4(null, obj); 63 if(_first == null){ 64 _last = ce; 65 }else{ 66 _first._next = ce; 67 } 68 _first = ce; 69 } 70 71 public final Object next() { 72 if(_last == null){ 73 return null; 74 } 75 Object ret = _last._element; 76 _last = _last._next; 77 if(_last == null){ 78 _first = null; 79 } 80 return ret; 81 } 82 83 public final boolean hasNext(){ 84 return _last != null; 85 } 86 87 public Iterator4 iterator() { 88 return new Queue4Iterator(); 89 } 90 91 } 92 | Popular Tags |