]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/collections/Set.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / collections / Set.js
1 if(!dojo._hasResource["dojox.collections.Set"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.collections.Set"] = true;
3 dojo.provide("dojox.collections.Set");
4 dojo.require("dojox.collections.ArrayList");
5
6 (function(){
7         var dxc=dojox.collections;
8         dxc.Set=new (function(){
9                 function conv(arr){
10                         if(arr.constructor==Array){
11                                 return new dojox.collections.ArrayList(arr);    //      dojox.collections.ArrayList
12                         }
13                         return arr;             //      dojox.collections.ArrayList
14                 }
15                 this.union = function(/* array */setA, /* array */setB){
16                         //      summary
17                         //      Return the union of the two passed sets.
18                         setA=conv(setA);
19                         setB=conv(setB);
20                         var result = new dojox.collections.ArrayList(setA.toArray());
21                         var e = setB.getIterator();
22                         while(!e.atEnd()){
23                                 var item=e.get();
24                                 if(!result.contains(item)){
25                                         result.add(item);
26                                 }
27                         }
28                         return result;  //      dojox.collections.ArrayList
29                 };
30                 this.intersection = function(/* array */setA, /* array */setB){
31                         //      summary
32                         //      Return the intersection of the two passed sets.
33                         setA=conv(setA);
34                         setB=conv(setB);
35                         var result = new dojox.collections.ArrayList();
36                         var e = setB.getIterator();
37                         while(!e.atEnd()){
38                                 var item=e.get();
39                                 if(setA.contains(item)){
40                                         result.add(item);
41                                 }
42                         }
43                         return result;  //      dojox.collections.ArrayList
44                 };
45                 this.difference = function(/* array */setA, /* array */setB){
46                         //      summary
47                         //      Returns everything in setA that is not in setB.
48                         setA=conv(setA);
49                         setB=conv(setB);
50                         var result = new dojox.collections.ArrayList();
51                         var e=setA.getIterator();
52                         while(!e.atEnd()){
53                                 var item=e.get();
54                                 if(!setB.contains(item)){
55                                         result.add(item);
56                                 }
57                         }
58                         return result;  //      dojox.collections.ArrayList
59                 };
60                 this.isSubSet = function(/* array */setA, /* array */setB) {
61                         //      summary
62                         //      Returns if set B is a subset of set A.
63                         setA=conv(setA);
64                         setB=conv(setB);
65                         var e = setA.getIterator();
66                         while(!e.atEnd()){
67                                 if(!setB.contains(e.get())){
68                                         return false;   //      boolean
69                                 }
70                         }
71                         return true;    //      boolean
72                 };
73                 this.isSuperSet = function(/* array */setA, /* array */setB){
74                         //      summary
75                         //      Returns if set B is a superset of set A.
76                         setA=conv(setA);
77                         setB=conv(setB);
78                         var e = setB.getIterator();
79                         while(!e.atEnd()){
80                                 if(!setA.contains(e.get())){
81                                         return false;   //      boolean
82                                 }
83                         }
84                         return true;    //      boolean
85                 };
86         })();
87 })();
88
89 }