| 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 import "dart:_internal"; | 7 import "dart:_internal"; |
| 8 import 'dart:math' show Random; | 8 import 'dart:math' show Random; |
| 9 | 9 |
| 10 patch class Int8List { | 10 patch class Int8List { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 bool get isEmpty { | 401 bool get isEmpty { |
| 402 return this.length == 0; | 402 return this.length == 0; |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool get isNotEmpty => !isEmpty; | 405 bool get isNotEmpty => !isEmpty; |
| 406 | 406 |
| 407 // Method(s) implementing the List interface. | 407 // Method(s) implementing the List interface. |
| 408 | 408 |
| 409 set length(newLength) { | 409 set length(newLength) { |
| 410 throw new UnsupportedError( | 410 throw new UnsupportedError( |
| 411 "Cannot resize a non-extendable array"); | 411 "Cannot resize a fixed-length list"); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void add(value) { | 414 void add(value) { |
| 415 throw new UnsupportedError( | 415 throw new UnsupportedError( |
| 416 "Cannot add to a non-extendable array"); | 416 "Cannot add to a fixed-length list"); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void addAll(Iterable value) { | 419 void addAll(Iterable value) { |
| 420 throw new UnsupportedError( | 420 throw new UnsupportedError( |
| 421 "Cannot add to a non-extendable array"); | 421 "Cannot add to a fixed-length list"); |
| 422 } | 422 } |
| 423 | 423 |
| 424 void insert(int index, value) { | 424 void insert(int index, value) { |
| 425 throw new UnsupportedError( | 425 throw new UnsupportedError( |
| 426 "Cannot insert into a non-extendable array"); | 426 "Cannot insert into a fixed-length list"); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void insertAll(int index, Iterable values) { | 429 void insertAll(int index, Iterable values) { |
| 430 throw new UnsupportedError( | 430 throw new UnsupportedError( |
| 431 "Cannot insert into a non-extendable array"); | 431 "Cannot insert into a fixed-length list"); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void sort([int compare(a, b)]) { | 434 void sort([int compare(a, b)]) { |
| 435 IterableMixinWorkaround.sortList(this, compare); | 435 IterableMixinWorkaround.sortList(this, compare); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void shuffle([Random random]) { | 438 void shuffle([Random random]) { |
| 439 IterableMixinWorkaround.shuffleList(this, random); | 439 IterableMixinWorkaround.shuffleList(this, random); |
| 440 } | 440 } |
| 441 | 441 |
| 442 int indexOf(element, [int start = 0]) { | 442 int indexOf(element, [int start = 0]) { |
| 443 return IterableMixinWorkaround.indexOfList(this, element, start); | 443 return IterableMixinWorkaround.indexOfList(this, element, start); |
| 444 } | 444 } |
| 445 | 445 |
| 446 int lastIndexOf(element, [int start = null]) { | 446 int lastIndexOf(element, [int start = null]) { |
| 447 return IterableMixinWorkaround.lastIndexOfList(this, element, start); | 447 return IterableMixinWorkaround.lastIndexOfList(this, element, start); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void clear() { | 450 void clear() { |
| 451 throw new UnsupportedError( | 451 throw new UnsupportedError( |
| 452 "Cannot remove from a non-extendable array"); | 452 "Cannot remove from a fixed-length list"); |
| 453 } | 453 } |
| 454 | 454 |
| 455 int removeLast() { | 455 int removeLast() { |
| 456 throw new UnsupportedError( | 456 throw new UnsupportedError( |
| 457 "Cannot remove from a non-extendable array"); | 457 "Cannot remove from a fixed-length list"); |
| 458 } | 458 } |
| 459 | 459 |
| 460 bool remove(Object element) { | 460 bool remove(Object element) { |
| 461 throw new UnsupportedError( | 461 throw new UnsupportedError( |
| 462 "Cannot remove from a non-extendable array"); | 462 "Cannot remove from a fixed-length list"); |
| 463 } | 463 } |
| 464 | 464 |
| 465 bool removeAt(int index) { | 465 bool removeAt(int index) { |
| 466 throw new UnsupportedError( | 466 throw new UnsupportedError( |
| 467 "Cannot remove from a non-extendable array"); | 467 "Cannot remove from a fixed-length list"); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void removeWhere(bool test(element)) { | 470 void removeWhere(bool test(element)) { |
| 471 throw new UnsupportedError( | 471 throw new UnsupportedError( |
| 472 "Cannot remove from a non-extendable array"); | 472 "Cannot remove from a fixed-length list"); |
| 473 } | 473 } |
| 474 | 474 |
| 475 void retainWhere(bool test(element)) { | 475 void retainWhere(bool test(element)) { |
| 476 throw new UnsupportedError( | 476 throw new UnsupportedError( |
| 477 "Cannot remove from a non-extendable array"); | 477 "Cannot remove from a fixed-length list"); |
| 478 } | 478 } |
| 479 | 479 |
| 480 dynamic get first { | 480 dynamic get first { |
| 481 if (length > 0) return this[0]; | 481 if (length > 0) return this[0]; |
| 482 throw new StateError("No elements"); | 482 throw new StateError("No elements"); |
| 483 } | 483 } |
| 484 | 484 |
| 485 dynamic get last { | 485 dynamic get last { |
| 486 if (length > 0) return this[length - 1]; | 486 if (length > 0) return this[length - 1]; |
| 487 throw new StateError("No elements"); | 487 throw new StateError("No elements"); |
| 488 } | 488 } |
| 489 | 489 |
| 490 dynamic get single { | 490 dynamic get single { |
| 491 if (length == 1) return this[0]; | 491 if (length == 1) return this[0]; |
| 492 if (length == 0) throw new StateError("No elements"); | 492 if (length == 0) throw new StateError("No elements"); |
| 493 throw new StateError("More than one element"); | 493 throw new StateError("More than one element"); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void removeRange(int start, int end) { | 496 void removeRange(int start, int end) { |
| 497 throw new UnsupportedError( | 497 throw new UnsupportedError( |
| 498 "Cannot remove from a non-extendable array"); | 498 "Cannot remove from a fixed-length list"); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void replaceRange(int start, int end, Iterable iterable) { | 501 void replaceRange(int start, int end, Iterable iterable) { |
| 502 throw new UnsupportedError( | 502 throw new UnsupportedError( |
| 503 "Cannot remove from a non-extendable array"); | 503 "Cannot remove from a fixed-length list"); |
| 504 } | 504 } |
| 505 | 505 |
| 506 List toList({bool growable: true}) { | 506 List toList({bool growable: true}) { |
| 507 return new List.from(this, growable: growable); | 507 return new List.from(this, growable: growable); |
| 508 } | 508 } |
| 509 | 509 |
| 510 Set toSet() { | 510 Set toSet() { |
| 511 return new Set.from(this); | 511 return new Set.from(this); |
| 512 } | 512 } |
| 513 | 513 |
| (...skipping 3126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3640 return value; | 3640 return value; |
| 3641 } | 3641 } |
| 3642 return object; | 3642 return object; |
| 3643 } | 3643 } |
| 3644 | 3644 |
| 3645 | 3645 |
| 3646 void _throwRangeError(int index, int length) { | 3646 void _throwRangeError(int index, int length) { |
| 3647 String message = "$index must be in the range [0..$length)"; | 3647 String message = "$index must be in the range [0..$length)"; |
| 3648 throw new RangeError(message); | 3648 throw new RangeError(message); |
| 3649 } | 3649 } |
| OLD | NEW |