-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSystem.Collections.debug.js
More file actions
576 lines (556 loc) · 19.1 KB
/
System.Collections.debug.js
File metadata and controls
576 lines (556 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
//=============================================================================
// Jocys.com JavaScript.NET Classes (In C# Object Oriented Style)
// Created by Evaldas Jocys <evaldas@jocys.com>
//=============================================================================
/// <reference path="System.debug.js" />
//=============================================================================
// Namespaces
//-----------------------------------------------------------------------------
// <PropertyGroup>
// <RootNamespace>System.Collections</RootNamespace>
// <PropertyGroup>
//-----------------------------------------------------------------------------
System.Type.RegisterNamespace("System.Collections");
//=============================================================================
System.Collections.BitArray = function (length, defaultValue) {
/// <summary>
/// Initializes a new instance of the System.Collections.BitArray class that
/// can hold the specified number of bit values, which are initially set to the
/// specified value.
/// </summary>
/// <param type="int" name="length"> The number of bit values in the new System.Collections.BitArray.</param>
/// <param type="bool" name="defaultValue">The Boolean value to assign to each bit.</param>
/// <remarks>This object is here for xml comments only</remarks>
};
System.Collections.BitArray = function (numbers, bpn) {
/// <summary>
/// Initializes a new instance of the System.Collections.BitArray class that
/// contains bit values copied from the specified array of bytes.
/// </summary>
/// <param type="array[]" name="numbers">An array of numbers</param>
/// <param type="int" name="bpn">
/// Optional. Bits per number: 8 byte (default), 16 - Int16, 32 - Int32.
/// </param>
//---------------------------------------------------------
function NumberToBits(value, buffer, offset, count) {
/// <summary>
/// Write value as bits into array.
/// </summary>
/// <param name="value">Number value.<param>
/// <param name="buffer">The destination buffer.</param>
/// <param name="offset">The byte offset into buffer.</param>
/// <param name="count">The number of bits to copy.</param>
// Bits of numbers will be stored in
// Little-endian format - lowest order (little) numbers coming first.
for (var b = 0; b < count; b++) {
buffer[offset + b] = value & 0x1 ? true : false;
value = value >> 1;
}
}
//---------------------------------------------------------
this.Initialize = function () {
var a0 = arguments[0];
var a1 = arguments[1];
var data = null;
// Bits per number.
if (typeof a0 === "number") {
// -------------------------
// System.Collections.BitArray(length, defaultValue);
data = new Array(a0);
// Make sure that default value is true or false;
a1 = a1 ? true : false;
// Route througth bitArray...
for (var i = 0; i < length; i++) {
data[i] = a1;
}
} else {
// -------------------------
// System.Collections.BitArray(numbers, bpn);
var bpn = a1 ? a1 : 8;
var length = a0.length;
data = new Array(length * bpn);
// Route througth numbers...
for (var x = 0; x < length; x++) {
var n = a0[x];
// Fill array with number bits.
NumberToBits(n, data, x * bpn, bpn);
}
}
return data;
};
return this.Initialize.apply(this, arguments);
};
System.Collections.BitArray.ToString = function (array, bpn) {
/// <summary>
/// Function for converting bit array into string representation.
/// </summary>
/// <param name="array">Bits array</param>
/// <param name="bpn">Bits per number. Used to split string representation.</param>
/// <returns>String representation of bits array</returns>
/// <remarks>
/// There is no static function System.Collections.BitArray.ToString(array, bpn) in .NET.
/// </remarks>
var length = array.length;
bpn = arguments[1] ? arguments[1] : 8;
var sb = new System.Text.StringBuilder();
for (var i = 0; i < length; i++) {
if (i > 0 && i % bpn === 0) sb.Append(' ');
sb.Append(array[i] ? '1' : '0');
}
return "[" + sb.ToString() + "]";
};
//=============================================================================
// CLASS: System.Collections.DictionaryEntry
//-----------------------------------------------------------------------------
System.Collections.DictionaryEntry = function (key, value) {
/// <summary>
///
/// </summary>
this.Key;
this.Value;
//---------------------------------------------------------
// METHOD: Equals
//---------------------------------------------------------
// Determines whether two instances are equal.
this.Equals = function (item) {
var equal = true;
equal = equal && this.Key === item.Key;
equal = equal && this.Value === item.Value;
return equal;
};
//---------------------------------------------------------
// METHOD: ToString
//---------------------------------------------------------
// Returns a String that represents the current Object.
this.ToString = function () {
return "HashtableItem[Key='" + this.Key + "';Value='" + this.Value + "']";
};
//---------------------------------------------------------
// INIT: Class
//---------------------------------------------------------
this.InitializeClass = function () {
this.Key = key;
this.Value = value;
};
this.InitializeClass();
};
//=============================================================================
// CLASS: System.Collections.Hashtable
//-----------------------------------------------------------------------------
System.Collections.Hashtable = function () {
/// <summary>
///
/// </summary>
//---------------------------------------------------------
// PROPERTY: Items
//---------------------------------------------------------
this.Items;
this.Count;
//---------------------------------------------------------
// METHOD: GetKeys
//---------------------------------------------------------
// Get array of keys from the Hashtable.
this.GetKeys = function (key) {
var keys = [];
for (var property in this.Items) {
keys.push(property);
}
return keys;
};
//---------------------------------------------------------
// METHOD: GetValues
//---------------------------------------------------------
// Get array of values from the Hashtable.
this.GetValues = function (value) {
var values = [];
for (var property in this.Items) {
values.push(this.Items[property]);
}
return values;
};
//---------------------------------------------------------
// METHOD: GetValue
//---------------------------------------------------------
// Get value by key.
this.GetValue = function (key) {
return this.Items[key];
};
//---------------------------------------------------------
// METHOD: GetKey
//---------------------------------------------------------
// Get first key by value;
this.GetKey = function (value) {
var key;
for (var property in this.Items) {
if (this.Items[property] === value) {
key = property;
break;
}
}
return key;
};
//---------------------------------------------------------
// METHOD: Add
//---------------------------------------------------------
// Adds an element with the specified key and value into the Hashtable.
this.Add = function (key, value) {
var containsKey = this.ContainsKey(key);
if (!containsKey) this.Count++;
this.Items[key] = value;
return !containsKey;
};
//---------------------------------------------------------
// METHOD: Remove
//---------------------------------------------------------
// Removes the element with the specified key from the Hashtable.
this.Remove = function (key) {
var containsKey = this.ContainsKey(key);
if (containsKey) {
this.Count--;
delete this.Items[key];
}
return !containsKey;
};
//---------------------------------------------------------
// METHOD: Clear
//---------------------------------------------------------
// Removes all items.
this.Clear = function () {
this.Items = {};
};
//---------------------------------------------------------
// METHOD: ContainsKey
//---------------------------------------------------------
// Determines whether the Hashtable contains a specific key.
this.ContainsKey = function (key) {
return typeof this.Items[key] !== "undefined";
};
//---------------------------------------------------------
// METHOD: ContainsValue
//---------------------------------------------------------
// Determines whether the Hashtable contains a specific value.
this.ContainsValue = function (value) {
return typeof this.GetKey(value) !== "undefined";
};
//---------------------------------------------------------
// METHOD: ToString
//---------------------------------------------------------
// Returns a String that represents the current Object.
this.ToString = function () {
return this.GetType().Name + "[Count=" + Count + "]";
};
//---------------------------------------------------------
// INIT: Class
//---------------------------------------------------------
this.InitializeClass = function () {
// Use array to store items (slower).
this.Items = {};
this.Count = 0;
};
this.InitializeClass();
};
//=============================================================================
// CLASS: System.Collections.List
//-----------------------------------------------------------------------------
System.Collections.List = function () {
/// <summary>
///
/// </summary>
this.KeyIsUnique;
this.ValueIsUnique;
//---------------------------------------------------------
// PROPERTY: Items
//---------------------------------------------------------
this.Items;
//---------------------------------------------------------
// METHOD: _indexOf
//---------------------------------------------------------
this._indexOf = function (property, value) {
var index = -1;
for (var i = 0; i < this.Items.length; i++) {
if (this.Items[i][property] === value) {
index = i;
break;
}
}
return;
};
//---------------------------------------------------------
// METHOD: _getItems
//---------------------------------------------------------
// Returns: System.Collections.DictionaryEntry[]
this._getItemsBy = function (property, value, single) {
var items = [];
var i;
// Get all objects.
if (typeof value === "undefined") {
for (i = 0; i < this.Items.length; i++) {
items.push(this.Items[i]);
}
} else {
// Get objects by value.
for (i = 0; i < this.Items.length; i++) {
if (this.Items[i][property] === value) {
items.push(this.Items[i]);
if (single) break;
}
}
}
return items;
};
//---------------------------------------------------------
// METHOD: _getObjectsBy
//---------------------------------------------------------
// Returns: object[]
this._getObjectsBy = function (property, value, single) {
var objects = [];
var i;
// Get all objects.
if (typeof value === "undefined") {
for (i = 0; i < this.Items.length; i++) {
objects.push(this.Items[i][property]);
}
} else {
// Get objects by value.
for (i = 0; i < this.Items.length; i++) {
if (this.Items[i][property] === value) {
objects.push(this.Items[i][property]);
if (single) break;
}
}
}
return objects;
};
//---------------------------------------------------------
// METHOD: IndexOfKey
//---------------------------------------------------------
// Get index of key (only if not unique).
this.IndexOfKey = function (key) {
return this._indexOf("Key", key);
};
//---------------------------------------------------------
// METHOD: GetIndexByValue
//---------------------------------------------------------
// Get index of value (only if not unique).
this.IndexOfValue = function (value) {
return this._indexOf("Value", value);
};
//---------------------------------------------------------
// METHOD: GetKeys
//---------------------------------------------------------
// Get array of keys from the Hashtable.
this.GetKeys = function () {
return this._getObjectsBy("Key", key, this.KeyIsUnique);
};
//---------------------------------------------------------
// METHOD: GetValues
//---------------------------------------------------------
// Get array of values from the Hashtable.
this.GetValues = function () {
return this._getObjectsBy("Value", value, this.ValueIsUnique);
};
//---------------------------------------------------------
// METHOD: GetValue
//---------------------------------------------------------
// Get first value by key.
this.GetValue = function (key) {
var value;
var items = this._getItemsBy("Key", key, true);
if (items.length > 0) value = items[0].Value;
return value;
};
//---------------------------------------------------------
// METHOD: GetKey
//---------------------------------------------------------
// Get first key by value;
this.GetKey = function (value) {
var key;
var items = this._getItemsBy("Value", value, true);
if (items.length > 0) key = items[0].Key;
return key;
};
//---------------------------------------------------------
// METHOD: Add
//---------------------------------------------------------
// Adds an element with the specified key and value into the Hashtable.
this.Add = function (key, value) {
var allow = true;
if (this.KeyIsUnique) allow = allow && this.IndexOfKey === -1;
if (this.ValueIsUnique) allow = allow && this.IndexOfValue === -1;
if (allow) {
var item = new System.Collections.DictionaryEntry(key, value);
this.Items.push(item);
}
return allow;
};
//---------------------------------------------------------
// METHOD: Remove
//---------------------------------------------------------
// Removes the element with the specified key from the Hashtable.
this.Remove = function (key) {
var index;
var removed = false;
while (index !== -1) {
index = this._indexOf("Key", key);
if (index > -1) {
this.Items.splice(index, 1);
removed = true;
}
}
return removed;
};
//---------------------------------------------------------
// METHOD: Clear
//---------------------------------------------------------
// Removes all items.
this.Clear = function () {
this.Items = [];
};
//---------------------------------------------------------
// METHOD: ContainsKey
//---------------------------------------------------------
// Determines whether the Hashtable contains a specific key.
this.ContainsKey = function (key) {
return this._indexOf("Key", key) > -1;
};
//---------------------------------------------------------
// METHOD: ContainsValue
//---------------------------------------------------------
// Determines whether the Hashtable contains a specific value.
this.ContainsValue = function (value) {
return this._indexOf("Value", value) > -1;
};
//---------------------------------------------------------
// METHOD: ToString
//---------------------------------------------------------
// Returns a String that represents the current Object.
this.ToString = function () {
return this.GetType().Name + "[Items.length=" + this.Items.length + "]";
};
//---------------------------------------------------------
// INIT: Class
//---------------------------------------------------------
this.InitializeClass = function () {
// Use array to store items (slower).
this.Items = [];
this.KeyIsUnique = false;
this.ValueIsUnique = false;
};
this.InitializeClass();
};
//=============================================================================
// CLASS: System.Collections.SortedList
//-----------------------------------------------------------------------------
System.Collections.SortedList = function () {
/// <summary>
///
/// </summary>
this.Items = [];
//var aa = new ActiveXObject("Scripting.Dictionary");
//---------------------------------------------------------
// INIT: Class
//---------------------------------------------------------
this.Add = function (key, value) {
// If user submited number then just set value.
if (new String(parseInt(key)) === key) {
this.Items[key] = value;
} else {
if (this.Items[key] === null) this.Items.push(value);
this.Items[key] = value;
}
};
this.push = function (value) {
this.Add(this.length, value);
};
this.ContainsKey = function (key) {
this._keys.push(key);
this._values.push(value);
};
};
//=============================================================================
// CLASS: System.Collections.ArrayUniqueValueAdd
//-----------------------------------------------------------------------------
System.Collections.ArrayUniqueValueAdd = function (array, value, propertyName) {
/// <summary>
///
/// </summary>
if (typeof array === "object") {
var itemExist = false;
var i;
if (property === null) {
for (i = 0; i < array.length; i++) {
if (array[i] === value) {
itemExist = true;
break;
}
}
} else {
for (i = 0; i < array.length; i++) {
//Trace.Write(propertyName+" "+array[f][propertyName]+" "+value.ticketId);
if (array[i][propertyName] === value[propertyName]) {
itemExist = true;
break;
}
}
}
// If value does not exist then...
if (itemExist === false) {
// Add value to array.
//Trace.Write("Push value");
array.push(value);
}
}
};
//=============================================================================
// CLASS: System.Collections.ArrayUniqueValueRemove
//-----------------------------------------------------------------------------
System.Collections.ArrayUniqueValueRemove = function (array, value, propertyName) {
/// <summary>
/// This will remove one value by key from array. It works faster than ArrayValueRemove.
/// </summary>
if (typeof array === "object") {
var i;
if (property === null) {
for (i = 0; i < array.length; i++) {
if (array[i] === value) {
array.splice(i, 1);
break;
}
}
} else {
for (i = 0; i < array.length; i++) {
if (array[i][propertyName] === value[propertyName]) {
array.splice(i, 1);
break;
}
}
}
}
};
//=============================================================================
// CLASS: System.Collections.ArrayValueRemove
//-----------------------------------------------------------------------------
System.Collections.ArrayValueRemove = function (array, value, propertyName) {
/// <summary>
/// This will remove all values by key from array. It works slower than ArrayUniqueValueRemove.
/// </summary>
if (typeof array === "object") {
var i;
if (property === null) {
for (i = 0; i < array.length; i++) {
if (array[i] === value) {
array.splice(i, 1);
}
}
} else {
for (i = 0; i < array.length; i++) {
if (array[i][propertyName] === value[propertyName]) {
array.splice(i, 1);
}
}
}
}
};
//==============================================================================
// END
//------------------------------------------------------------------------------