Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.collections.ArrayList");
14
dojo.require("dojo.collections.Collections");
15
dojo.collections.ArrayList = function (arr) {
16
	var items = [];
17
	if (arr) {
18
		items = items.concat(arr);
19
	}
20
	this.count = items.length;
21
	this.add = function (obj) {
22
		items.push(obj);
23
		this.count = items.length;
24
	};
25
	this.addRange = function (a) {
26
		if (a.getIterator) {
27
			var e = a.getIterator();
28
			while (!e.atEnd()) {
29
				this.add(e.get());
30
			}
31
			this.count = items.length;
32
		} else {
33
			for (var i = 0; i < a.length; i++) {
34
				items.push(a[i]);
35
			}
36
			this.count = items.length;
37
		}
38
	};
39
	this.clear = function () {
40
		items.splice(0, items.length);
41
		this.count = 0;
42
	};
43
	this.clone = function () {
44
		return new dojo.collections.ArrayList(items);
45
	};
46
	this.contains = function (obj) {
47
		for (var i = 0; i < items.length; i++) {
48
			if (items[i] == obj) {
49
				return true;
50
			}
51
		}
52
		return false;
53
	};
54
	this.forEach = function (fn, scope) {
55
		var s = scope || dj_global;
56
		if (Array.forEach) {
57
			Array.forEach(items, fn, s);
58
		} else {
59
			for (var i = 0; i < items.length; i++) {
60
				fn.call(s, items[i], i, items);
61
			}
62
		}
63
	};
64
	this.getIterator = function () {
65
		return new dojo.collections.Iterator(items);
66
	};
67
	this.indexOf = function (obj) {
68
		for (var i = 0; i < items.length; i++) {
69
			if (items[i] == obj) {
70
				return i;
71
			}
72
		}
73
		return -1;
74
	};
75
	this.insert = function (i, obj) {
76
		items.splice(i, 0, obj);
77
		this.count = items.length;
78
	};
79
	this.item = function (i) {
80
		return items[i];
81
	};
82
	this.remove = function (obj) {
83
		var i = this.indexOf(obj);
84
		if (i >= 0) {
85
			items.splice(i, 1);
86
		}
87
		this.count = items.length;
88
	};
89
	this.removeAt = function (i) {
90
		items.splice(i, 1);
91
		this.count = items.length;
92
	};
93
	this.reverse = function () {
94
		items.reverse();
95
	};
96
	this.sort = function (fn) {
97
		if (fn) {
98
			items.sort(fn);
99
		} else {
100
			items.sort();
101
		}
102
	};
103
	this.setByIndex = function (i, obj) {
104
		items[i] = obj;
105
		this.count = items.length;
106
	};
107
	this.toArray = function () {
108
		return [].concat(items);
109
	};
110
	this.toString = function (delim) {
111
		return items.join((delim || ","));
112
	};
113
};
114