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