--- /dev/null
+/*\r
+ Copyright (c) 2008, Adobe Systems Incorporated\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without \r
+ modification, are permitted provided that the following conditions are\r
+ met:\r
+\r
+ * Redistributions of source code must retain the above copyright notice, \r
+ this list of conditions and the following disclaimer.\r
+ \r
+ * Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in the \r
+ documentation and/or other materials provided with the distribution.\r
+ \r
+ * Neither the name of Adobe Systems Incorporated nor the names of its \r
+ contributors may be used to endorse or promote products derived from \r
+ this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS\r
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR \r
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+*/\r
+\r
+package com.adobe.utils\r
+{\r
+ \r
+ /**\r
+ * Class that contains static utility methods for manipulating and working\r
+ * with Arrays.\r
+ * \r
+ * Note that all APIs assume that they are working with well formed arrays.\r
+ * i.e. they will only manipulate indexed values. \r
+ * \r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public class ArrayUtil\r
+ {\r
+ \r
+ /**\r
+ * Determines whether the specified array contains the specified value. \r
+ * \r
+ * @param arr The array that will be checked for the specified value.\r
+ *\r
+ * @param value The object which will be searched for within the array\r
+ * \r
+ * @return True if the array contains the value, False if it does not.\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public static function arrayContainsValue(arr:Array, value:Object):Boolean\r
+ {\r
+ return (arr.indexOf(value) != -1);\r
+ } \r
+ \r
+ /**\r
+ * Remove all instances of the specified value from the array,\r
+ * \r
+ * @param arr The array from which the value will be removed\r
+ *\r
+ * @param value The object that will be removed from the array.\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public static function removeValueFromArray(arr:Array, value:Object):void\r
+ {\r
+ var len:uint = arr.length;\r
+ \r
+ for(var i:Number = len; i > -1; i--)\r
+ {\r
+ if(arr[i] === value)\r
+ {\r
+ arr.splice(i, 1);\r
+ }\r
+ } \r
+ }\r
+\r
+ /**\r
+ * Create a new array that only contains unique instances of objects\r
+ * in the specified array.\r
+ *\r
+ * Basically, this can be used to remove duplication object instances\r
+ * from an array\r
+ * \r
+ * @param arr The array which contains the values that will be used to\r
+ * create the new array that contains no duplicate values.\r
+ *\r
+ * @return A new array which only contains unique items from the specified\r
+ * array.\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public static function createUniqueCopy(a:Array):Array\r
+ {\r
+ var newArray:Array = new Array();\r
+ \r
+ var len:Number = a.length;\r
+ var item:Object;\r
+ \r
+ for (var i:uint = 0; i < len; ++i)\r
+ {\r
+ item = a[i];\r
+ \r
+ if(ArrayUtil.arrayContainsValue(newArray, item))\r
+ {\r
+ continue;\r
+ }\r
+ \r
+ newArray.push(item);\r
+ }\r
+ \r
+ return newArray;\r
+ }\r
+ \r
+ /**\r
+ * Creates a copy of the specified array.\r
+ *\r
+ * Note that the array returned is a new array but the items within the\r
+ * array are not copies of the items in the original array (but rather \r
+ * references to the same items)\r
+ * \r
+ * @param arr The array that will be copies\r
+ *\r
+ * @return A new array which contains the same items as the array passed\r
+ * in.\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public static function copyArray(arr:Array):Array\r
+ { \r
+ return arr.slice();\r
+ }\r
+ \r
+ /**\r
+ * Compares two arrays and returns a boolean indicating whether the arrays\r
+ * contain the same values at the same indexes.\r
+ * \r
+ * @param arr1 The first array that will be compared to the second.\r
+ *\r
+ * @param arr2 The second array that will be compared to the first.\r
+ *\r
+ * @return True if the arrays contains the same values at the same indexes.\r
+ False if they do not.\r
+ *\r
+ * @langversion ActionScript 3.0\r
+ * @playerversion Flash 9.0\r
+ * @tiptext\r
+ */ \r
+ public static function arraysAreEqual(arr1:Array, arr2:Array):Boolean\r
+ {\r
+ if(arr1.length != arr2.length)\r
+ {\r
+ return false;\r
+ }\r
+ \r
+ var len:Number = arr1.length;\r
+ \r
+ for(var i:Number = 0; i < len; i++)\r
+ {\r
+ if(arr1[i] !== arr2[i])\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ \r
+ return true;\r
+ }\r
+ }\r
+}\r