ArrayIterator can be unmodifiable.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4550 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-02-10 03:35:37 +00:00
parent 15c0bbbe1c
commit d1ff63d62d
2 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ public class DSet
*/
public function iterator () :Iterator
{
return new ArrayIterator(_entries);
return new ArrayIterator(_entries, false);
}
/**
+9 -5
View File
@@ -12,10 +12,11 @@ public class ArrayIterator
/**
* Create an ArrayIterator.
*/
public function ArrayIterator (arr :Array)
public function ArrayIterator (arr :Array, allowRemove :Boolean = true)
{
_arr = arr;
_index = 0;
_lastIndex = allowRemove ? -1 : -2;
}
// documentation inherited from interface Iterator
@@ -27,14 +28,16 @@ public class ArrayIterator
// documentation inherited from interface Iterator
public function next () :Object
{
_lastIndex = _index;
if (_lastIndex != -2) {
_lastIndex = _index;
}
return _arr[_index++];
}
// documentation inherited from interface Iterator
public function remove () :void
{
if (_lastIndex == -1) {
if (_lastIndex < 0) {
throw new IllegalOperationError();
} else {
@@ -50,7 +53,8 @@ public class ArrayIterator
/** The current index. */
protected var _index :int;
/** The last-removed index. */
protected var _lastIndex :int = -1;
/** The last-removed index.
* Or -1 for already removed, -2 for no removals allowed. */
protected var _lastIndex :int;
}
}