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.Set");
14
dojo.require("dojo.collections.Collections");
15
dojo.require("dojo.collections.ArrayList");
16
dojo.collections.Set = new function () {
17
	this.union = function (setA, setB) {
18
		if (setA.constructor == Array) {
19
			var setA = new dojo.collections.ArrayList(setA);
20
		}
21
		if (setB.constructor == Array) {
22
			var setB = new dojo.collections.ArrayList(setB);
23
		}
24
		if (!setA.toArray || !setB.toArray) {
25
			dojo.raise("Set operations can only be performed on array-based collections.");
26
		}
27
		var result = new dojo.collections.ArrayList(setA.toArray());
28
		var e = setB.getIterator();
29
		while (!e.atEnd()) {
30
			var item = e.get();
31
			if (!result.contains(item)) {
32
				result.add(item);
33
			}
34
		}
35
		return result;
36
	};
37
	this.intersection = function (setA, setB) {
38
		if (setA.constructor == Array) {
39
			var setA = new dojo.collections.ArrayList(setA);
40
		}
41
		if (setB.constructor == Array) {
42
			var setB = new dojo.collections.ArrayList(setB);
43
		}
44
		if (!setA.toArray || !setB.toArray) {
45
			dojo.raise("Set operations can only be performed on array-based collections.");
46
		}
47
		var result = new dojo.collections.ArrayList();
48
		var e = setB.getIterator();
49
		while (!e.atEnd()) {
50
			var item = e.get();
51
			if (setA.contains(item)) {
52
				result.add(item);
53
			}
54
		}
55
		return result;
56
	};
57
	this.difference = function (setA, setB) {
58
		if (setA.constructor == Array) {
59
			var setA = new dojo.collections.ArrayList(setA);
60
		}
61
		if (setB.constructor == Array) {
62
			var setB = new dojo.collections.ArrayList(setB);
63
		}
64
		if (!setA.toArray || !setB.toArray) {
65
			dojo.raise("Set operations can only be performed on array-based collections.");
66
		}
67
		var result = new dojo.collections.ArrayList();
68
		var e = setA.getIterator();
69
		while (!e.atEnd()) {
70
			var item = e.get();
71
			if (!setB.contains(item)) {
72
				result.add(item);
73
			}
74
		}
75
		return result;
76
	};
77
	this.isSubSet = function (setA, setB) {
78
		if (setA.constructor == Array) {
79
			var setA = new dojo.collections.ArrayList(setA);
80
		}
81
		if (setB.constructor == Array) {
82
			var setB = new dojo.collections.ArrayList(setB);
83
		}
84
		if (!setA.toArray || !setB.toArray) {
85
			dojo.raise("Set operations can only be performed on array-based collections.");
86
		}
87
		var e = setA.getIterator();
88
		while (!e.atEnd()) {
89
			if (!setB.contains(e.get())) {
90
				return false;
91
			}
92
		}
93
		return true;
94
	};
95
	this.isSuperSet = function (setA, setB) {
96
		if (setA.constructor == Array) {
97
			var setA = new dojo.collections.ArrayList(setA);
98
		}
99
		if (setB.constructor == Array) {
100
			var setB = new dojo.collections.ArrayList(setB);
101
		}
102
		if (!setA.toArray || !setB.toArray) {
103
			dojo.raise("Set operations can only be performed on array-based collections.");
104
		}
105
		var e = setB.getIterator();
106
		while (!e.atEnd()) {
107
			if (!setA.contains(e.get())) {
108
				return false;
109
			}
110
		}
111
		return true;
112
	};
113
}();
114