From 626b4d257fc031b07cff616a7b9bce2280ac9fd2 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 5 Oct 2006 00:16:11 +0000 Subject: [PATCH] Added some methods to StreamableArrayList that behave properly (use Equalable to determine equality instead of using reference equality). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4407 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/util/StreamableArrayList.as | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/as/com/threerings/util/StreamableArrayList.as b/src/as/com/threerings/util/StreamableArrayList.as index 5691cf4d5..8efb6dadc 100644 --- a/src/as/com/threerings/util/StreamableArrayList.as +++ b/src/as/com/threerings/util/StreamableArrayList.as @@ -9,6 +9,48 @@ import com.threerings.io.Streamable; public class StreamableArrayList extends ArrayCollection implements Streamable { + /** + * Returns the index of the specified object in this collection, using + * Equalable.equals() if possible. + */ + public function indexOf (object :Object) :int + { + return ArrayUtil.indexOf(source, object); + } + + /** + * Removes the first instance of the supplied object from this array, using + * Equalable.equals() to determine equality. Returns the removed object if + * a match was found, null otherwise. + */ + public function remove (object :Object) :Object + { + return ArrayUtil.removeFirst(source, object); + } + + /** + * Adds all of the elements of the supplied collection to the end of this + * list. + */ + public function addAll (list :ArrayCollection) :void + { + for (var ii :int = 0; ii < list.length; ii++) { + addItem(list.getItemAt(ii)); + } + } + + /** + * Extracts and returns a sublist from this list. + */ + public function subList (startIdx :int, endIdx :int) :ArrayCollection + { + var newlist :ArrayCollection = new ArrayCollection(); + for (var ii :int = startIdx; ii <= endIdx; ii++) { + newlist.addItem(getItemAt(ii)); + } + return newlist; + } + // documentation inherited from interface Streamable public function writeObject (out :ObjectOutputStream) :void {