| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of dart._collection.dev; | 5 part of dart._collection.dev; |
| 6 | 6 |
| 7 | 7 |
| 8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, | 8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, |
| 9 // unless coordinated with either me or the core library team. Thanks! | 9 // unless coordinated with either me or the core library team. Thanks! |
| 10 // TODO(ajohnsen): Remove at the 11th of Auguest 2013. | 10 // TODO(ajohnsen): Remove at the 11th of Auguest 2013. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 _current = _iterable.elementAt(_index); | 316 _current = _iterable.elementAt(_index); |
| 317 _index++; | 317 _index++; |
| 318 return true; | 318 return true; |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 typedef T _Transformation<S, T>(S value); | 322 typedef T _Transformation<S, T>(S value); |
| 323 | 323 |
| 324 class MappedIterable<S, T> extends IterableBase<T> { | 324 class MappedIterable<S, T> extends IterableBase<T> { |
| 325 final Iterable<S> _iterable; | 325 final Iterable<S> _iterable; |
| 326 // TODO(ahe): Restore type when feature is implemented in dart2js | 326 final _Transformation<S, T> _f; |
| 327 // checked mode. http://dartbug.com/7733 | |
| 328 final /* _Transformation<S, T> */ _f; | |
| 329 | 327 |
| 330 MappedIterable(this._iterable, T this._f(S element)); | 328 MappedIterable(this._iterable, T this._f(S element)); |
| 331 | 329 |
| 332 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); | 330 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); |
| 333 | 331 |
| 334 // Length related functions are independent of the mapping. | 332 // Length related functions are independent of the mapping. |
| 335 int get length => _iterable.length; | 333 int get length => _iterable.length; |
| 336 bool get isEmpty => _iterable.isEmpty; | 334 bool get isEmpty => _iterable.isEmpty; |
| 337 | 335 |
| 338 // Index based lookup can be done before transforming. | 336 // Index based lookup can be done before transforming. |
| 339 T get first => _f(_iterable.first); | 337 T get first => _f(_iterable.first); |
| 340 T get last => _f(_iterable.last); | 338 T get last => _f(_iterable.last); |
| 341 T get single => _f(_iterable.single); | 339 T get single => _f(_iterable.single); |
| 342 T elementAt(int index) => _f(_iterable.elementAt(index)); | 340 T elementAt(int index) => _f(_iterable.elementAt(index)); |
| 343 } | 341 } |
| 344 | 342 |
| 345 class MappedIterator<S, T> extends Iterator<T> { | 343 class MappedIterator<S, T> extends Iterator<T> { |
| 346 T _current; | 344 T _current; |
| 347 final Iterator<S> _iterator; | 345 final Iterator<S> _iterator; |
| 348 // TODO(ahe): Restore type when feature is implemented in dart2js | 346 final _Transformation<S, T> _f; |
| 349 // checked mode. http://dartbug.com/7733 | |
| 350 final /* _Transformation<S, T> */ _f; | |
| 351 | 347 |
| 352 MappedIterator(this._iterator, T this._f(S element)); | 348 MappedIterator(this._iterator, T this._f(S element)); |
| 353 | 349 |
| 354 bool moveNext() { | 350 bool moveNext() { |
| 355 if (_iterator.moveNext()) { | 351 if (_iterator.moveNext()) { |
| 356 _current = _f(_iterator.current); | 352 _current = _f(_iterator.current); |
| 357 return true; | 353 return true; |
| 358 } | 354 } |
| 359 _current = null; | 355 _current = null; |
| 360 return false; | 356 return false; |
| 361 } | 357 } |
| 362 | 358 |
| 363 T get current => _current; | 359 T get current => _current; |
| 364 } | 360 } |
| 365 | 361 |
| 366 /** Specialized alternative to [MappedIterable] for mapped [List]s. */ | 362 /** Specialized alternative to [MappedIterable] for mapped [List]s. */ |
| 367 class MappedListIterable<S, T> extends ListIterable<T> { | 363 class MappedListIterable<S, T> extends ListIterable<T> { |
| 368 final Iterable<S> _source; | 364 final Iterable<S> _source; |
| 369 // TODO(ahe): Restore type when feature is implemented in dart2js | 365 final _Transformation<S, T> _f; |
| 370 // checked mode. http://dartbug.com/7733 | |
| 371 final /* _Transformation<S, T> */ _f; | |
| 372 | 366 |
| 373 MappedListIterable(this._source, T this._f(S value)); | 367 MappedListIterable(this._source, T this._f(S value)); |
| 374 | 368 |
| 375 int get length => _source.length; | 369 int get length => _source.length; |
| 376 T elementAt(int index) => _f(_source.elementAt(index)); | 370 T elementAt(int index) => _f(_source.elementAt(index)); |
| 377 } | 371 } |
| 378 | 372 |
| 379 | 373 |
| 380 typedef bool _ElementPredicate<E>(E element); | 374 typedef bool _ElementPredicate<E>(E element); |
| 381 | 375 |
| 382 class WhereIterable<E> extends IterableBase<E> { | 376 class WhereIterable<E> extends IterableBase<E> { |
| 383 final Iterable<E> _iterable; | 377 final Iterable<E> _iterable; |
| 384 // TODO(ahe): Restore type when feature is implemented in dart2js | 378 final _ElementPredicate _f; |
| 385 // checked mode. http://dartbug.com/7733 | |
| 386 final /* _ElementPredicate */ _f; | |
| 387 | 379 |
| 388 WhereIterable(this._iterable, bool this._f(E element)); | 380 WhereIterable(this._iterable, bool this._f(E element)); |
| 389 | 381 |
| 390 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); | 382 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); |
| 391 } | 383 } |
| 392 | 384 |
| 393 class WhereIterator<E> extends Iterator<E> { | 385 class WhereIterator<E> extends Iterator<E> { |
| 394 final Iterator<E> _iterator; | 386 final Iterator<E> _iterator; |
| 395 // TODO(ahe): Restore type when feature is implemented in dart2js | 387 final _ElementPredicate _f; |
| 396 // checked mode. http://dartbug.com/7733 | |
| 397 final /* _ElementPredicate */ _f; | |
| 398 | 388 |
| 399 WhereIterator(this._iterator, bool this._f(E element)); | 389 WhereIterator(this._iterator, bool this._f(E element)); |
| 400 | 390 |
| 401 bool moveNext() { | 391 bool moveNext() { |
| 402 while (_iterator.moveNext()) { | 392 while (_iterator.moveNext()) { |
| 403 if (_f(_iterator.current)) { | 393 if (_f(_iterator.current)) { |
| 404 return true; | 394 return true; |
| 405 } | 395 } |
| 406 } | 396 } |
| 407 return false; | 397 return false; |
| 408 } | 398 } |
| 409 | 399 |
| 410 E get current => _iterator.current; | 400 E get current => _iterator.current; |
| 411 } | 401 } |
| 412 | 402 |
| 413 typedef Iterable<T> _ExpandFunction<S, T>(S sourceElement); | 403 typedef Iterable<T> _ExpandFunction<S, T>(S sourceElement); |
| 414 | 404 |
| 415 class ExpandIterable<S, T> extends IterableBase<T> { | 405 class ExpandIterable<S, T> extends IterableBase<T> { |
| 416 final Iterable<S> _iterable; | 406 final Iterable<S> _iterable; |
| 417 // TODO(ahe): Restore type when feature is implemented in dart2js | 407 final _ExpandFunction _f; |
| 418 // checked mode. http://dartbug.com/7733 | |
| 419 final /* _ExpandFunction */ _f; | |
| 420 | 408 |
| 421 ExpandIterable(this._iterable, Iterable<T> this._f(S element)); | 409 ExpandIterable(this._iterable, Iterable<T> this._f(S element)); |
| 422 | 410 |
| 423 Iterator<T> get iterator => new ExpandIterator<S, T>(_iterable.iterator, _f); | 411 Iterator<T> get iterator => new ExpandIterator<S, T>(_iterable.iterator, _f); |
| 424 } | 412 } |
| 425 | 413 |
| 426 class ExpandIterator<S, T> implements Iterator<T> { | 414 class ExpandIterator<S, T> implements Iterator<T> { |
| 427 final Iterator<S> _iterator; | 415 final Iterator<S> _iterator; |
| 428 // TODO(ahe): Restore type when feature is implemented in dart2js | 416 final _ExpandFunction _f; |
| 429 // checked mode. http://dartbug.com/7733 | |
| 430 final /* _ExpandFunction */ _f; | |
| 431 // Initialize _currentExpansion to an empty iterable. A null value | 417 // Initialize _currentExpansion to an empty iterable. A null value |
| 432 // marks the end of iteration, and we don't want to call _f before | 418 // marks the end of iteration, and we don't want to call _f before |
| 433 // the first moveNext call. | 419 // the first moveNext call. |
| 434 Iterator<T> _currentExpansion = const EmptyIterator(); | 420 Iterator<T> _currentExpansion = const EmptyIterator(); |
| 435 T _current; | 421 T _current; |
| 436 | 422 |
| 437 ExpandIterator(this._iterator, Iterable<T> this._f(S element)); | 423 ExpandIterator(this._iterator, Iterable<T> this._f(S element)); |
| 438 | 424 |
| 439 void _nextExpansion() { | 425 void _nextExpansion() { |
| 440 } | 426 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 478 } |
| 493 | 479 |
| 494 E get current { | 480 E get current { |
| 495 if (_remaining < 0) return null; | 481 if (_remaining < 0) return null; |
| 496 return _iterator.current; | 482 return _iterator.current; |
| 497 } | 483 } |
| 498 } | 484 } |
| 499 | 485 |
| 500 class TakeWhileIterable<E> extends IterableBase<E> { | 486 class TakeWhileIterable<E> extends IterableBase<E> { |
| 501 final Iterable<E> _iterable; | 487 final Iterable<E> _iterable; |
| 502 // TODO(ahe): Restore type when feature is implemented in dart2js | 488 final _ElementPredicate _f; |
| 503 // checked mode. http://dartbug.com/7733 | |
| 504 final /* _ElementPredicate */ _f; | |
| 505 | 489 |
| 506 TakeWhileIterable(this._iterable, bool this._f(E element)); | 490 TakeWhileIterable(this._iterable, bool this._f(E element)); |
| 507 | 491 |
| 508 Iterator<E> get iterator { | 492 Iterator<E> get iterator { |
| 509 return new TakeWhileIterator<E>(_iterable.iterator, _f); | 493 return new TakeWhileIterator<E>(_iterable.iterator, _f); |
| 510 } | 494 } |
| 511 } | 495 } |
| 512 | 496 |
| 513 class TakeWhileIterator<E> extends Iterator<E> { | 497 class TakeWhileIterator<E> extends Iterator<E> { |
| 514 final Iterator<E> _iterator; | 498 final Iterator<E> _iterator; |
| 515 // TODO(ahe): Restore type when feature is implemented in dart2js | 499 final _ElementPredicate _f; |
| 516 // checked mode. http://dartbug.com/7733 | |
| 517 final /* _ElementPredicate */ _f; | |
| 518 bool _isFinished = false; | 500 bool _isFinished = false; |
| 519 | 501 |
| 520 TakeWhileIterator(this._iterator, bool this._f(E element)); | 502 TakeWhileIterator(this._iterator, bool this._f(E element)); |
| 521 | 503 |
| 522 bool moveNext() { | 504 bool moveNext() { |
| 523 if (_isFinished) return false; | 505 if (_isFinished) return false; |
| 524 if (!_iterator.moveNext() || !_f(_iterator.current)) { | 506 if (!_iterator.moveNext() || !_f(_iterator.current)) { |
| 525 _isFinished = true; | 507 _isFinished = true; |
| 526 return false; | 508 return false; |
| 527 } | 509 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 for (int i = 0; i < _skipCount; i++) _iterator.moveNext(); | 550 for (int i = 0; i < _skipCount; i++) _iterator.moveNext(); |
| 569 _skipCount = 0; | 551 _skipCount = 0; |
| 570 return _iterator.moveNext(); | 552 return _iterator.moveNext(); |
| 571 } | 553 } |
| 572 | 554 |
| 573 E get current => _iterator.current; | 555 E get current => _iterator.current; |
| 574 } | 556 } |
| 575 | 557 |
| 576 class SkipWhileIterable<E> extends IterableBase<E> { | 558 class SkipWhileIterable<E> extends IterableBase<E> { |
| 577 final Iterable<E> _iterable; | 559 final Iterable<E> _iterable; |
| 578 // TODO(ahe): Restore type when feature is implemented in dart2js | 560 final _ElementPredicate _f; |
| 579 // checked mode. http://dartbug.com/7733 | |
| 580 final /* _ElementPredicate */ _f; | |
| 581 | 561 |
| 582 SkipWhileIterable(this._iterable, bool this._f(E element)); | 562 SkipWhileIterable(this._iterable, bool this._f(E element)); |
| 583 | 563 |
| 584 Iterator<E> get iterator { | 564 Iterator<E> get iterator { |
| 585 return new SkipWhileIterator<E>(_iterable.iterator, _f); | 565 return new SkipWhileIterator<E>(_iterable.iterator, _f); |
| 586 } | 566 } |
| 587 } | 567 } |
| 588 | 568 |
| 589 class SkipWhileIterator<E> extends Iterator<E> { | 569 class SkipWhileIterator<E> extends Iterator<E> { |
| 590 final Iterator<E> _iterator; | 570 final Iterator<E> _iterator; |
| 591 // TODO(ahe): Restore type when feature is implemented in dart2js | 571 final _ElementPredicate _f; |
| 592 // checked mode. http://dartbug.com/7733 | |
| 593 final /* _ElementPredicate */ _f; | |
| 594 bool _hasSkipped = false; | 572 bool _hasSkipped = false; |
| 595 | 573 |
| 596 SkipWhileIterator(this._iterator, bool this._f(E element)); | 574 SkipWhileIterator(this._iterator, bool this._f(E element)); |
| 597 | 575 |
| 598 bool moveNext() { | 576 bool moveNext() { |
| 599 if (!_hasSkipped) { | 577 if (!_hasSkipped) { |
| 600 _hasSkipped = true; | 578 _hasSkipped = true; |
| 601 while (_iterator.moveNext()) { | 579 while (_iterator.moveNext()) { |
| 602 if (!_f(_iterator.current)) return true; | 580 if (!_f(_iterator.current)) return true; |
| 603 } | 581 } |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 | 1042 |
| 1065 static Set setDifference(Set set, Set other, Set result) { | 1043 static Set setDifference(Set set, Set other, Set result) { |
| 1066 for (var element in set) { | 1044 for (var element in set) { |
| 1067 if (!other.contains(element)) { | 1045 if (!other.contains(element)) { |
| 1068 result.add(element); | 1046 result.add(element); |
| 1069 } | 1047 } |
| 1070 } | 1048 } |
| 1071 return result; | 1049 return result; |
| 1072 } | 1050 } |
| 1073 } | 1051 } |
| OLD | NEW |