A data-tube concept based class.
package engine
{
/**
* @file CDataTube.as
* @author Abhishek Kumar
*/
public class CDataTube
{
public function CDataTube()
{
}
public function manageItem(iCommand:Boolean, iItem:*, iList:*):Array
{
if (iList == undefined)
{
iList = [];
iList = addItem(iItem, iList);
}
else
iList = (iCommand)? addItem(iItem, iList) : deleteItem(isPresent(iItem, iList), iList);
return iList;
}
private function addItem(iItem:*, iList:Array):Array
{
iList.push(iItem);
return iList;
}
private function deleteItem(iIndex:int, iList:Array):Array
{
for (var j:int = iIndex; j < iList.length; j++)
iList[j] = iList[j + 1];
iList.length--;
return iList;
}
private function isPresent(iItem:*, iList:Array):int
{
for (var i:int = 0; i < iList.length; i++ )
if (iList[i] == iItem)
return i;
return -1;
}
}
}
Comments
Post a Comment