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 library analyzer.src.generated.utilities_collection; | 5 library analyzer.src.generated.utilities_collection; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import "dart:math" as math; | 8 import "dart:math" as math; |
9 | 9 |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 16 matching lines...) Expand all Loading... |
27 for (int i = 0; i < a.length; i++) { | 27 for (int i = 0; i < a.length; i++) { |
28 if (a[i] != b[i]) { | 28 if (a[i] != b[i]) { |
29 return false; | 29 return false; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 return true; | 33 return true; |
34 } | 34 } |
35 | 35 |
36 /** | 36 /** |
37 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays | 37 * Methods for operating on integers as if they were arrays of booleans. These |
38 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. | 38 * arrays can be indexed by either integers or by enumeration constants. |
39 */ | 39 */ |
40 class BooleanArray { | 40 class BooleanArray { |
41 /** | 41 /** |
42 * Return the value of the element at the given index. | 42 * Return the value of the element of the given [array] at the given [index]. |
43 * | |
44 * @param array the array being accessed | |
45 * @param index the index of the element being accessed | |
46 * @return the value of the element at the given index | |
47 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
48 */ | 43 */ |
49 static bool get(int array, int index) { | 44 static bool get(int array, int index) { |
50 _checkIndex(index); | 45 _checkIndex(index); |
51 return (array & (1 << index)) > 0; | 46 return (array & (1 << index)) > 0; |
52 } | 47 } |
53 | 48 |
54 /** | 49 /** |
55 * Return the value of the element at the given index. | 50 * Return the value of the element at the given index. |
56 * | |
57 * @param array the array being accessed | |
58 * @param index the index of the element being accessed | |
59 * @return the value of the element at the given index | |
60 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
61 */ | 51 */ |
| 52 @deprecated |
62 static bool getEnum(int array, Enum index) => get(array, index.ordinal); | 53 static bool getEnum(int array, Enum index) => get(array, index.ordinal); |
63 | 54 |
64 /** | 55 /** |
65 * Set the value of the element at the given index to the given value. | 56 * Set the value of the element of the given [array] at the given [index] to |
66 * | 57 * the given [value]. |
67 * @param array the array being modified | |
68 * @param index the index of the element being set | |
69 * @param value the value to be assigned to the element | |
70 * @return the updated value of the array | |
71 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
72 */ | 58 */ |
73 static int set(int array, int index, bool value) { | 59 static int set(int array, int index, bool value) { |
74 _checkIndex(index); | 60 _checkIndex(index); |
75 if (value) { | 61 if (value) { |
76 return array | (1 << index); | 62 return array | (1 << index); |
77 } else { | 63 } else { |
78 return array & ~(1 << index); | 64 return array & ~(1 << index); |
79 } | 65 } |
80 } | 66 } |
81 | 67 |
82 /** | 68 /** |
83 * Set the value of the element at the given index to the given value. | 69 * Set the value of the element at the given index to the given value. |
84 * | |
85 * @param array the array being modified | |
86 * @param index the index of the element being set | |
87 * @param value the value to be assigned to the element | |
88 * @return the updated value of the array | |
89 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
90 */ | 70 */ |
| 71 @deprecated |
91 static int setEnum(int array, Enum index, bool value) => | 72 static int setEnum(int array, Enum index, bool value) => |
92 set(array, index.ordinal, value); | 73 set(array, index.ordinal, value); |
93 | 74 |
94 /** | 75 /** |
95 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array | 76 * Throw an exception if the index is not within the bounds allowed for an |
96 * of boolean values. | 77 * integer-encoded array of boolean values. |
97 * | |
98 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | |
99 */ | 78 */ |
100 static void _checkIndex(int index) { | 79 static void _checkIndex(int index) { |
101 if (index < 0 || index > 30) { | 80 if (index < 0 || index > 30) { |
102 throw new RangeError("Index not between 0 and 30: $index"); | 81 throw new RangeError("Index not between 0 and 30: $index"); |
103 } | 82 } |
104 } | 83 } |
105 } | 84 } |
106 | 85 |
107 /** | 86 /** |
108 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are | 87 * Instances of the class `DirectedGraph` implement a directed graph in which th
e nodes are |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 /** | 717 /** |
739 * Map the key to the value. | 718 * Map the key to the value. |
740 * | 719 * |
741 * @param key the token being mapped to the value | 720 * @param key the token being mapped to the value |
742 * @param value the token to which the key will be mapped | 721 * @param value the token to which the key will be mapped |
743 */ | 722 */ |
744 void put(Token key, Token value) { | 723 void put(Token key, Token value) { |
745 _map[key] = value; | 724 _map[key] = value; |
746 } | 725 } |
747 } | 726 } |
OLD | NEW |