| OLD | NEW |
| 1 /* | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 * Copyright (c) 2013, the Dart project authors. | 2 // significant change. Please see the README file for more information. |
| 3 * | 3 library engine.utilities.collection; |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 import 'java_core.dart'; |
| 5 * in compliance with the License. You may obtain a copy of the License at | |
| 6 * | |
| 7 * http://www.eclipse.org/legal/epl-v10.html | |
| 8 * | |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under | |
| 12 * the License. | |
| 13 */ | |
| 14 package com.google.dart.engine.utilities.collection; | |
| 15 | |
| 16 /** | 5 /** |
| 17 * The class {@code BooleanArray} defines methods for operating on integers as i
f they were arrays | 6 * The class `BooleanArray` defines methods for operating on integers as if they
were arrays |
| 18 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. | 7 * of booleans. These arrays can be indexed by either integers or by enumeration
constants. |
| 19 */ | 8 */ |
| 20 public final class BooleanArray { | 9 class BooleanArray { |
| 10 |
| 21 /** | 11 /** |
| 22 * Return the value of the element at the given index. | 12 * Return the value of the element at the given index. |
| 23 * | 13 * |
| 24 * @param array the array being accessed | 14 * @param array the array being accessed |
| 25 * @param index the index of the element being accessed | 15 * @param index the index of the element being accessed |
| 26 * @return the value of the element at the given index | 16 * @return the value of the element at the given index |
| 27 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | 17 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 28 */ | 18 */ |
| 29 public static boolean get(int array, Enum<?> index) { | 19 static bool get(int array, Enum<Object> index) => get2(array, index.ordinal); |
| 30 return get(array, index.ordinal()); | |
| 31 } | |
| 32 | 20 |
| 33 /** | 21 /** |
| 34 * Return the value of the element at the given index. | 22 * Return the value of the element at the given index. |
| 35 * | 23 * |
| 36 * @param array the array being accessed | 24 * @param array the array being accessed |
| 37 * @param index the index of the element being accessed | 25 * @param index the index of the element being accessed |
| 38 * @return the value of the element at the given index | 26 * @return the value of the element at the given index |
| 39 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | 27 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 40 */ | 28 */ |
| 41 public static boolean get(int array, int index) { | 29 static bool get2(int array, int index) { |
| 42 checkIndex(index); | 30 checkIndex(index); |
| 43 return (array & (1 << index)) > 0; | 31 return (array & (1 << index)) > 0; |
| 44 } | 32 } |
| 45 | 33 |
| 46 /** | 34 /** |
| 47 * Set the value of the element at the given index to the given value. | 35 * Set the value of the element at the given index to the given value. |
| 48 * | 36 * |
| 49 * @param array the array being modified | 37 * @param array the array being modified |
| 50 * @param index the index of the element being set | 38 * @param index the index of the element being set |
| 51 * @param value the value to be assigned to the element | 39 * @param value the value to be assigned to the element |
| 52 * @return the updated value of the array | 40 * @return the updated value of the array |
| 53 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | 41 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 54 */ | 42 */ |
| 55 public static int set(int array, Enum<?> index, boolean value) { | 43 static int set(int array, Enum<Object> index, bool value) => set2(array, index
.ordinal, value); |
| 56 return set(array, index.ordinal(), value); | |
| 57 } | |
| 58 | 44 |
| 59 /** | 45 /** |
| 60 * Set the value of the element at the given index to the given value. | 46 * Set the value of the element at the given index to the given value. |
| 61 * | 47 * |
| 62 * @param array the array being modified | 48 * @param array the array being modified |
| 63 * @param index the index of the element being set | 49 * @param index the index of the element being set |
| 64 * @param value the value to be assigned to the element | 50 * @param value the value to be assigned to the element |
| 65 * @return the updated value of the array | 51 * @return the updated value of the array |
| 66 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | 52 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 67 */ | 53 */ |
| 68 public static int set(int array, int index, boolean value) { | 54 static int set2(int array, int index, bool value) { |
| 69 checkIndex(index); | 55 checkIndex(index); |
| 70 if (value) { | 56 if (value) { |
| 71 return array | (1 << index); | 57 return array | (1 << index); |
| 72 } else { | 58 } else { |
| 73 return array & ~(1 << index); | 59 return array & ~(1 << index); |
| 74 } | 60 } |
| 75 } | 61 } |
| 76 | 62 |
| 77 /** | 63 /** |
| 78 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array | 64 * Throw an exception if the index is not within the bounds allowed for an int
eger-encoded array |
| 79 * of boolean values. | 65 * of boolean values. |
| 80 * | 66 * |
| 81 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive | 67 * @throws IndexOutOfBoundsException if the index is not between zero (0) and
31, inclusive |
| 82 */ | 68 */ |
| 83 private static void checkIndex(int index) { | 69 static void checkIndex(int index) { |
| 84 if (index < 0 || index > 30) { | 70 if (index < 0 || index > 30) { |
| 85 throw new IndexOutOfBoundsException("Index not between 0 and 30: " + index
); | 71 throw new RangeError("Index not between 0 and 30: ${index}"); |
| 86 } | 72 } |
| 87 } | 73 } |
| 74 } |
| 75 /** |
| 76 * The class `ListUtilities` defines utility methods useful for working with [Li
st |
| 77 ]. |
| 78 */ |
| 79 class ListUtilities { |
| 88 | 80 |
| 89 /** | 81 /** |
| 90 * Prevent the creation of instances of this class. | 82 * Add all of the elements in the given array to the given list. |
| 83 * |
| 84 * @param list the list to which the elements are to be added |
| 85 * @param elements the elements to be added to the list |
| 91 */ | 86 */ |
| 92 private BooleanArray() { | 87 static void addAll(List list, List<Object> elements) { |
| 93 super(); | 88 for (Object element in elements) { |
| 89 list.add(element); |
| 90 } |
| 94 } | 91 } |
| 95 } | 92 } |
| OLD | NEW |