| 1 |
define(["dojo/_base/kernel", "dojo/_base/array", "./_base"], function(dojo, darray, dxc){ |
| 2 |
|
| 3 |
dxc.ArrayList=function( arr){ |
| 4 |
|
| 5 |
|
| 6 |
var items=[]; |
| 7 |
if(arr) items=items.concat(arr); |
| 8 |
this.count=items.length; |
| 9 |
this.add=function( obj){ |
| 10 |
|
| 11 |
|
| 12 |
items.push(obj); |
| 13 |
this.count=items.length; |
| 14 |
}; |
| 15 |
this.addRange=function( a){ |
| 16 |
|
| 17 |
|
| 18 |
if(a.getIterator){ |
| 19 |
var e=a.getIterator(); |
| 20 |
while(!e.atEnd()){ |
| 21 |
this.add(e.get()); |
| 22 |
} |
| 23 |
this.count=items.length; |
| 24 |
}else{ |
| 25 |
for(var i=0; i<a.length; i++){ |
| 26 |
items.push(a[i]); |
| 27 |
} |
| 28 |
this.count=items.length; |
| 29 |
} |
| 30 |
}; |
| 31 |
this.clear=function(){ |
| 32 |
|
| 33 |
|
| 34 |
items.splice(0, items.length); |
| 35 |
this.count=0; |
| 36 |
}; |
| 37 |
this.clone=function(){ |
| 38 |
|
| 39 |
|
| 40 |
return new dxc.ArrayList(items); |
| 41 |
}; |
| 42 |
this.contains=function( obj){ |
| 43 |
|
| 44 |
|
| 45 |
for(var i=0; i < items.length; i++){ |
| 46 |
if(items[i] == obj) { |
| 47 |
return true; |
| 48 |
} |
| 49 |
} |
| 50 |
return false; |
| 51 |
}; |
| 52 |
this.forEach=function( fn, scope){ |
| 53 |
|
| 54 |
|
| 55 |
dojo.forEach(items, fn, scope); |
| 56 |
}; |
| 57 |
this.getIterator=function(){ |
| 58 |
|
| 59 |
|
| 60 |
return new dxc.Iterator(items); |
| 61 |
}; |
| 62 |
this.indexOf=function( obj){ |
| 63 |
|
| 64 |
|
| 65 |
for(var i=0; i < items.length; i++){ |
| 66 |
if(items[i] == obj) { |
| 67 |
return i; |
| 68 |
} |
| 69 |
} |
| 70 |
return -1; |
| 71 |
}; |
| 72 |
this.insert=function( i, obj){ |
| 73 |
|
| 74 |
|
| 75 |
items.splice(i,0,obj); |
| 76 |
this.count=items.length; |
| 77 |
}; |
| 78 |
this.item=function( i){ |
| 79 |
|
| 80 |
|
| 81 |
return items[i]; |
| 82 |
}; |
| 83 |
this.remove=function( obj){ |
| 84 |
|
| 85 |
|
| 86 |
var i=this.indexOf(obj); |
| 87 |
if(i >=0) { |
| 88 |
items.splice(i,1); |
| 89 |
} |
| 90 |
this.count=items.length; |
| 91 |
}; |
| 92 |
this.removeAt=function( i){ |
| 93 |
|
| 94 |
|
| 95 |
items.splice(i,1); |
| 96 |
this.count=items.length; |
| 97 |
}; |
| 98 |
this.reverse=function(){ |
| 99 |
|
| 100 |
|
| 101 |
items.reverse(); |
| 102 |
}; |
| 103 |
this.sort=function( fn){ |
| 104 |
|
| 105 |
|
| 106 |
if(fn){ |
| 107 |
items.sort(fn); |
| 108 |
}else{ |
| 109 |
items.sort(); |
| 110 |
} |
| 111 |
}; |
| 112 |
this.setByIndex=function( i, obj){ |
| 113 |
|
| 114 |
|
| 115 |
items[i]=obj; |
| 116 |
this.count=items.length; |
| 117 |
}; |
| 118 |
this.toArray=function(){ |
| 119 |
|
| 120 |
|
| 121 |
return [].concat(items); |
| 122 |
}; |
| 123 |
this.toString=function( delim){ |
| 124 |
|
| 125 |
|
| 126 |
return items.join((delim||",")); |
| 127 |
}; |
| 128 |
}; |
| 129 |
return dxc.ArrayList; |
| 130 |
}); |