Diffstat (limited to 'frontend/beta/js/Clipperz/Set.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Set.js | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/Set.js b/frontend/beta/js/Clipperz/Set.js new file mode 100644 index 0000000..61e0769 --- a/dev/null +++ b/frontend/beta/js/Clipperz/Set.js | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | |||
30 | if (typeof(Clipperz) == 'undefined') { | ||
31 | Clipperz = {}; | ||
32 | } | ||
33 | |||
34 | //############################################################################# | ||
35 | |||
36 | Clipperz.Set = function(args) { | ||
37 | args = args || {}; | ||
38 | //MochiKit.Base.bindMethods(this); | ||
39 | |||
40 | if (args.items != null) { | ||
41 | this._items = args.items.slice(); | ||
42 | } else { | ||
43 | this._items = []; | ||
44 | } | ||
45 | |||
46 | return this; | ||
47 | } | ||
48 | |||
49 | //============================================================================= | ||
50 | |||
51 | Clipperz.Set.prototype = MochiKit.Base.update(null, { | ||
52 | |||
53 | //------------------------------------------------------------------------- | ||
54 | |||
55 | 'toString': function() { | ||
56 | return "Clipperz.Set"; | ||
57 | }, | ||
58 | |||
59 | //------------------------------------------------------------------------- | ||
60 | |||
61 | 'items': function() { | ||
62 | return this._items; | ||
63 | }, | ||
64 | |||
65 | //------------------------------------------------------------------------- | ||
66 | |||
67 | 'popAnItem': function() { | ||
68 | var result; | ||
69 | |||
70 | if (this.size() > 0) { | ||
71 | result = this.items().pop(); | ||
72 | } else { | ||
73 | result = null; | ||
74 | } | ||
75 | |||
76 | return result; | ||
77 | }, | ||
78 | |||
79 | //------------------------------------------------------------------------- | ||
80 | |||
81 | 'allItems': function() { | ||
82 | return this.items(); | ||
83 | }, | ||
84 | |||
85 | //------------------------------------------------------------------------- | ||
86 | |||
87 | 'contains': function(anItem) { | ||
88 | return (this.indexOf(anItem) != -1); | ||
89 | }, | ||
90 | |||
91 | //------------------------------------------------------------------------- | ||
92 | |||
93 | 'indexOf': function(anItem) { | ||
94 | varresult; | ||
95 | vari, c; | ||
96 | |||
97 | result = -1; | ||
98 | |||
99 | c = this.items().length; | ||
100 | for (i=0; (i<c) && (result == -1); i++) { | ||
101 | if (this.items()[i] === anItem) { | ||
102 | result = i; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | return result; | ||
107 | }, | ||
108 | |||
109 | //------------------------------------------------------------------------- | ||
110 | |||
111 | 'add': function(anItem) { | ||
112 | if (anItem.constructor == Array) { | ||
113 | MochiKit.Base.map(MochiKit.Base.bind(this,add, this), anItem); | ||
114 | } else { | ||
115 | if (! this.contains(anItem)) { | ||
116 | this.items().push(anItem); | ||
117 | } | ||
118 | } | ||
119 | }, | ||
120 | |||
121 | //------------------------------------------------------------------------- | ||
122 | |||
123 | 'debug': function() { | ||
124 | vari, c; | ||
125 | |||
126 | result = -1; | ||
127 | |||
128 | c = this.items().length; | ||
129 | for (i=0; i<c; i++) { | ||
130 | alert("[" + i + "] " + this.items()[i].label); | ||
131 | } | ||
132 | }, | ||
133 | |||
134 | //------------------------------------------------------------------------- | ||
135 | |||
136 | 'remove': function(anItem) { | ||
137 | if (anItem.constructor == Array) { | ||
138 | MochiKit.Base.map(MochiKit.Base.bind(this.remove, this), anItem); | ||
139 | } else { | ||
140 | varitemIndex; | ||
141 | |||
142 | itemIndex = this.indexOf(anItem); | ||
143 | if (itemIndex != -1) { | ||
144 | this.items().splice(itemIndex, 1); | ||
145 | } | ||
146 | } | ||
147 | }, | ||
148 | |||
149 | //------------------------------------------------------------------------- | ||
150 | |||
151 | 'size': function() { | ||
152 | return this.items().length; | ||
153 | }, | ||
154 | |||
155 | //------------------------------------------------------------------------- | ||
156 | |||
157 | 'empty': function() { | ||
158 | this.items().splice(0, this.items().length); | ||
159 | }, | ||
160 | |||
161 | //------------------------------------------------------------------------- | ||
162 | |||
163 | __syntaxFix__: "syntax fix" | ||
164 | |||
165 | //------------------------------------------------------------------------- | ||
166 | }); | ||
167 | |||