@@ -11,9 +11,9 @@ class ArrayList<T> implements IList<T> {
11
11
* Inner content
12
12
*/
13
13
private _content : Array < T > ;
14
-
14
+
15
15
//endregion Fields
16
-
16
+
17
17
//region Constructors
18
18
19
19
/**
@@ -27,15 +27,15 @@ class ArrayList<T> implements IList<T> {
27
27
source . forEach ( x => this . add ( x ) ) ;
28
28
}
29
29
}
30
-
30
+
31
31
//endregion Constructors
32
-
32
+
33
33
//region Methods
34
-
34
+
35
35
//region Private Methods
36
-
36
+
37
37
//endregion Private Methods
38
-
38
+
39
39
//region Public Methods
40
40
41
41
//region IList
@@ -173,7 +173,7 @@ class ArrayList<T> implements IList<T> {
173
173
a = new Array < T > ( ) ;
174
174
this . forEach ( e => a . push ( e ) ) ;
175
175
CollectionUtils . ArrayUtils . sort ( a , getter ) ;
176
-
176
+
177
177
for ( var i = 0 ; i < a . length ; i ++ ) {
178
178
outcome . add ( a [ i ] ) ;
179
179
}
@@ -194,7 +194,7 @@ class ArrayList<T> implements IList<T> {
194
194
a = new Array < T > ( ) ;
195
195
this . forEach ( e => a . push ( e ) ) ;
196
196
CollectionUtils . ArrayUtils . sort ( a , getter , false ) ;
197
-
197
+
198
198
for ( var i = 0 ; i < a . length ; i ++ ) {
199
199
outcome . add ( a [ i ] ) ;
200
200
}
@@ -218,6 +218,14 @@ class ArrayList<T> implements IList<T> {
218
218
219
219
//region ICollection
220
220
221
+ average ( getter : Func < T , number > ) : number {
222
+ return CollectionUtils . CollectionHelper . average ( this , getter ) ;
223
+ }
224
+
225
+ exists ( selector : Func < T , boolean > ) : boolean {
226
+ return this . find ( selector ) !== null ;
227
+ }
228
+
221
229
find ( selector : Func < T , boolean > ) : T {
222
230
var size : number ;
223
231
@@ -245,67 +253,36 @@ class ArrayList<T> implements IList<T> {
245
253
}
246
254
}
247
255
248
- map ( action : Func < T , T > ) : ICollection < T > {
256
+ intersect ( collection : ICollection < T > ) : ICollection < T > {
249
257
var outcome : ArrayList < T > ;
250
258
251
259
outcome = new ArrayList < T > ( ) ;
252
- this . forEach ( e => outcome . add ( action ( e ) ) ) ;
253
-
254
- return outcome ;
255
- }
256
-
257
- max ( getter : Func < T , number > ) : T {
258
- var max : number ;
259
- var current : T ;
260
-
261
- if ( this . getLength ( ) === 0 ) {
262
- return null ;
263
- }
264
-
265
- current = this . getAt ( 0 ) ;
266
- max = getter ( current ) ;
267
-
268
260
this . forEach (
269
- ( e ) => {
270
- var value : number ;
271
-
272
- value = getter ( e ) ;
273
-
274
- if ( value > max ) {
275
- max = value ;
276
- current = e ;
261
+ ( x ) => {
262
+ if ( collection . exists ( e => e === x ) ) {
263
+ outcome . add ( x ) ;
277
264
}
278
265
}
279
266
) ;
280
267
281
- return current ;
268
+ return outcome ;
282
269
}
283
270
284
- min ( getter : Func < T , number > ) : T {
285
- var min : number ;
286
- var current : T ;
287
-
288
- if ( this . getLength ( ) === 0 ) {
289
- return null ;
290
- }
291
-
292
- current = this . getAt ( 0 ) ;
293
- min = getter ( current ) ;
271
+ map ( action : Func < T , T > ) : ICollection < T > {
272
+ var outcome : ArrayList < T > ;
294
273
295
- this . forEach (
296
- ( e ) => {
297
- var value : number ;
274
+ outcome = new ArrayList < T > ( ) ;
275
+ this . forEach ( e => outcome . add ( action ( e ) ) ) ;
298
276
299
- value = getter ( e ) ;
277
+ return outcome ;
278
+ }
300
279
301
- if ( value < min ) {
302
- min = value ;
303
- current = e ;
304
- }
305
- }
306
- ) ;
280
+ max ( getter : Func < T , number > ) : T {
281
+ return CollectionUtils . CollectionHelper . max ( this , getter ) ;
282
+ }
307
283
308
- return current ;
284
+ min ( getter : Func < T , number > ) : T {
285
+ return CollectionUtils . CollectionHelper . min ( this , getter ) ;
309
286
}
310
287
311
288
select ( selector : Func < T , boolean > ) : ICollection < T > {
@@ -325,39 +302,54 @@ class ArrayList<T> implements IList<T> {
325
302
}
326
303
327
304
sum ( getter : Func < T , number > ) : number {
328
- var acc : number ;
329
-
330
- acc = 0 ;
331
- this . forEach ( e => acc += getter ( e ) ) ;
332
-
333
- return acc ;
305
+ return CollectionUtils . CollectionHelper . sum ( this , getter ) ;
334
306
}
335
307
336
308
toArray ( ) : Array < T > {
337
- var outcome : Array < T > ;
309
+ return CollectionUtils . CollectionHelper . toArray ( this ) ;
310
+ }
338
311
339
- outcome = new Array < T > ( ) ;
340
- this . forEach ( x => outcome . push ( x ) ) ;
312
+ toDictionary < K , V > ( keyGetter : Func < T , K > , valueGetter : Func < T , V > ) : IDictionary < K , V > {
313
+ return CollectionUtils . CollectionHelper . toDictionary ( this , keyGetter , valueGetter ) ;
314
+ }
341
315
342
- return outcome ;
316
+ toList ( ) : IList < T > {
317
+ return CollectionUtils . CollectionHelper . toList ( this ) ;
343
318
}
344
319
345
- toDictionary < K , V > ( keyGetter : Func < T , K > , valueGetter : Func < T , V > ) : IDictionary < K , V > {
346
- var outcome : IDictionary < K , V > ;
320
+ union ( collection : ICollection < T > ) : ICollection < T > {
321
+ var outcome : ArrayList < T > ;
347
322
348
- outcome = new Dictionary < K , V > ( ) ;
349
- this . forEach ( x => outcome . add ( keyGetter ( x ) , valueGetter ( x ) ) ) ;
323
+ outcome = new ArrayList < T > ( this ) ;
324
+ collection . forEach (
325
+ ( x ) => {
326
+ if ( ! this . exists ( e => e === x ) ) {
327
+ outcome . add ( x ) ;
328
+ }
329
+ }
330
+ ) ;
350
331
351
332
return outcome ;
352
333
}
353
334
354
- toList ( ) : IList < T > {
355
- return new ArrayList < T > ( this ) ;
335
+ uniq ( ) : ICollection < T > {
336
+ var outcome : ArrayList < T > ;
337
+
338
+ outcome = new ArrayList < T > ( ) ;
339
+ this . forEach (
340
+ ( x ) => {
341
+ if ( ! outcome . exists ( e => e === x ) ) {
342
+ outcome . add ( x ) ;
343
+ }
344
+ }
345
+ ) ;
346
+
347
+ return outcome ;
356
348
}
357
349
358
350
//endregion ICollection
359
-
351
+
360
352
//endregion Public Methods
361
-
353
+
362
354
//endregion Methods
363
355
}
0 commit comments