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