arrays - AS3 How to i turn head of the Vector list? -
i have vector ip , port list , socket connection, when connection lose click button , call next ip , port vector list.
my question when finish list how turn head of list ?
this current code
public class uriiterator { private var _availableaddresses: vector.<socketconnection> = new vector.<socketconnection>(); public function uriiterator() { } public function withaddress(host: string, port: int): uriiterator { const a: socketconnection = new socketconnection(host, port); _availableaddresses.push(a); return this; } public function next(): socketconnection{ return _availableaddresses.length ? _availableaddresses.pop() : null; } }
thanks
in current implementation can traverse list once. need change code keep list unmodified:
public class uriiterator { private var _currentindex:int = 0; private var _availableaddresses: vector.<socketconnection> = new vector.<socketconnection>(); public function withaddress(host: string, port: int): uriiterator { const a: socketconnection = new socketconnection(host, port); _availableaddresses.push(a); return this; } public function first():socketconnection { _currentindex = 0; if (_currentindex >= _availableaddresses.length) return null; return _availableaddresses[_currentindex++]; } public function next(): socketconnection { if (_currentindex >= _availableaddresses.length) return null; return _availableaddresses[_currentindex++]; } }
now first entry call const firstconn:socketconnection = iterator.first
, rest of them, keep calling iterator.next
.
Comments
Post a Comment