| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // TODO(ngeoffray): Rename to Lists. | |
| 6 class Arrays { | |
| 7 static void copy(List src, int srcStart, | |
| 8 List dst, int dstStart, int count) { | |
| 9 if (srcStart === null) srcStart = 0; | |
| 10 if (dstStart === null) dstStart = 0; | |
| 11 | |
| 12 if (srcStart < dstStart) { | |
| 13 for (int i = srcStart + count - 1, j = dstStart + count - 1; | |
| 14 i >= srcStart; i--, j--) { | |
| 15 dst[j] = src[i]; | |
| 16 } | |
| 17 } else { | |
| 18 for (int i = srcStart, j = dstStart; i < srcStart + count; i++, j++) { | |
| 19 dst[j] = src[i]; | |
| 20 } | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 static bool areEqual(List a, Object b) { | |
| 25 if (a === b) return true; | |
| 26 if (!(b is List)) return false; | |
| 27 int length = a.length; | |
| 28 if (length != b.length) return false; | |
| 29 | |
| 30 for (int i = 0; i < length; i++) { | |
| 31 if (a[i] !== b[i]) return false; | |
| 32 } | |
| 33 return true; | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Returns the index in the list [a] of the given [element], starting | |
| 38 * the search at index [startIndex] to [endIndex] (exclusive). | |
| 39 * Returns -1 if [element] is not found. | |
| 40 */ | |
| 41 static int indexOf(List a, | |
| 42 Object element, | |
| 43 int startIndex, | |
| 44 int endIndex) { | |
| 45 if (startIndex >= a.length) { | |
| 46 return -1; | |
| 47 } | |
| 48 if (startIndex < 0) { | |
| 49 startIndex = 0; | |
| 50 } | |
| 51 for (int i = startIndex; i < endIndex; i++) { | |
| 52 if (a[i] == element) { | |
| 53 return i; | |
| 54 } | |
| 55 } | |
| 56 return -1; | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * Returns the last index in the list [a] of the given [element], starting | |
| 61 * the search at index [startIndex] to 0. | |
| 62 * Returns -1 if [element] is not found. | |
| 63 */ | |
| 64 static int lastIndexOf(List a, Object element, int startIndex) { | |
| 65 if (startIndex < 0) { | |
| 66 return -1; | |
| 67 } | |
| 68 if (startIndex >= a.length) { | |
| 69 startIndex = a.length - 1; | |
| 70 } | |
| 71 for (int i = startIndex; i >= 0; i--) { | |
| 72 if (a[i] == element) { | |
| 73 return i; | |
| 74 } | |
| 75 } | |
| 76 return -1; | |
| 77 } | |
| 78 | |
| 79 static void rangeCheck(List a, int start, int length) { | |
| 80 if (length < 0) { | |
| 81 throw new ArgumentError("negative length $length"); | |
| 82 } | |
| 83 if (start < 0 ) { | |
| 84 String message = "$start must be greater than or equal to 0"; | |
| 85 throw new IndexOutOfRangeException(message); | |
| 86 } | |
| 87 if (start + length > a.length) { | |
| 88 String message = "$start + $length must be in the range [0..${a.length})"; | |
| 89 throw new IndexOutOfRangeException(message); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| OLD | NEW |