All the latest and ... well, the latest anyway.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3950 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-03-15 03:28:02 +00:00
parent 4fe0d6e484
commit ed1be4a0f2
18 changed files with 551 additions and 350 deletions
+50
View File
@@ -0,0 +1,50 @@
package com.threerings.util {
/**
* Contains methods that should be in Array, but aren't.
*/
public class ArrayUtil
{
/**
* Remove the first instance of the specified element from the array.
*/
public static function removeFirst (arr :Array, element :Object) :void
{
removeImpl(arr, element, true);
}
/**
* Remove the last instance of the specified element from the array.
*/
public static function removeLast (arr :Array, element :Object) :void
{
arr.reverse();
removeFirst(arr, element);
arr.reverse();
}
/**
* Removes all instances of the specified element from the array.
*/
public static function removeAll (arr :Array, element :Object) :void
{
removeImpl(arr, element, false);
}
/**
* Implementation of remove methods.
*/
private static function removeImpl (
arr :Array, element :Object, firstOnly :Boolean) :void
{
for (var ii :int = 0; ii < arr.length; ii++) {
if (arr[ii] === element) {
arr.splice(ii--, 1);
if (firstOnly) {
return;
}
}
}
}
}
}