| 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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 275 } |
| 276 | 276 |
| 277 | 277 |
| 278 // Based class for _TypedList that provides common methods for implementing | 278 // Based class for _TypedList that provides common methods for implementing |
| 279 // the collection and list interfaces. | 279 // the collection and list interfaces. |
| 280 | 280 |
| 281 abstract class _TypedListBase { | 281 abstract class _TypedListBase { |
| 282 // Method(s) implementing the Collection interface. | 282 // Method(s) implementing the Collection interface. |
| 283 bool contains(element) => IterableMixinWorkaround.contains(this, element); | 283 bool contains(element) => IterableMixinWorkaround.contains(this, element); |
| 284 | 284 |
| 285 void forEach(void f(element)) { | 285 void forEach(void f(num element)) { |
| 286 var len = this.length; | 286 var len = this.length; |
| 287 for (var i = 0; i < len; i++) { | 287 for (var i = 0; i < len; i++) { |
| 288 f(this[i]); | 288 f(this[i]); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 Iterable map(f(int element)) { | 292 Iterable map(f(num element)) { |
| 293 return IterableMixinWorkaround.mapList(this, f); | 293 return IterableMixinWorkaround.mapList(this, f); |
| 294 } | 294 } |
| 295 | 295 |
| 296 String join([String separator = ""]) { | 296 String join([String separator = ""]) { |
| 297 return IterableMixinWorkaround.join(this, separator); | 297 return IterableMixinWorkaround.join(this, separator); |
| 298 } | 298 } |
| 299 | 299 |
| 300 dynamic reduce(dynamic combine(value, element)) { | 300 num reduce(dynamic combine(num value, num element)) { |
| 301 return IterableMixinWorkaround.reduce(this, combine); | 301 return IterableMixinWorkaround.reduce(this, combine); |
| 302 } | 302 } |
| 303 | 303 |
| 304 dynamic fold(dynamic initialValue, | 304 dynamic fold(dynamic initialValue, |
| 305 dynamic combine(dynamic initialValue, element)) { | 305 dynamic combine(dynamic initialValue, num element)) { |
| 306 return IterableMixinWorkaround.fold(this, initialValue, combine); | 306 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 307 } | 307 } |
| 308 | 308 |
| 309 Iterable where(bool f(int element)) { | 309 Iterable where(bool f(num element)) { |
| 310 return IterableMixinWorkaround.where(this, f); | 310 return IterableMixinWorkaround.where(this, f); |
| 311 } | 311 } |
| 312 | 312 |
| 313 Iterable expand(Iterable f(int element)) { | 313 Iterable expand(Iterable f(num element)) { |
| 314 return IterableMixinWorkaround.expand(this, f); | 314 return IterableMixinWorkaround.expand(this, f); |
| 315 } | 315 } |
| 316 | 316 |
| 317 Iterable take(int n) { | 317 Iterable take(int n) { |
| 318 return IterableMixinWorkaround.takeList(this, n); | 318 return IterableMixinWorkaround.takeList(this, n); |
| 319 } | 319 } |
| 320 | 320 |
| 321 Iterable takeWhile(bool test(int value)) { | 321 Iterable takeWhile(bool test(num element)) { |
| 322 return IterableMixinWorkaround.takeWhile(this, test); | 322 return IterableMixinWorkaround.takeWhile(this, test); |
| 323 } | 323 } |
| 324 | 324 |
| 325 Iterable skip(int n) { | 325 Iterable skip(int n) { |
| 326 return IterableMixinWorkaround.skipList(this, n); | 326 return IterableMixinWorkaround.skipList(this, n); |
| 327 } | 327 } |
| 328 | 328 |
| 329 Iterable skipWhile(bool test(int value)) { | 329 Iterable skipWhile(bool test(num element)) { |
| 330 return IterableMixinWorkaround.skipWhile(this, test); | 330 return IterableMixinWorkaround.skipWhile(this, test); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool every(bool f(element)) { | 333 bool every(bool f(num element)) { |
| 334 return IterableMixinWorkaround.every(this, f); | 334 return IterableMixinWorkaround.every(this, f); |
| 335 } | 335 } |
| 336 | 336 |
| 337 bool any(bool f(element)) { | 337 bool any(bool f(num element)) { |
| 338 return IterableMixinWorkaround.any(this, f); | 338 return IterableMixinWorkaround.any(this, f); |
| 339 } | 339 } |
| 340 | 340 |
| 341 int firstWhere(bool test(int value), {int orElse()}) { | 341 num firstWhere(bool test(num element), {orElse()}) { |
| 342 return IterableMixinWorkaround.firstWhere(this, test, orElse); | 342 return IterableMixinWorkaround.firstWhere(this, test, orElse); |
| 343 } | 343 } |
| 344 | 344 |
| 345 int lastWhere(bool test(int value), {int orElse()}) { | 345 num lastWhere(bool test(num element), {orElse()}) { |
| 346 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | 346 return IterableMixinWorkaround.lastWhereList(this, test, orElse); |
| 347 } | 347 } |
| 348 | 348 |
| 349 int singleWhere(bool test(int value)) { | 349 num singleWhere(bool test(num element)) { |
| 350 return IterableMixinWorkaround.singleWhere(this, test); | 350 return IterableMixinWorkaround.singleWhere(this, test); |
| 351 } | 351 } |
| 352 | 352 |
| 353 int elementAt(int index) { | 353 num elementAt(int index) { |
| 354 return this[index]; | 354 return this[index]; |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool get isEmpty { | 357 bool get isEmpty { |
| 358 return this.length == 0; | 358 return this.length == 0; |
| 359 } | 359 } |
| 360 | 360 |
| 361 bool get isNotEmpty => !isEmpty; | 361 bool get isNotEmpty => !isEmpty; |
| 362 | 362 |
| 363 // Method(s) implementing the List interface. | 363 // Method(s) implementing the List interface. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 380 void insert(int index, value) { | 380 void insert(int index, value) { |
| 381 throw new UnsupportedError( | 381 throw new UnsupportedError( |
| 382 "Cannot insert into a non-extendable array"); | 382 "Cannot insert into a non-extendable array"); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void insertAll(int index, Iterable values) { | 385 void insertAll(int index, Iterable values) { |
| 386 throw new UnsupportedError( | 386 throw new UnsupportedError( |
| 387 "Cannot insert into a non-extendable array"); | 387 "Cannot insert into a non-extendable array"); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void sort([int compare(var a, var b)]) { | 390 void sort([int compare(num a, num b)]) { |
| 391 return IterableMixinWorkaround.sortList(this, compare); | 391 return IterableMixinWorkaround.sortList(this, compare); |
| 392 } | 392 } |
| 393 | 393 |
| 394 int indexOf(element, [int start = 0]) { | 394 int indexOf(element, [int start = 0]) { |
| 395 return IterableMixinWorkaround.indexOfList(this, element, start); | 395 return IterableMixinWorkaround.indexOfList(this, element, start); |
| 396 } | 396 } |
| 397 | 397 |
| 398 int lastIndexOf(element, [int start = null]) { | 398 int lastIndexOf(element, [int start = null]) { |
| 399 return IterableMixinWorkaround.lastIndexOfList(this, element, start); | 399 return IterableMixinWorkaround.lastIndexOfList(this, element, start); |
| 400 } | 400 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 422 void removeAll(Iterable elements) { | 422 void removeAll(Iterable elements) { |
| 423 throw new UnsupportedError( | 423 throw new UnsupportedError( |
| 424 "Cannot remove from a non-extendable array"); | 424 "Cannot remove from a non-extendable array"); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void retainAll(Iterable elements) { | 427 void retainAll(Iterable elements) { |
| 428 throw new UnsupportedError( | 428 throw new UnsupportedError( |
| 429 "Cannot remove from a non-extendable array"); | 429 "Cannot remove from a non-extendable array"); |
| 430 } | 430 } |
| 431 | 431 |
| 432 void removeWhere(bool test(int element)) { | 432 void removeWhere(bool test(element)) { |
| 433 throw new UnsupportedError( | 433 throw new UnsupportedError( |
| 434 "Cannot remove from a non-extendable array"); | 434 "Cannot remove from a non-extendable array"); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void retainWhere(bool test(int element)) { | 437 void retainWhere(bool test(element)) { |
| 438 throw new UnsupportedError( | 438 throw new UnsupportedError( |
| 439 "Cannot remove from a non-extendable array"); | 439 "Cannot remove from a non-extendable array"); |
| 440 } | 440 } |
| 441 | 441 |
| 442 int get first { | 442 num get first { |
| 443 if (length > 0) return this[0]; | 443 if (length > 0) return this[0]; |
| 444 throw new StateError("No elements"); | 444 throw new StateError("No elements"); |
| 445 } | 445 } |
| 446 | 446 |
| 447 int get last { | 447 num get last { |
| 448 if (length > 0) return this[length - 1]; | 448 if (length > 0) return this[length - 1]; |
| 449 throw new StateError("No elements"); | 449 throw new StateError("No elements"); |
| 450 } | 450 } |
| 451 | 451 |
| 452 int get single { | 452 num get single { |
| 453 if (length == 1) return this[0]; | 453 if (length == 1) return this[0]; |
| 454 if (length == 0) throw new StateError("No elements"); | 454 if (length == 0) throw new StateError("No elements"); |
| 455 throw new StateError("More than one element"); | 455 throw new StateError("More than one element"); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void removeRange(int start, int end) { | 458 void removeRange(int start, int end) { |
| 459 throw new UnsupportedError( | 459 throw new UnsupportedError( |
| 460 "Cannot remove from a non-extendable array"); | 460 "Cannot remove from a non-extendable array"); |
| 461 } | 461 } |
| 462 | 462 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 490 if (!_setRange(start, end - start, iterable, skipCount)) { | 490 if (!_setRange(start, end - start, iterable, skipCount)) { |
| 491 IterableMixinWorkaround.setRangeList(this, start, | 491 IterableMixinWorkaround.setRangeList(this, start, |
| 492 end, iterable, skipCount); | 492 end, iterable, skipCount); |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 void setAll(int index, Iterable iterable) { | 496 void setAll(int index, Iterable iterable) { |
| 497 IterableMixinWorkaround.setAllList(this, index, iterable); | 497 IterableMixinWorkaround.setAllList(this, index, iterable); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void fillRange(int start, int end, [fillValue]) { | 500 void fillRange(int start, int end, [num fillValue]) { |
| 501 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); | 501 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); |
| 502 } | 502 } |
| 503 | 503 |
| 504 | 504 |
| 505 // Method(s) implementing Object interface. | 505 // Method(s) implementing Object interface. |
| 506 | 506 |
| 507 String toString() { | 507 String toString() { |
| 508 return ToString.iterableToString(this); | 508 return ToString.iterableToString(this); |
| 509 } | 509 } |
| 510 | 510 |
| (...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3106 return value; | 3106 return value; |
| 3107 } | 3107 } |
| 3108 return object; | 3108 return object; |
| 3109 } | 3109 } |
| 3110 | 3110 |
| 3111 | 3111 |
| 3112 void _throwRangeError(int index, int length) { | 3112 void _throwRangeError(int index, int length) { |
| 3113 String message = "$index must be in the range [0..$length)"; | 3113 String message = "$index must be in the range [0..$length)"; |
| 3114 throw new RangeError(message); | 3114 throw new RangeError(message); |
| 3115 } | 3115 } |
| OLD | NEW |