| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // patch classes for Int8List ..... Float64List and ByteData implementations. | 5 // patch classes for Int8List ..... Float64List and ByteData implementations. |
| 6 | 6 |
| 7 patch class Int8List { | 7 patch class Int8List { |
| 8 /* patch */ factory Int8List(int length) { | 8 /* patch */ factory Int8List(int length) { |
| 9 return new _Int8Array(length); | 9 return new _Int8Array(length); |
| 10 } | 10 } |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 | 311 |
| 312 // Based class for _TypedList that provides common methods for implementing | 312 // Based class for _TypedList that provides common methods for implementing |
| 313 // the collection and list interfaces. | 313 // the collection and list interfaces. |
| 314 | 314 |
| 315 abstract class _TypedListBase { | 315 abstract class _TypedListBase { |
| 316 | 316 |
| 317 // Method(s) implementing the Collection interface. | 317 // Method(s) implementing the Collection interface. |
| 318 bool contains(element) => IterableMixinWorkaround.contains(this, element); | 318 bool contains(element) => IterableMixinWorkaround.contains(this, element); |
| 319 | 319 |
| 320 void forEach(void f(num element)) { | 320 void forEach(void f(element)) { |
| 321 var len = this.length; | 321 var len = this.length; |
| 322 for (var i = 0; i < len; i++) { | 322 for (var i = 0; i < len; i++) { |
| 323 f(this[i]); | 323 f(this[i]); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 Iterable map(f(num element)) { | 327 Iterable map(f(element)) { |
| 328 return IterableMixinWorkaround.mapList(this, f); | 328 return IterableMixinWorkaround.mapList(this, f); |
| 329 } | 329 } |
| 330 | 330 |
| 331 String join([String separator = ""]) { | 331 String join([String separator = ""]) { |
| 332 return IterableMixinWorkaround.join(this, separator); | 332 return IterableMixinWorkaround.join(this, separator); |
| 333 } | 333 } |
| 334 | 334 |
| 335 num reduce(dynamic combine(num value, num element)) { | 335 dynamic reduce(dynamic combine(value, element)) { |
| 336 return IterableMixinWorkaround.reduce(this, combine); | 336 return IterableMixinWorkaround.reduce(this, combine); |
| 337 } | 337 } |
| 338 | 338 |
| 339 dynamic fold(dynamic initialValue, | 339 dynamic fold(dynamic initialValue, |
| 340 dynamic combine(dynamic initialValue, num element)) { | 340 dynamic combine(dynamic initialValue, element)) { |
| 341 return IterableMixinWorkaround.fold(this, initialValue, combine); | 341 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 342 } | 342 } |
| 343 | 343 |
| 344 Iterable where(bool f(num element)) { | 344 Iterable where(bool f(element)) { |
| 345 return IterableMixinWorkaround.where(this, f); | 345 return IterableMixinWorkaround.where(this, f); |
| 346 } | 346 } |
| 347 | 347 |
| 348 Iterable expand(Iterable f(num element)) { | 348 Iterable expand(Iterable f(element)) { |
| 349 return IterableMixinWorkaround.expand(this, f); | 349 return IterableMixinWorkaround.expand(this, f); |
| 350 } | 350 } |
| 351 | 351 |
| 352 Iterable take(int n) { | 352 Iterable take(int n) { |
| 353 return IterableMixinWorkaround.takeList(this, n); | 353 return IterableMixinWorkaround.takeList(this, n); |
| 354 } | 354 } |
| 355 | 355 |
| 356 Iterable takeWhile(bool test(num element)) { | 356 Iterable takeWhile(bool test(element)) { |
| 357 return IterableMixinWorkaround.takeWhile(this, test); | 357 return IterableMixinWorkaround.takeWhile(this, test); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Iterable skip(int n) { | 360 Iterable skip(int n) { |
| 361 return IterableMixinWorkaround.skipList(this, n); | 361 return IterableMixinWorkaround.skipList(this, n); |
| 362 } | 362 } |
| 363 | 363 |
| 364 Iterable skipWhile(bool test(num element)) { | 364 Iterable skipWhile(bool test(element)) { |
| 365 return IterableMixinWorkaround.skipWhile(this, test); | 365 return IterableMixinWorkaround.skipWhile(this, test); |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool every(bool f(num element)) { | 368 bool every(bool f(element)) { |
| 369 return IterableMixinWorkaround.every(this, f); | 369 return IterableMixinWorkaround.every(this, f); |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool any(bool f(num element)) { | 372 bool any(bool f(element)) { |
| 373 return IterableMixinWorkaround.any(this, f); | 373 return IterableMixinWorkaround.any(this, f); |
| 374 } | 374 } |
| 375 | 375 |
| 376 num firstWhere(bool test(num element), {orElse()}) { | 376 dynamic firstWhere(bool test(element), {orElse()}) { |
| 377 return IterableMixinWorkaround.firstWhere(this, test, orElse); | 377 return IterableMixinWorkaround.firstWhere(this, test, orElse); |
| 378 } | 378 } |
| 379 | 379 |
| 380 num lastWhere(bool test(num element), {orElse()}) { | 380 dynamic lastWhere(bool test(element), {orElse()}) { |
| 381 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | 381 return IterableMixinWorkaround.lastWhereList(this, test, orElse); |
| 382 } | 382 } |
| 383 | 383 |
| 384 num singleWhere(bool test(num element)) { | 384 dynamic singleWhere(bool test(element)) { |
| 385 return IterableMixinWorkaround.singleWhere(this, test); | 385 return IterableMixinWorkaround.singleWhere(this, test); |
| 386 } | 386 } |
| 387 | 387 |
| 388 Iterable<num> get reversed { | 388 Iterable<dynamic> get reversed { |
| 389 return IterableMixinWorkaround.reversedList(this); | 389 return IterableMixinWorkaround.reversedList(this); |
| 390 } | 390 } |
| 391 | 391 |
| 392 num elementAt(int index) { | 392 dynamic elementAt(int index) { |
| 393 return this[index]; | 393 return this[index]; |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool get isEmpty { | 396 bool get isEmpty { |
| 397 return this.length == 0; | 397 return this.length == 0; |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool get isNotEmpty => !isEmpty; | 400 bool get isNotEmpty => !isEmpty; |
| 401 | 401 |
| 402 // Method(s) implementing the List interface. | 402 // Method(s) implementing the List interface. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 419 void insert(int index, value) { | 419 void insert(int index, value) { |
| 420 throw new UnsupportedError( | 420 throw new UnsupportedError( |
| 421 "Cannot insert into a non-extendable array"); | 421 "Cannot insert into a non-extendable array"); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void insertAll(int index, Iterable values) { | 424 void insertAll(int index, Iterable values) { |
| 425 throw new UnsupportedError( | 425 throw new UnsupportedError( |
| 426 "Cannot insert into a non-extendable array"); | 426 "Cannot insert into a non-extendable array"); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void sort([int compare(num a, num b)]) { | 429 void sort([int compare(a, b)]) { |
| 430 IterableMixinWorkaround.sortList(this, compare); | 430 IterableMixinWorkaround.sortList(this, compare); |
| 431 } | 431 } |
| 432 | 432 |
| 433 void shuffle([Random random]) { | 433 void shuffle([Random random]) { |
| 434 IterableMixinWorkaround.shuffleList(this, random); | 434 IterableMixinWorkaround.shuffleList(this, random); |
| 435 } | 435 } |
| 436 | 436 |
| 437 int indexOf(element, [int start = 0]) { | 437 int indexOf(element, [int start = 0]) { |
| 438 return IterableMixinWorkaround.indexOfList(this, element, start); | 438 return IterableMixinWorkaround.indexOfList(this, element, start); |
| 439 } | 439 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 465 void removeWhere(bool test(element)) { | 465 void removeWhere(bool test(element)) { |
| 466 throw new UnsupportedError( | 466 throw new UnsupportedError( |
| 467 "Cannot remove from a non-extendable array"); | 467 "Cannot remove from a non-extendable array"); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void retainWhere(bool test(element)) { | 470 void retainWhere(bool test(element)) { |
| 471 throw new UnsupportedError( | 471 throw new UnsupportedError( |
| 472 "Cannot remove from a non-extendable array"); | 472 "Cannot remove from a non-extendable array"); |
| 473 } | 473 } |
| 474 | 474 |
| 475 num get first { | 475 dynamic get first { |
| 476 if (length > 0) return this[0]; | 476 if (length > 0) return this[0]; |
| 477 throw new StateError("No elements"); | 477 throw new StateError("No elements"); |
| 478 } | 478 } |
| 479 | 479 |
| 480 num get last { | 480 dynamic get last { |
| 481 if (length > 0) return this[length - 1]; | 481 if (length > 0) return this[length - 1]; |
| 482 throw new StateError("No elements"); | 482 throw new StateError("No elements"); |
| 483 } | 483 } |
| 484 | 484 |
| 485 num get single { | 485 dynamic get single { |
| 486 if (length == 1) return this[0]; | 486 if (length == 1) return this[0]; |
| 487 if (length == 0) throw new StateError("No elements"); | 487 if (length == 0) throw new StateError("No elements"); |
| 488 throw new StateError("More than one element"); | 488 throw new StateError("More than one element"); |
| 489 } | 489 } |
| 490 | 490 |
| 491 void removeRange(int start, int end) { | 491 void removeRange(int start, int end) { |
| 492 throw new UnsupportedError( | 492 throw new UnsupportedError( |
| 493 "Cannot remove from a non-extendable array"); | 493 "Cannot remove from a non-extendable array"); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void replaceRange(int start, int end, Iterable iterable) { | 496 void replaceRange(int start, int end, Iterable iterable) { |
| 497 throw new UnsupportedError( | 497 throw new UnsupportedError( |
| 498 "Cannot remove from a non-extendable array"); | 498 "Cannot remove from a non-extendable array"); |
| 499 } | 499 } |
| 500 | 500 |
| 501 List toList({bool growable: true}) { | 501 List toList({bool growable: true}) { |
| 502 return new List.from(this, growable: growable); | 502 return new List.from(this, growable: growable); |
| 503 } | 503 } |
| 504 | 504 |
| 505 Set toSet() { | 505 Set toSet() { |
| 506 return new Set.from(this); | 506 return new Set.from(this); |
| 507 } | 507 } |
| 508 | 508 |
| 509 Map<int, num> asMap() { | 509 Map<int, dynamic> asMap() { |
| 510 return IterableMixinWorkaround.asMapList(this); | 510 return IterableMixinWorkaround.asMapList(this); |
| 511 } | 511 } |
| 512 | 512 |
| 513 List sublist(int start, [int end]) { | 513 List sublist(int start, [int end]) { |
| 514 if (end == null) end = this.length; | 514 if (end == null) end = this.length; |
| 515 int length = end - start; | 515 int length = end - start; |
| 516 _rangeCheck(this.length, start, length); | 516 _rangeCheck(this.length, start, length); |
| 517 List result = _createList(length); | 517 List result = _createList(length); |
| 518 result.setRange(0, length, this, start); | 518 result.setRange(0, length, this, start); |
| 519 return result; | 519 return result; |
| 520 } | 520 } |
| 521 | 521 |
| 522 Iterable getRange(int start, [int end]) { | 522 Iterable getRange(int start, [int end]) { |
| 523 return IterableMixinWorkaround.getRangeList(this, start, end); | 523 return IterableMixinWorkaround.getRangeList(this, start, end); |
| 524 } | 524 } |
| 525 | 525 |
| 526 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { | 526 void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| 527 if (!_setRange(start, end - start, iterable, skipCount)) { | 527 if (!_setRange(start, end - start, iterable, skipCount)) { |
| 528 IterableMixinWorkaround.setRangeList(this, start, | 528 IterableMixinWorkaround.setRangeList(this, start, |
| 529 end, iterable, skipCount); | 529 end, iterable, skipCount); |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 | 532 |
| 533 void setAll(int index, Iterable iterable) { | 533 void setAll(int index, Iterable iterable) { |
| 534 IterableMixinWorkaround.setAllList(this, index, iterable); | 534 IterableMixinWorkaround.setAllList(this, index, iterable); |
| 535 } | 535 } |
| 536 | 536 |
| 537 void fillRange(int start, int end, [num fillValue]) { | 537 void fillRange(int start, int end, [fillValue]) { |
| 538 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); | 538 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); |
| 539 } | 539 } |
| 540 | 540 |
| 541 | 541 |
| 542 // Method(s) implementing Object interface. | 542 // Method(s) implementing Object interface. |
| 543 | 543 |
| 544 String toString() { | 544 String toString() { |
| 545 return IterableMixinWorkaround.toStringIterable(this, '[', ']'); | 545 return IterableMixinWorkaround.toStringIterable(this, '[', ']'); |
| 546 } | 546 } |
| 547 | 547 |
| (...skipping 2797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3345 return value; | 3345 return value; |
| 3346 } | 3346 } |
| 3347 return object; | 3347 return object; |
| 3348 } | 3348 } |
| 3349 | 3349 |
| 3350 | 3350 |
| 3351 void _throwRangeError(int index, int length) { | 3351 void _throwRangeError(int index, int length) { |
| 3352 String message = "$index must be in the range [0..$length)"; | 3352 String message = "$index must be in the range [0..$length)"; |
| 3353 throw new RangeError(message); | 3353 throw new RangeError(message); |
| 3354 } | 3354 } |
| OLD | NEW |