NOTE: Reprint please indicate the source.
/**------------------------Public Method-------------------------* *
/**
* Add Remove method to array
*
* @param s
* The values in the removed array
* @return
*/
Array.prototype.remove = function (s) {
for (var i = 0; i < this.length; i++) {
if (s = = This[i])
This.splice (i, 1);
}
}
/**------------------------Public Method End-------------------------* *
/**------------------------bytemap Start-------------------------* *
/**
* Simulate Java Map class, put (Key,value), get (key), remove (key), IsEmpty,..........
*/
function Bytemap () {
/** keys store key value data storage/
var keys = new Array ();
var data = new Object ();
/**
* Put a key value pair
*
* @param key
* Value String
* @param value
* Key Value Object
*/
This.put = function (key, value) {
if (data[key] = = null) {
Keys.push (key);
}
Data[key] = value;
};
/**
* Get a key value
*
* @param key
* Key String
*/
This.get = function (key) {
return Date[key];
};
/**
* return "1" When a key key does not exist
*
* @param key
* Key String
*/
This.remove = function (key) {
When key does not exist
if (data[key] = = null) {
Return '-1 ';
}
Keys.remove (key);
Data[key] = null;
};
/**
* Traversal function performs the callback function fn (key,value,index) parameter is not a function Ruturn "-1"
*
* @param fn
* Callback function name function parameter should be (Key,value,index)
*/
This.each = function (fn) {
Check if this function exists
if (typeof fn!= ' function ') {
Return '-1 ';
}
for (var i = 0; i < keys.length; i++) {
FN (Keys[i], data[keys[i]], i);
}
};
/**
* Get the corresponding array of key values similar to Java EntrySet ()
*
* @return An array of key value objects {Key,value}
*/
This.entryarray = function () {
var len = keys.length;
var Temparr = new Array (len);
for (var i = 0; i < len; i++) {
Temparr[i] = {
Key:keys[i],
Value:data[keys[i]]
};
}
return Temparr;
};
/**
* Return key array similar to Java Ketset () function
*
* @return Array
*/
This.keyset = function () {
return keys;
}
/**
* Determine if the map is empty
*
* @return NULL return true NOT NULL return FALSE
*/
This.isempty = function () {
return keys.length = = 0;
};
/**
* Returns the size of the map
*/
This.size = function () {
return keys.length;
};
/**
* Rewrite the tostring format as {key1=value1,key2=value2,....}
*/
this.tostring = function () {
var len = keys.length;
var temp = "{";
for (var i = 0; i < len; i++) {
Temp + = (Keys[i] + "=" + Data[keys[i]] + ",");
}
Temp + = "}";
return temp;
};
/**
* Empty Map
*
* @return
*/
This.clear = function () {
for (var i = keys.length-1 i >= 0; i--) {
Delete Data[keys[i]];
Keys.pop (i);
}
};
}
/**------------------------Bytemap test method Start-------------------------* *