Make OidList Iterable
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6426 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
package com.threerings.presents.dobj;
|
package com.threerings.presents.dobj;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import com.threerings.io.Streamable;
|
import com.threerings.io.Streamable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,7 +38,8 @@ import com.threerings.io.Streamable;
|
|||||||
* <li> When an object is destroyed, its oid is automagically removed from any OidLists.
|
* <li> When an object is destroyed, its oid is automagically removed from any OidLists.
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class OidList implements Streamable
|
public class OidList
|
||||||
|
implements Streamable, Iterable<Integer>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates an empty oid list.
|
* Creates an empty oid list.
|
||||||
@@ -148,6 +152,11 @@ public class OidList implements Streamable
|
|||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterator<Integer> iterator ()
|
||||||
|
{
|
||||||
|
return new OidIterator();
|
||||||
|
}
|
||||||
|
|
||||||
private void expand ()
|
private void expand ()
|
||||||
{
|
{
|
||||||
int[] oids = new int[_oids.length*2];
|
int[] oids = new int[_oids.length*2];
|
||||||
@@ -155,6 +164,30 @@ public class OidList implements Streamable
|
|||||||
_oids = oids;
|
_oids = oids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected class OidIterator
|
||||||
|
implements Iterator<Integer>
|
||||||
|
{
|
||||||
|
public boolean hasNext ()
|
||||||
|
{
|
||||||
|
return _index < size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer next ()
|
||||||
|
{
|
||||||
|
if (!hasNext()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
return get(_index++);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove ()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int _index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
private int[] _oids;
|
private int[] _oids;
|
||||||
private int _size;
|
private int _size;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user