Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.collections.ArrayList");
12
dojo.require("dojo.collections.Collections");
13
dojo.collections.ArrayList = function (arr) {
14
	var items = [];
15
	if (arr) {
16
		items = items.concat(arr);
17
	}
18
	this.count = items.length;
19
	this.add = function (obj) {
20
		items.push(obj);
21
		this.count = items.length;
22
	};
23
	this.addRange = function (a) {
24
		if (a.getIterator) {
25
			var e = a.getIterator();
26
			while (!e.atEnd()) {
27
				this.add(e.get());
28
			}
29
			this.count = items.length;
30
		} else {
31
			for (var i = 0; i < a.length; i++) {
32
				items.push(a[i]);
33
			}
34
			this.count = items.length;
35
		}
36
	};
37
	this.clear = function () {
38
		items.splice(0, items.length);
39
		this.count = 0;
40
	};
41
	this.clone = function () {
42
		return new dojo.collections.ArrayList(items);
43
	};
44
	this.contains = function (obj) {
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
		var s = scope || dj_global;
54
		if (Array.forEach) {
55
			Array.forEach(items, fn, s);
56
		} else {
57
			for (var i = 0; i < items.length; i++) {
58
				fn.call(s, items[i], i, items);
59
			}
60
		}
61
	};
62
	this.getIterator = function () {
63
		return new dojo.collections.Iterator(items);
64
	};
65
	this.indexOf = function (obj) {
66
		for (var i = 0; i < items.length; i++) {
67
			if (items[i] == obj) {
68
				return i;
69
			}
70
		}
71
		return -1;
72
	};
73
	this.insert = function (i, obj) {
74
		items.splice(i, 0, obj);
75
		this.count = items.length;
76
	};
77
	this.item = function (i) {
78
		return items[i];
79
	};
80
	this.remove = function (obj) {
81
		var i = this.indexOf(obj);
82
		if (i >= 0) {
83
			items.splice(i, 1);
84
		}
85
		this.count = items.length;
86
	};
87
	this.removeAt = function (i) {
88
		items.splice(i, 1);
89
		this.count = items.length;
90
	};
91
	this.reverse = function () {
92
		items.reverse();
93
	};
94
	this.sort = function (fn) {
95
		if (fn) {
96
			items.sort(fn);
97
		} else {
98
			items.sort();
99
		}
100
	};
101
	this.setByIndex = function (i, obj) {
102
		items[i] = obj;
103
		this.count = items.length;
104
	};
105
	this.toArray = function () {
106
		return [].concat(items);
107
	};
108
	this.toString = function (delim) {
109
		return items.join((delim || ","));
110
	};
111
};
112