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
77
78
79
80
81
82
83
84
85
86
87
88
|
/**
*@class ArrayList
*@description
*@time 2014-09-16 21:59
*@author StarZou
**/
function ArrayList(arr) {
this ._elementData = arr || [];
}
var arrayListPrototype = {
'_arrayPrototype' : Array.prototype,
'_getData' : function () {
return this ._elementData;
},
'size' : function () {
return this ._getData().length;
},
'isEmpty' : function () {
return this .size() === 0;
},
'contains' : function (obj) {
return this .indexOf(obj) > -1;
},
'indexOf' : function (obj) {
var i , data = this ._getData(), length = data.length;
for (i = 0; i < length; i++) {
if (obj === data[i]) {
return i;
}
}
return -1;
},
'lastIndexOf' : function (obj) {
var i , data = this ._getData(), length = data.length;
for (i = length - 1; i > -1; i--) {
if (obj === data[i]) {
return i;
}
}
return -1;
},
'get' : function (index) {
return this ._getData()[index];
},
'set' : function (index, element) {
this ._getData()[index] = element;
},
'add' : function (index, element) {
if (element) {
this .set(index, element);
} else {
return this ._getData().push(index);
}
},
'remove' : function (index) {
var oldValue = this ._getData()[index];
this ._getData()[index] = null ;
return oldValue;
},
'clear' : function () {
this ._getData().length = 0;
},
'addAll' : function (index, array) {
if (array) {
this ._getData().splice(index, 0, array);
} else {
this ._arrayPrototype.push.apply( this ._getData(), index);
}
}
};
ArrayList.prototype = arrayListPrototype;
|