1 if(!dojo._hasResource["dojox.collections.ArrayList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.collections.ArrayList"] = true;
3 dojo.provide("dojox.collections.ArrayList");
4 dojo.require("dojox.collections._base");
6 dojox.collections.ArrayList=function(/* array? */arr){
8 // Returns a new object of type dojox.collections.ArrayList
10 if(arr) items=items.concat(arr);
11 this.count=items.length;
12 this.add=function(/* object */obj){
14 // Add an element to the collection.
16 this.count=items.length;
18 this.addRange=function(/* array */a){
20 // Add a range of objects to the ArrayList
22 var e=a.getIterator();
26 this.count=items.length;
28 for(var i=0; i<a.length; i++){
31 this.count=items.length;
34 this.clear=function(){
36 // Clear all elements out of the collection, and reset the count.
37 items.splice(0, items.length);
40 this.clone=function(){
42 // Clone the array list
43 return new dojox.collections.ArrayList(items); // dojox.collections.ArrayList
45 this.contains=function(/* object */obj){
47 // Check to see if the passed object is a member in the ArrayList
48 for(var i=0; i < items.length; i++){
55 this.forEach=function(/* function */ fn, /* object? */ scope){
57 // functional iterator, following the mozilla spec.
58 dojo.forEach(items, fn, scope);
60 this.getIterator=function(){
62 // Get an Iterator for this object
63 return new dojox.collections.Iterator(items); // dojox.collections.Iterator
65 this.indexOf=function(/* object */obj){
67 // Return the numeric index of the passed object; will return -1 if not found.
68 for(var i=0; i < items.length; i++){
75 this.insert=function(/* int */ i, /* object */ obj){
77 // Insert the passed object at index i
78 items.splice(i,0,obj);
79 this.count=items.length;
81 this.item=function(/* int */ i){
83 // return the element at index i
84 return items[i]; // object
86 this.remove=function(/* object */obj){
88 // Look for the passed object, and if found, remove it from the internal array.
89 var i=this.indexOf(obj);
93 this.count=items.length;
95 this.removeAt=function(/* int */ i){
97 // return an array with function applied to all elements
99 this.count=items.length;
101 this.reverse=function(){
103 // Reverse the internal array
106 this.sort=function(/* function? */ fn){
108 // sort the internal array
115 this.setByIndex=function(/* int */ i, /* object */ obj){
117 // Set an element in the array by the passed index.
119 this.count=items.length;
121 this.toArray=function(){
123 // Return a new array with all of the items of the internal array concatenated.
124 return [].concat(items);
126 this.toString=function(/* string */ delim){
128 // implementation of toString, follows [].toString();
129 return items.join((delim||","));