8d14155ababc8cb12c1ab524a5a42aa28bce00f8.svn-base 2.6 KB

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