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