OLD | NEW |
| (Empty) |
1 // This code was auto-generated, is not intended to be edited, and is subject to | |
2 // significant change. Please see the README file for more information. | |
3 library engine.utilities.collection; | |
4 import 'java_core.dart'; | |
5 import 'scanner.dart' show Token; | |
6 /** | |
7 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays | |
8 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. | |
9 */ | |
10 class BooleanArray { | |
11 | |
12 /** | |
13 * Return the value of the element at the given index. | |
14 * | |
15 * @param array the array being accessed | |
16 * @param index the index of the element being accessed | |
17 * @return the value of the element at the given index | |
18 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
19 */ | |
20 static bool get(int array, Enum index) => get2(array, index.ordinal); | |
21 | |
22 /** | |
23 * Return the value of the element at the given index. | |
24 * | |
25 * @param array the array being accessed | |
26 * @param index the index of the element being accessed | |
27 * @return the value of the element at the given index | |
28 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
29 */ | |
30 static bool get2(int array, int index) { | |
31 checkIndex(index); | |
32 return (array & (1 << index)) > 0; | |
33 } | |
34 | |
35 /** | |
36 * Set the value of the element at the given index to the given value. | |
37 * | |
38 * @param array the array being modified | |
39 * @param index the index of the element being set | |
40 * @param value the value to be assigned to the element | |
41 * @return the updated value of the array | |
42 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
43 */ | |
44 static int set(int array, Enum index, bool value) => set2(array, index.ordinal
, value); | |
45 | |
46 /** | |
47 * Set the value of the element at the given index to the given value. | |
48 * | |
49 * @param array the array being modified | |
50 * @param index the index of the element being set | |
51 * @param value the value to be assigned to the element | |
52 * @return the updated value of the array | |
53 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
54 */ | |
55 static int set2(int array, int index, bool value) { | |
56 checkIndex(index); | |
57 if (value) { | |
58 return array | (1 << index); | |
59 } else { | |
60 return array & ~(1 << index); | |
61 } | |
62 } | |
63 | |
64 /** | |
65 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array | |
66 * of boolean values. | |
67 * | |
68 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
69 */ | |
70 static void checkIndex(int index) { | |
71 if (index < 0 || index > 30) { | |
72 throw new RangeError("Index not between 0 and 30: ${index}"); | |
73 } | |
74 } | |
75 } | |
76 /** | |
77 * Instances of the class `TokenMap` map one set of tokens to another set of tok
ens. | |
78 */ | |
79 class TokenMap { | |
80 | |
81 /** | |
82 * A table mapping tokens to tokens. This should be replaced by a more perform
ant implementation. | |
83 * One possibility is a pair of parallel arrays, with keys being sorted by the
ir offset and a | |
84 * cursor indicating where to start searching. | |
85 */ | |
86 Map<Token, Token> _map = new Map<Token, Token>(); | |
87 | |
88 /** | |
89 * Return the token that is mapped to the given token, or `null` if there is n
o token | |
90 * corresponding to the given token. | |
91 * | |
92 * @param key the token being mapped to another token | |
93 * @return the token that is mapped to the given token | |
94 */ | |
95 Token get(Token key) => _map[key]; | |
96 | |
97 /** | |
98 * Map the key to the value. | |
99 * | |
100 * @param key the token being mapped to the value | |
101 * @param value the token to which the key will be mapped | |
102 */ | |
103 void put(Token key, Token value) { | |
104 _map[key] = value; | |
105 } | |
106 } | |
107 /** | |
108 * The class `ListUtilities` defines utility methods useful for working with [Li
st | |
109 ]. | |
110 */ | |
111 class ListUtilities { | |
112 | |
113 /** | |
114 * Add all of the elements in the given array to the given list. | |
115 * | |
116 * @param list the list to which the elements are to be added | |
117 * @param elements the elements to be added to the list | |
118 */ | |
119 static void addAll(List list, List<Object> elements) { | |
120 for (Object element in elements) { | |
121 list.add(element); | |
122 } | |
123 } | |
124 } | |
OLD | NEW |