Flex3 Array Processing class myarrayutils.

Source: Internet
Author: User

Recently, many common processing classes have been used for projects. Post them and share them. If there are any mistakes, please correct them and welcome to the discussion.

 

//////////////////////////////////////// ////////////////////////////////////////
//
// My system
// Copyright 2008-2009 my systems inconfigurated
// All Rights Reserved.
//
// Notice: My system permits you to use, modify, and distribute this file
// Langversion ActionScript 3.0
// Playerversion, flash 9.0
// Date: 2009-03-22 Keren
// QQ: 994251681
// MSN: keren1515@hotmail.com
//
//////////////////////////////////////// ////////////////////////////////////////
Package org. App. utils. Common
{
Import com. hurlant. Eval. Ast. nulltype;
 
Public class myarrayutils
{
Public Function myarrayutils (single: singletonenforcer)
{
If (single = NULL) throw new error ("this class is singletonenforcer .");
}
//////////////////////////////////////// ////////////////////////////////
/**
* Convert an identified string into an array.
* @ Param string SRC Source string
* @ Param string flg ID
*
* @ Return Array
*/
Public static function toarray (SRC: String, flg: string): Array {
Return SRC. Split (flg );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Add new elements to the array
* @ Param array the array to be operated by Target
* @ Param Boolean position added by flg, true: false at the end: in the header
* @ Param newitems new elements (one or more elements separated by commas, or an array)
* Eg: "A", "B", "C"
*
* @ Return Array
*/
Public static function additem (target: array, flg: Boolean = true,... newitems): Array {
If (flg) {// Add at the end of Array
Target. Push (newitems );
} Else {// Add it to the header
Target. unshift (newitems );
}
Return target;
}
/**
* Add the new element to the end of the specified position in the array.
* @ Param array the array to be operated by Target
* @ Param Boolean position added by startindex
* @ Param newitems new elements (one or more elements separated by commas, or an array)
*
* @ Return Array
*/
Public static function additembyindex (target: array, startindex: Int = 0,... newitems): Array {
VaR length: Int = target. length;
If (startindex> length ){
// Throw new error ("the added position is greater than the length of the array. Please confirm again! ");
Startindex = length-1;
}
Return target. splice (startindex, 0, newitems );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Delete the header or tail element from the array.
* @ Param array the array to be operated by Target
* @ Param Boolean the position where flg is deleted, true: false at the end: in the header
*
* @ Return Array
*/
Public static function dropitem (target: array, flg: Boolean = true): Array {
If (flg) {// Delete the object at the end of the array -- Implement the following: first-in-first-out
Target. Pop ();
} Else {// Delete the header
Target. unshift ();
}
Return target;
}
/**
* [Delete the specified location before inserting it]
* Delete the element at the specified position in the array and insert a new element at the specified position.
* @ Param array the array to be operated by Target
* @ Param startindex start position, and the last element will be deleted.
* @ Param deletecount: Number of deleted items
* @ Param newitems new element
*
* @ Return Array
*/
Public static function dropitembyindex (target: array,
Startindex: Int = 0, deletecount: uint = 0,... newitems): Array {
VaR length: Int = target. length;
If (startindex> length ){
Throw new error ("the deleted location is greater than the length of the array. Please confirm again! ");
// Startindex = length-1;
}
// How many elements are there from startindex to the end?
VaR leave: Int = length-1-startIndex;
If (deletecount> Leave ){
Deletecount = leave;
}
If (values = NULL ){
Return target. splice (startindex, delcount );
}
Return target. splice (startindex, delcount, newitems );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Add an element at the end of the array.
*
*/
Public static function append (target: array, newitem: *): Array {
Target [target. Length] = newitem;
Return target;
}
/**
* Clear the content of an array element.
*
*/
Public static function empityitem (target: array, index: INT): Array {
Delete (target [Index]); // only deletes the content of the element and changes the content to undefined.
Return target;
}
//////////////////////////////////////// ////////////////////////////////
/**
* Re-set the length of the array
* @ Param target: Target Array
* @ Param newsize new length
*
* @ Return Array
*/
Public static function resize (target: array, newsize: uint): Array {
VaR length: Int = target. length;
If (newsize> length) {// is in Amplification
// Except the last element, all other element values are undefined.
Target [newsize] = "";
}
Else {// cut the end
Target. Length = newsize;
}
Return target;
}
//////////////////////////////////////// ////////////////////////////////
//?????????????????????????
Public static function findmatchindex (target: array,
Search: String, startindex: Int = 0,
Fullmatch: Boolean = false): int {
Return NULL;
}
//?????????????????????????
Public static function findmatchitem (target: array,
Search: String, startindex: Int = 0,
Fullmatch: Boolean = false): object {
Return NULL;
}
//////////////////////////////////////// ////////////////////////////////
/**
* Connection count string
*/
Public static function join (target: array, SEG: String = ","): String {
Return target. Join (SEG );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Join multiple numbers to form a new array
* @ Param target: Target Array
* @ Param ARGs connection object
*
* @ Return array new array
*/
Public static function Link (target: array,... ARGs): Array {
Return target. Concat (ARGs );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Sort array elements. By default, the elements are sorted by ASCII code in ascending order.
* Parameters:
* Caseinsensitive: case insensitive
* Descending: Descending Order
* Uniquesort: If the elements have the same elements, the sorting is stopped.
* Numberic: sorts numbers using ASCII codes.
* The preceding parameters can be integrated, for example, array. caseinsensitive | array. Descending,
* Use a vertical bar (|) to connect multiple sorting constants.
*/
Public static function sort (target: array,... ARGs): Array {
Return target. Sort (ARGs );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Sort by keywords. Generally, josn objects are placed in the array and sorted by keys of josn objects,
* Eg: array xx;
* XX. Push ({key1: 1, key2: 2 });
*
* XX. sorton (key1); or XX. sorton ([key1, key2]);
*
* Format: array. sorton ([keyword 1 | keyword 2 |...], [sorting constant 1 | sorting constant 2 |...]);
* Or
* Array. sorton (keyword, sorting constant 1 | sorting constant 2 | ...);
*/
Public static function sorton (target: array,
Fieldname: object, options: Object = NULL): Array {
Return target. sorton (fieldname, options );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Implement custom sorting and pass in the sorting function.
* Eg:
* Function name (A: data type, B: data type): int {
* If (the condition in which a is placed after B ){
* Return 1;
*} Else if (the condition that a ranks before B ){
* Return-1;
*} Else {
* Return 0;
*}
*}
*
*/
Public static function sortbyselffunction (target: array, FUNC: function): Array {
Return target. Sort (func );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Obtain the largest and smallest element values in the array.
*/
Public static function getitem (target: array, flg: Boolean = false): object {
Target. Sort (array. Numeric );
If (flg) {// obtain the maximum value
Return target [target. Length-1];
} Else {
Return target [0];
}
}
Public static function getmaxitem (target: array): object {
Return getitem (target, true );
}
Public static function getminitem (target: array): object {
Return getitem (target, false );
}
//////////////////////////////////////// ////////////////////////////////
/**
* Compare two arrays by comparing elements
* @ Param SRC
* @ Param dest
* @ Param ignoresequence ignore the comparison sequence of array elements. True: false: No
*
* @ Return true: equal false: not equal
*/
Public static function equals (SRC: array, DEST: array,
Ignoresequence: Boolean = true): Boolean {
VaR length4src: uint = SRC. length;
VaR length4dest: uint = DeST. length;
If (length4src! = Length4dest) return false;
For (var I: Int = 0; I <length4src; I ++ ){
If (ignoresequence ){
VaR flg: Boolean = false;
For (var k: Int = 0; k <length4dest; k ++ ){
If (SRC [I] = Dest [k]) {
Flg = true;
Break;
}
}
If (! Flg) return false;
} Else {
If (SRC [I]! = Dest [I]) return false;
}
}
Return true;
}
//////////////////////////////////////// ////////////////////////////////
/**
* Copy an array. If it is a deep copy, a new array instance will be created. Otherwise, it will point to the same instance, and one of the changes will be
* Another array is affected.
* @ Param SRC
* @ Param deepclone deep copy, true: false: No, indicating a new array instance.
*
* @ Return Array
*/
Public static function clone (SRC: array, deepclone: Boolean = true): Array {
VaR newarr: array = NULL;
If (deepclone ){
Newarr = new array (SRC. Length );
For (var I: Int = 0; I <SRC. length; I ++ ){
Newarr [I] = SRC [I];
}
} Else {
Newarr = SRC;
}
Return newarr;
}
//////////////////////////////////////// ////////////////////////////////
//////////////////////////////////////// ////////////////////////////////
//////////////////////////////////////// ////////////////////////////////
} // End class
} // End package
Class singletonenforcer {}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.