flex类似HashMap工具
来源:互联网 发布:图片浏览软件 编辑:程序博客网 时间:2024/05/17 01:12
package com.**.utils
{
/**
* The hash table is similar to a Dictionary in that a key object is used to map data. Unlike a Dictionary the HashTable behaves similar to an Array
* providing the ability check length and get itmes by position.
*
*/
public class HashTableUtil
{
private var _itemTable:Array; // stores the items
private var _keyTable:Array; // stores the keys
/**
* Constructor for the HashTable.
*
*/
public function HashTableUtil()
{
_itemTable = new Array();
_keyTable = new Array();
}
/**
* Adds a key/item pair to the HashTable. This enables the ability to lookup items by key or position. This also enables keys to be found by items or position.
* @param key
* @param item
*
*/
public function addItem(key:*, item:*):void
{
// see if we are already tracking the key
var len:int = _keyTable.length;
for(var i:uint = 0; i < len; i++)
{
if(_keyTable[i] == key)
{
_itemTable[i] = item;
return;
}
}
// we have not had this key yet, add it
_keyTable.push(key);
_itemTable.push(item);
}
/**
* Removes an item/key pair based on the key provided.
*
* @param key Key to remove item on.
*
*/
public function remove(key:*):void
{
// find key and remove key/item pair
var len:int = _keyTable.length;
for(var i:uint = 0; i < len; i++)
{
if(_keyTable[i] == key)
{
// remove from both tables
_itemTable.splice(i, 1);
_keyTable.splice(i, 1);
}
}
}
/**
* Returns the key at a specified position if the HashTable has that position available.
*
* @param position Position to return key.
* @return Key at specified position.
*
*/
public function getKeyAt(position:int):*
{
return _keyTable[position];
}
/**
* Returns the item for the specified key, if the key is not found then the method returns null.
*
* @param key Key object to look up item.
* @return Item bound to key.
*
*/
public function getItem(key:*):*
{
// find key return item
var item:* = null;
var len:int = _keyTable.length;
for(var i:uint = 0; i < len; i++)
{
if(_keyTable[i] == key)
{
item = _itemTable[i];
break;
}
}
return item;
}
/**
* Returns all items stored in the HashTable. The returned Array is a clone of the stored array to prevent key pair corruption.
*
* @return Array of all the contained items.
*
*/
public function getAllItems():Array
{
return _itemTable.slice();
}
/**
* Returns all keys stored in the HashTable. The returned Array is a clone of the stored array to prevent key pair corruption.
*
* @return Array of all the contained keys.
*
*/
public function getAllKeys():Array
{
return _keyTable.slice();
}
/**
* Removes all items and keys from the HashTable.
*
*/
public function removeAll():void
{
_itemTable = new Array();
_keyTable = new Array();
}
/**
* Looks up the requested item and returns true if the item is contained, false if it is not.
*
* @param item Item to lookup.
* @return True if found, false if not.
*
*/
public function containsItem(item:*):Boolean
{
var len:int = _itemTable.length;
for(var i:uint = 0; i < len; i++)
{
if(_itemTable[i] == item) return true;
}
return false;
}
/**
* Looks up the requested key and returns true if the key is contained, false if it is not.
*
* @param key Key to lookup.
* @return True if found, false if not.
*
*/
public function containsKey(key:*):Boolean
{
var len:int = _keyTable.length;
for(var i:uint = 0; i < len; i++)
{
if(_keyTable[i] == key) return true;
}
return false;
}
/**
* Used to determine if there are currently item pairs in the table.
*
* @return True if empty, false if not.
*
*/
public function get isEmpty():Boolean
{
return (_itemTable.length > 0) ? false : true;
}
/**
* Returns the number of items currently inside the HashTable.
*
* @return The number of items in the table.
*
*/
public function get length():int
{
return _itemTable.length;
}
}
}
- flex类似HashMap工具
- Flex HashMap
- FLEX HashMap遍历
- flex创建hashMap
- Flex 写Cookie(类似Cookie)
- flex类似鱼眼效果
- Flex 写Cookie(类似Cookie)
- actionscript(flex)中hashmap hashtable
- red5与flex通信 HashMap
- javascript创建类似java中的HashMap
- 工具 - js自定义HashMap
- 类似Xmlhttp获取数据的Flex方法~
- Flex类似js里面getElementById的方法
- 用FLex实现类似论坛个人信息页面
- flex 滚动信息,类似marquee的展现
- Flex滑动面板,类似QQ隐藏效果
- flex中 类似java instanceof 的用法
- tunna类似redush的工具
- IOS文件操作的两种方式:NSFileManager操作和流操作
- 欢迎使用CSDN-markdown编辑器
- Linux 技巧:让进程在后台可靠运行的几种方法
- ubuntu通过windows下的ccproxy代理上网
- java中两个字符串如何比较大小
- flex类似HashMap工具
- Qt-4.8.4使用电容触摸屏
- 修改 Ubuntu ulimit 限制
- Java学习笔记之异常
- 黑马程序员--代码实现2 多态
- flex AdvancedDataGrid 某行指定值变颜色
- GIT基本概念和用法总结
- Spring事务管理—aop:pointcut expression解析
- Android使用FileInputStream和FileOutputStream进行文件I/O操作