1:/* Array Iterator by AsFusion. March 2, 2004 Version 1.0
   2:* check www.asfusion.com for updates and more free code.
   3:* You may distribute this code freely, as long as this comment block remains intact
   4:*/
   5:
   6:class ArrayIterator
   7:{
   8:    private var data:Array;
   9:    private var index:Number = -1;
  10:    function ArrayIterator(a:Array)
  11:    {
  12:        data = a;
  13:    }
  14:    /*Inserts the specified element into the list 
  15:    before the cursor*/
  16:    public function addElement(o:Object):Void
  17:    {
  18:        data.splice((index == -1) ? 0 : index++, 0, o );
  19:    }
  20:    /*Returns true if this list iterator has more elements
  21:    when traversing the list in the forward direction*/
  22:    public function hasNext():Boolean
  23:    {
  24:        return (index < data.length -1);
  25:    }
  26:    /*Returns true if this list iterator has more elements
  27:    when  traversing the list in the reverse direction.*/
  28:    public function hasPrevious():Boolean
  29:    {
  30:        return (index > 0);
  31:    }
  32:    /*Returns the next element in the list.*/
  33:    public function next():Object
  34:    {
  35:        return data[++index];
  36:    }
  37:    /*Returns the previous element in the list.*/
  38:    public function previous():Object
  39:    {
  40:        return data[--index];
  41:    }
  42:    /* Returns the index of the element that would be
  43:    returned by a subsequent call to next.*/
  44:    public function nextIndex():Number
  45:    {
  46:        return hasNext() ? index + 1 : null;
  47:    }
  48:    /*Returns the index of the element that would be
  49:    returned by a subsequent  call to previous.*/
  50:    public function previousIndex():Number
  51:    {
  52:        return hasPrevious() ? index - 1 : null;
  53:    }
  54:    /*Removes from the list the last element that
  55:    was returned by  next or previous*/
  56:    public function remove():Void
  57:    {
  58:        data.splice(index, 1 );
  59:    }
  60:    /*Replaces the last element returned by next or  
  61:    previous with the specified element*/
  62:    public function setElement(o:Object):Void
  63:    {
  64:        data[index] = o;
  65:    }
  66:    /*Returns the first element in the list.*/
  67:    public function first():Object
  68:    {
  69:        index = 0;
  70:        return data[index];
  71:    }
  72:    /*Returns the last element in the list.*/
  73:    public function last():Object
  74:    {
  75:        index = data.length - 1;
  76:        return data[index];
  77:    }
  78:}