Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
5
 
6
dojox.collections.ArrayList=function(/* array? */arr){
7
	//	summary
8
	//	Returns a new object of type dojox.collections.ArrayList
9
	var items=[];
10
	if(arr) items=items.concat(arr);
11
	this.count=items.length;
12
	this.add=function(/* object */obj){
13
		//	summary
14
		//	Add an element to the collection.
15
		items.push(obj);
16
		this.count=items.length;
17
	};
18
	this.addRange=function(/* array */a){
19
		//	summary
20
		//	Add a range of objects to the ArrayList
21
		if(a.getIterator){
22
			var e=a.getIterator();
23
			while(!e.atEnd()){
24
				this.add(e.get());
25
			}
26
			this.count=items.length;
27
		}else{
28
			for(var i=0; i<a.length; i++){
29
				items.push(a[i]);
30
			}
31
			this.count=items.length;
32
		}
33
	};
34
	this.clear=function(){
35
		//	summary
36
		//	Clear all elements out of the collection, and reset the count.
37
		items.splice(0, items.length);
38
		this.count=0;
39
	};
40
	this.clone=function(){
41
		//	summary
42
		//	Clone the array list
43
		return new dojox.collections.ArrayList(items);	//	dojox.collections.ArrayList
44
	};
45
	this.contains=function(/* object */obj){
46
		//	summary
47
		//	Check to see if the passed object is a member in the ArrayList
48
		for(var i=0; i < items.length; i++){
49
			if(items[i] == obj) {
50
				return true;	//	bool
51
			}
52
		}
53
		return false;	//	bool
54
	};
55
	this.forEach=function(/* function */ fn, /* object? */ scope){
56
		//	summary
57
		//	functional iterator, following the mozilla spec.
58
		dojo.forEach(items, fn, scope);
59
	};
60
	this.getIterator=function(){
61
		//	summary
62
		//	Get an Iterator for this object
63
		return new dojox.collections.Iterator(items);	//	dojox.collections.Iterator
64
	};
65
	this.indexOf=function(/* object */obj){
66
		//	summary
67
		//	Return the numeric index of the passed object; will return -1 if not found.
68
		for(var i=0; i < items.length; i++){
69
			if(items[i] == obj) {
70
				return i;	//	int
71
			}
72
		}
73
		return -1;	// int
74
	};
75
	this.insert=function(/* int */ i, /* object */ obj){
76
		//	summary
77
		//	Insert the passed object at index i
78
		items.splice(i,0,obj);
79
		this.count=items.length;
80
	};
81
	this.item=function(/* int */ i){
82
		//	summary
83
		//	return the element at index i
84
		return items[i];	//	object
85
	};
86
	this.remove=function(/* object */obj){
87
		//	summary
88
		//	Look for the passed object, and if found, remove it from the internal array.
89
		var i=this.indexOf(obj);
90
		if(i >=0) {
91
			items.splice(i,1);
92
		}
93
		this.count=items.length;
94
	};
95
	this.removeAt=function(/* int */ i){
96
		//	summary
97
		//	return an array with function applied to all elements
98
		items.splice(i,1);
99
		this.count=items.length;
100
	};
101
	this.reverse=function(){
102
		//	summary
103
		//	Reverse the internal array
104
		items.reverse();
105
	};
106
	this.sort=function(/* function? */ fn){
107
		//	summary
108
		//	sort the internal array
109
		if(fn){
110
			items.sort(fn);
111
		}else{
112
			items.sort();
113
		}
114
	};
115
	this.setByIndex=function(/* int */ i, /* object */ obj){
116
		//	summary
117
		//	Set an element in the array by the passed index.
118
		items[i]=obj;
119
		this.count=items.length;
120
	};
121
	this.toArray=function(){
122
		//	summary
123
		//	Return a new array with all of the items of the internal array concatenated.
124
		return [].concat(items);
125
	}
126
	this.toString=function(/* string */ delim){
127
		//	summary
128
		//	implementation of toString, follows [].toString();
129
		return items.join((delim||","));
130
	};
131
};
132
 
133
}