| 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'; |
| 11 import 'scanner.dart' show Token; | 11 import 'scanner.dart' show Token; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays |
| 15 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. |
| 16 */ |
| 17 class BooleanArray { |
| 18 /** |
| 19 * Return the value of the element at the given index. |
| 20 * |
| 21 * @param array the array being accessed |
| 22 * @param index the index of the element being accessed |
| 23 * @return the value of the element at the given index |
| 24 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 25 */ |
| 26 static bool get(int array, int index) { |
| 27 _checkIndex(index); |
| 28 return (array & (1 << index)) > 0; |
| 29 } |
| 30 |
| 31 /** |
| 32 * Return the value of the element at the given index. |
| 33 * |
| 34 * @param array the array being accessed |
| 35 * @param index the index of the element being accessed |
| 36 * @return the value of the element at the given index |
| 37 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 38 */ |
| 39 static bool getEnum(int array, Enum index) => get(array, index.ordinal); |
| 40 |
| 41 /** |
| 42 * Set the value of the element at the given index to the given value. |
| 43 * |
| 44 * @param array the array being modified |
| 45 * @param index the index of the element being set |
| 46 * @param value the value to be assigned to the element |
| 47 * @return the updated value of the array |
| 48 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 49 */ |
| 50 static int set(int array, int index, bool value) { |
| 51 _checkIndex(index); |
| 52 if (value) { |
| 53 return array | (1 << index); |
| 54 } else { |
| 55 return array & ~(1 << index); |
| 56 } |
| 57 } |
| 58 |
| 59 /** |
| 60 * Set the value of the element at the given index to the given value. |
| 61 * |
| 62 * @param array the array being modified |
| 63 * @param index the index of the element being set |
| 64 * @param value the value to be assigned to the element |
| 65 * @return the updated value of the array |
| 66 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 67 */ |
| 68 static int setEnum(int array, Enum index, bool value) => set(array, index.ordi
nal, value); |
| 69 |
| 70 /** |
| 71 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array |
| 72 * of boolean values. |
| 73 * |
| 74 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 75 */ |
| 76 static void _checkIndex(int index) { |
| 77 if (index < 0 || index > 30) { |
| 78 throw new RangeError("Index not between 0 and 30: ${index}"); |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 /** |
| 14 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are | 84 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are |
| 15 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an | 85 * arbitrary (client provided) objects and edges are represented implicitly. The
graph will allow an |
| 16 * edge from any node to any other node, including itself, but will not represen
t multiple edges | 86 * edge from any node to any other node, including itself, but will not represen
t multiple edges |
| 17 * between the same pair of nodes. | 87 * between the same pair of nodes. |
| 18 * | 88 * |
| 19 * @param N the type of the nodes in the graph | 89 * @param N the type of the nodes in the graph |
| 20 */ | 90 */ |
| 21 class DirectedGraph<N> { | 91 class DirectedGraph<N> { |
| 22 /** | 92 /** |
| 23 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head | 93 * The table encoding the edges in the graph. An edge is represented by an ent
ry mapping the head |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 w = _pop(); | 399 w = _pop(); |
| 330 component.add(w); | 400 component.add(w); |
| 331 _nodeMap[w].component = component; | 401 _nodeMap[w].component = component; |
| 332 } while (!identical(w, v)); | 402 } while (!identical(w, v)); |
| 333 } | 403 } |
| 334 return vInfo; | 404 return vInfo; |
| 335 } | 405 } |
| 336 } | 406 } |
| 337 | 407 |
| 338 /** | 408 /** |
| 339 * Instances of the class `TokenMap` map one set of tokens to another set of tok
ens. | 409 * The class `ListUtilities` defines utility methods useful for working with [Li
st |
| 410 ]. |
| 340 */ | 411 */ |
| 341 class TokenMap { | 412 class ListUtilities { |
| 342 /** | 413 /** |
| 343 * A table mapping tokens to tokens. This should be replaced by a more perform
ant implementation. | 414 * Add all of the elements in the given array to the given list. |
| 344 * One possibility is a pair of parallel arrays, with keys being sorted by the
ir offset and a | 415 * |
| 345 * cursor indicating where to start searching. | 416 * @param list the list to which the elements are to be added |
| 417 * @param elements the elements to be added to the list |
| 346 */ | 418 */ |
| 347 Map<Token, Token> _map = new Map<Token, Token>(); | 419 static void addAll(List list, List<Object> elements) { |
| 348 | 420 int count = elements.length; |
| 349 /** | 421 for (int i = 0; i < count; i++) { |
| 350 * Return the token that is mapped to the given token, or `null` if there is n
o token | 422 list.add(elements[i]); |
| 351 * corresponding to the given token. | 423 } |
| 352 * | |
| 353 * @param key the token being mapped to another token | |
| 354 * @return the token that is mapped to the given token | |
| 355 */ | |
| 356 Token get(Token key) => _map[key]; | |
| 357 | |
| 358 /** | |
| 359 * Map the key to the value. | |
| 360 * | |
| 361 * @param key the token being mapped to the value | |
| 362 * @param value the token to which the key will be mapped | |
| 363 */ | |
| 364 void put(Token key, Token value) { | |
| 365 _map[key] = value; | |
| 366 } | 424 } |
| 367 } | 425 } |
| 368 | 426 |
| 369 /** | 427 /** |
| 370 * The interface `MapIterator` defines the behavior of objects that iterate over
the entries | 428 * The interface `MapIterator` defines the behavior of objects that iterate over
the entries |
| 371 * in a map. | 429 * in a map. |
| 372 * | 430 * |
| 373 * This interface defines the concept of a current entry and provides methods to
access the key and | 431 * This interface defines the concept of a current entry and provides methods to
access the key and |
| 374 * value in the current entry. When an iterator is first created it will be posi
tioned before the | 432 * value in the current entry. When an iterator is first created it will be posi
tioned before the |
| 375 * first entry and there is no current entry until [moveNext] is invoked. When a
ll of the | 433 * first entry and there is no current entry until [moveNext] is invoked. When a
ll of the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 406 /** | 464 /** |
| 407 * Set the value associated with the current element to the given value. | 465 * Set the value associated with the current element to the given value. |
| 408 * | 466 * |
| 409 * @param newValue the new value to be associated with the current element | 467 * @param newValue the new value to be associated with the current element |
| 410 * @throws NoSuchElementException if there is no current element | 468 * @throws NoSuchElementException if there is no current element |
| 411 */ | 469 */ |
| 412 void set value(V newValue); | 470 void set value(V newValue); |
| 413 } | 471 } |
| 414 | 472 |
| 415 /** | 473 /** |
| 416 * The class `ListUtilities` defines utility methods useful for working with [Li
st | |
| 417 ]. | |
| 418 */ | |
| 419 class ListUtilities { | |
| 420 /** | |
| 421 * Add all of the elements in the given array to the given list. | |
| 422 * | |
| 423 * @param list the list to which the elements are to be added | |
| 424 * @param elements the elements to be added to the list | |
| 425 */ | |
| 426 static void addAll(List list, List<Object> elements) { | |
| 427 int count = elements.length; | |
| 428 for (int i = 0; i < count; i++) { | |
| 429 list.add(elements[i]); | |
| 430 } | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 /** | |
| 435 * Instances of the class `MultipleMapIterator` implement an iterator that can b
e used to | 474 * Instances of the class `MultipleMapIterator` implement an iterator that can b
e used to |
| 436 * sequentially access the entries in multiple maps. | 475 * sequentially access the entries in multiple maps. |
| 437 */ | 476 */ |
| 438 class MultipleMapIterator<K, V> implements MapIterator<K, V> { | 477 class MultipleMapIterator<K, V> implements MapIterator<K, V> { |
| 439 /** | 478 /** |
| 440 * The iterators used to access the entries. | 479 * The iterators used to access the entries. |
| 441 */ | 480 */ |
| 442 List<MapIterator<K, V>> _iterators; | 481 List<MapIterator<K, V>> _iterators; |
| 443 | 482 |
| 444 /** | 483 /** |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 _currentIterator = iterator; | 565 _currentIterator = iterator; |
| 527 return true; | 566 return true; |
| 528 } | 567 } |
| 529 _iteratorIndex++; | 568 _iteratorIndex++; |
| 530 } | 569 } |
| 531 return false; | 570 return false; |
| 532 } | 571 } |
| 533 } | 572 } |
| 534 | 573 |
| 535 /** | 574 /** |
| 536 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays | 575 * Instances of the class `TokenMap` map one set of tokens to another set of tok
ens. |
| 537 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. | |
| 538 */ | 576 */ |
| 539 class BooleanArray { | 577 class TokenMap { |
| 540 /** | 578 /** |
| 541 * Return the value of the element at the given index. | 579 * A table mapping tokens to tokens. This should be replaced by a more perform
ant implementation. |
| 542 * | 580 * One possibility is a pair of parallel arrays, with keys being sorted by the
ir offset and a |
| 543 * @param array the array being accessed | 581 * cursor indicating where to start searching. |
| 544 * @param index the index of the element being accessed | |
| 545 * @return the value of the element at the given index | |
| 546 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 547 */ | 582 */ |
| 548 static bool get(int array, int index) { | 583 Map<Token, Token> _map = new Map<Token, Token>(); |
| 549 _checkIndex(index); | |
| 550 return (array & (1 << index)) > 0; | |
| 551 } | |
| 552 | 584 |
| 553 /** | 585 /** |
| 554 * Return the value of the element at the given index. | 586 * Return the token that is mapped to the given token, or `null` if there is n
o token |
| 587 * corresponding to the given token. |
| 555 * | 588 * |
| 556 * @param array the array being accessed | 589 * @param key the token being mapped to another token |
| 557 * @param index the index of the element being accessed | 590 * @return the token that is mapped to the given token |
| 558 * @return the value of the element at the given index | |
| 559 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 560 */ | 591 */ |
| 561 static bool getEnum(int array, Enum index) => get(array, index.ordinal); | 592 Token get(Token key) => _map[key]; |
| 562 | 593 |
| 563 /** | 594 /** |
| 564 * Set the value of the element at the given index to the given value. | 595 * Map the key to the value. |
| 565 * | 596 * |
| 566 * @param array the array being modified | 597 * @param key the token being mapped to the value |
| 567 * @param index the index of the element being set | 598 * @param value the token to which the key will be mapped |
| 568 * @param value the value to be assigned to the element | |
| 569 * @return the updated value of the array | |
| 570 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 571 */ | 599 */ |
| 572 static int set(int array, int index, bool value) { | 600 void put(Token key, Token value) { |
| 573 _checkIndex(index); | 601 _map[key] = value; |
| 574 if (value) { | |
| 575 return array | (1 << index); | |
| 576 } else { | |
| 577 return array & ~(1 << index); | |
| 578 } | |
| 579 } | |
| 580 | |
| 581 /** | |
| 582 * Set the value of the element at the given index to the given value. | |
| 583 * | |
| 584 * @param array the array being modified | |
| 585 * @param index the index of the element being set | |
| 586 * @param value the value to be assigned to the element | |
| 587 * @return the updated value of the array | |
| 588 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 589 */ | |
| 590 static int setEnum(int array, Enum index, bool value) => set(array, index.ordi
nal, value); | |
| 591 | |
| 592 /** | |
| 593 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array | |
| 594 * of boolean values. | |
| 595 * | |
| 596 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
| 597 */ | |
| 598 static void _checkIndex(int index) { | |
| 599 if (index < 0 || index > 30) { | |
| 600 throw new RangeError("Index not between 0 and 30: ${index}"); | |
| 601 } | |
| 602 } | 602 } |
| 603 } | 603 } |
| 604 | 604 |
| 605 /** | 605 /** |
| 606 * Instances of the class `SingleMapIterator` implement an iterator that can be
used to access | 606 * Instances of the class `SingleMapIterator` implement an iterator that can be
used to access |
| 607 * the entries in a single map. | 607 * the entries in a single map. |
| 608 */ | 608 */ |
| 609 class SingleMapIterator<K, V> implements MapIterator<K, V> { | 609 class SingleMapIterator<K, V> implements MapIterator<K, V> { |
| 610 /** | 610 /** |
| 611 * Returns a new [SingleMapIterator] instance for the given [Map]. | 611 * Returns a new [SingleMapIterator] instance for the given [Map]. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 | 671 |
| 672 @override | 672 @override |
| 673 void set value(V newValue) { | 673 void set value(V newValue) { |
| 674 if (_currentKey == null) { | 674 if (_currentKey == null) { |
| 675 throw new NoSuchElementException(); | 675 throw new NoSuchElementException(); |
| 676 } | 676 } |
| 677 _currentValue = newValue; | 677 _currentValue = newValue; |
| 678 _map[_currentKey] = newValue; | 678 _map[_currentKey] = newValue; |
| 679 } | 679 } |
| 680 } | 680 } |
| OLD | NEW |