OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class Arrays { | 5 class Arrays { |
6 | 6 |
7 static String asString(Array array) { | 7 static String asString(Array array) { |
8 String result = "["; | 8 String result = "["; |
9 int len = array.length; | 9 int len = array.length; |
10 for (int i = 0; i < len; i++) { | 10 for (int i = 0; i < len; i++) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (startIndex >= a.length) { | 79 if (startIndex >= a.length) { |
80 startIndex = a.length - 1; | 80 startIndex = a.length - 1; |
81 } | 81 } |
82 for (int i = startIndex; i >= 0; i--) { | 82 for (int i = startIndex; i >= 0; i--) { |
83 if (a[i] == element) { | 83 if (a[i] == element) { |
84 return i; | 84 return i; |
85 } | 85 } |
86 } | 86 } |
87 return -1; | 87 return -1; |
88 } | 88 } |
| 89 |
| 90 static void rangeCheck(Array a, int start, int length) { |
| 91 if (length < 0) { |
| 92 throw new IllegalArgumentException("negative length $length"); |
| 93 } |
| 94 if (start < 0 || start > a.length) { |
| 95 throw new IndexOutOfRangeException(start); |
| 96 } |
| 97 if (start + length > a.length) { |
| 98 throw new IndexOutOfRangeException(start + length); |
| 99 } |
| 100 } |
89 } | 101 } |
90 | 102 |
OLD | NEW |