Queue.js
1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* An internal Queue class.
* @private
*/
Ext.define('Ext.util.Queue', {
constructor: function() {
this.clear();
},
add : function(obj) {
var me = this,
key = me.getKey(obj);
if (!me.map[key]) {
++me.length;
me.items.push(obj);
me.map[key] = obj;
}
return obj;
},
/**
* Removes all items from the collection.
*/
clear : function(){
var me = this,
items = me.items;
me.items = [];
me.map = {};
me.length = 0;
return items;
},
contains: function (obj) {
var key = this.getKey(obj);
return this.map.hasOwnProperty(key);
},
/**
* Returns the number of items in the collection.
* @return {Number} the number of items in the collection.
*/
getCount : function(){
return this.length;
},
getKey : function(obj){
return obj.id;
},
/**
* Remove an item from the collection.
* @param {Object} obj The item to remove.
* @return {Object} The item removed or false if no item was removed.
*/
remove : function(obj){
var me = this,
key = me.getKey(obj),
items = me.items,
index;
if (me.map[key]) {
index = Ext.Array.indexOf(items, obj);
Ext.Array.erase(items, index, 1);
delete me.map[key];
--me.length;
}
return obj;
}
});