| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.utilities.collection; | 8 library engine.utilities.collection; |
| 9 | 9 |
| 10 import 'java_core.dart'; | 10 import 'java_core.dart'; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 w = _pop(); | 430 w = _pop(); |
| 431 component.add(w); | 431 component.add(w); |
| 432 _nodeMap[w].component = component; | 432 _nodeMap[w].component = component; |
| 433 } while (!identical(w, v)); | 433 } while (!identical(w, v)); |
| 434 } | 434 } |
| 435 return vInfo; | 435 return vInfo; |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 | 438 |
| 439 /** | 439 /** |
| 440 * The interface `MapIterator` defines the behavior of objects that iterate over
the entries |
| 441 * in a map. |
| 442 * |
| 443 * This interface defines the concept of a current entry and provides methods to
access the key and |
| 444 * value in the current entry. When an iterator is first created it will be posi
tioned before the |
| 445 * first entry and there is no current entry until [moveNext] is invoked. When a
ll of the |
| 446 * entries have been accessed there will also be no current entry. |
| 447 * |
| 448 * There is no guarantee made about the order in which the entries are accessibl
e. |
| 449 */ |
| 450 abstract class MapIterator<K, V> { |
| 451 /** |
| 452 * Return the key associated with the current element. |
| 453 * |
| 454 * @return the key associated with the current element |
| 455 * @throws NoSuchElementException if there is no current element |
| 456 */ |
| 457 K get key; |
| 458 |
| 459 /** |
| 460 * Return the value associated with the current element. |
| 461 * |
| 462 * @return the value associated with the current element |
| 463 * @throws NoSuchElementException if there is no current element |
| 464 */ |
| 465 V get value; |
| 466 |
| 467 /** |
| 468 * Advance to the next entry in the map. Return `true` if there is a current e
lement that |
| 469 * can be accessed after this method returns. It is safe to invoke this method
even if the |
| 470 * previous invocation returned `false`. |
| 471 * |
| 472 * @return `true` if there is a current element that can be accessed |
| 473 */ |
| 474 bool moveNext(); |
| 475 |
| 476 /** |
| 477 * Set the value associated with the current element to the given value. |
| 478 * |
| 479 * @param newValue the new value to be associated with the current element |
| 480 * @throws NoSuchElementException if there is no current element |
| 481 */ |
| 482 void set value(V newValue); |
| 483 } |
| 484 |
| 485 /** |
| 440 * The class `ListUtilities` defines utility methods useful for working with [Li
st | 486 * The class `ListUtilities` defines utility methods useful for working with [Li
st |
| 441 ]. | 487 ]. |
| 442 */ | 488 */ |
| 443 class ListUtilities { | 489 class ListUtilities { |
| 444 /** | 490 /** |
| 445 * Add all of the elements in the given array to the given list. | 491 * Add all of the elements in the given array to the given list. |
| 446 * | 492 * |
| 447 * @param list the list to which the elements are to be added | 493 * @param list the list to which the elements are to be added |
| 448 * @param elements the elements to be added to the list | 494 * @param elements the elements to be added to the list |
| 449 */ | 495 */ |
| 450 static void addAll(List list, List<Object> elements) { | 496 static void addAll(List list, List<Object> elements) { |
| 451 int count = elements.length; | 497 int count = elements.length; |
| 452 for (int i = 0; i < count; i++) { | 498 for (int i = 0; i < count; i++) { |
| 453 list.add(elements[i]); | 499 list.add(elements[i]); |
| 454 } | 500 } |
| 455 } | 501 } |
| 456 } | 502 } |
| 503 |
| 504 /** |
| 505 * Instances of the class `MultipleMapIterator` implement an iterator that can b
e used to |
| 506 * sequentially access the entries in multiple maps. |
| 507 */ |
| 508 class MultipleMapIterator<K, V> implements MapIterator<K, V> { |
| 509 /** |
| 510 * The iterators used to access the entries. |
| 511 */ |
| 512 List<MapIterator<K, V>> _iterators; |
| 513 |
| 514 /** |
| 515 * The index of the iterator currently being used to access the entries. |
| 516 */ |
| 517 int _iteratorIndex = -1; |
| 518 |
| 519 /** |
| 520 * The current iterator, or `null` if there is no current iterator. |
| 521 */ |
| 522 MapIterator<K, V> _currentIterator; |
| 523 |
| 524 /** |
| 525 * Initialize a newly created iterator to return the entries from the given ma
ps. |
| 526 * |
| 527 * @param maps the maps containing the entries to be iterated |
| 528 */ |
| 529 MultipleMapIterator(List<Map<K, V>> maps) { |
| 530 int count = maps.length; |
| 531 _iterators = new List<MapIterator>(count); |
| 532 for (int i = 0; i < count; i++) { |
| 533 _iterators[i] = new SingleMapIterator<K, V>(maps[i]); |
| 534 } |
| 535 } |
| 536 |
| 537 @override |
| 538 K get key { |
| 539 if (_currentIterator == null) { |
| 540 throw new NoSuchElementException(); |
| 541 } |
| 542 return _currentIterator.key; |
| 543 } |
| 544 |
| 545 @override |
| 546 V get value { |
| 547 if (_currentIterator == null) { |
| 548 throw new NoSuchElementException(); |
| 549 } |
| 550 return _currentIterator.value; |
| 551 } |
| 552 |
| 553 @override |
| 554 bool moveNext() { |
| 555 if (_iteratorIndex < 0) { |
| 556 if (_iterators.length == 0) { |
| 557 _currentIterator = null; |
| 558 return false; |
| 559 } |
| 560 if (_advanceToNextIterator()) { |
| 561 return true; |
| 562 } else { |
| 563 _currentIterator = null; |
| 564 return false; |
| 565 } |
| 566 } |
| 567 if (_currentIterator.moveNext()) { |
| 568 return true; |
| 569 } else if (_advanceToNextIterator()) { |
| 570 return true; |
| 571 } else { |
| 572 _currentIterator = null; |
| 573 return false; |
| 574 } |
| 575 } |
| 576 |
| 577 @override |
| 578 void set value(V newValue) { |
| 579 if (_currentIterator == null) { |
| 580 throw new NoSuchElementException(); |
| 581 } |
| 582 _currentIterator.value = newValue; |
| 583 } |
| 584 |
| 585 /** |
| 586 * Under the assumption that there are no more entries that can be returned us
ing the current |
| 587 * iterator, advance to the next iterator that has entries. |
| 588 * |
| 589 * @return `true` if there is a current iterator that has entries |
| 590 */ |
| 591 bool _advanceToNextIterator() { |
| 592 _iteratorIndex++; |
| 593 while (_iteratorIndex < _iterators.length) { |
| 594 MapIterator<K, V> iterator = _iterators[_iteratorIndex]; |
| 595 if (iterator.moveNext()) { |
| 596 _currentIterator = iterator; |
| 597 return true; |
| 598 } |
| 599 _iteratorIndex++; |
| 600 } |
| 601 return false; |
| 602 } |
| 603 } |
| 604 |
| 605 /** |
| 606 * Instances of the class `SingleMapIterator` implement an iterator that can be
used to access |
| 607 * the entries in a single map. |
| 608 */ |
| 609 class SingleMapIterator<K, V> implements MapIterator<K, V> { |
| 610 /** |
| 611 * Returns a new [SingleMapIterator] instance for the given [Map]. |
| 612 */ |
| 613 static SingleMapIterator forMap(Map map) => new SingleMapIterator(map); |
| 614 |
| 615 /** |
| 616 * The [Map] containing the entries to be iterated over. |
| 617 */ |
| 618 final Map<K, V> _map; |
| 619 |
| 620 /** |
| 621 * The iterator used to access the entries. |
| 622 */ |
| 623 Iterator<K> _keyIterator; |
| 624 |
| 625 /** |
| 626 * The current key, or `null` if there is no current key. |
| 627 */ |
| 628 K _currentKey; |
| 629 |
| 630 /** |
| 631 * The current value. |
| 632 */ |
| 633 V _currentValue; |
| 634 |
| 635 /** |
| 636 * Initialize a newly created iterator to return the entries from the given ma
p. |
| 637 * |
| 638 * @param map the map containing the entries to be iterated over |
| 639 */ |
| 640 SingleMapIterator(this._map) { |
| 641 this._keyIterator = _map.keys.iterator; |
| 642 } |
| 643 |
| 644 @override |
| 645 K get key { |
| 646 if (_currentKey == null) { |
| 647 throw new NoSuchElementException(); |
| 648 } |
| 649 return _currentKey; |
| 650 } |
| 651 |
| 652 @override |
| 653 V get value { |
| 654 if (_currentKey == null) { |
| 655 throw new NoSuchElementException(); |
| 656 } |
| 657 return _currentValue; |
| 658 } |
| 659 |
| 660 @override |
| 661 bool moveNext() { |
| 662 if (_keyIterator.moveNext()) { |
| 663 _currentKey = _keyIterator.current; |
| 664 _currentValue = _map[_currentKey]; |
| 665 return true; |
| 666 } else { |
| 667 _currentKey = null; |
| 668 return false; |
| 669 } |
| 670 } |
| 671 |
| 672 @override |
| 673 void set value(V newValue) { |
| 674 if (_currentKey == null) { |
| 675 throw new NoSuchElementException(); |
| 676 } |
| 677 _currentValue = newValue; |
| 678 _map[_currentKey] = newValue; |
| 679 } |
| 680 } |
| OLD | NEW |