OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 5 |
6 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
7 class _ObjectArray<E> implements List<E> { | 7 class _ObjectArray<E> implements List<E> { |
8 | 8 |
9 factory _ObjectArray(int length) native "ObjectArray_allocate"; | 9 factory _ObjectArray(int length) native "ObjectArray_allocate"; |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 bool some(bool f(E element)) { | 87 bool some(bool f(E element)) { |
88 return Collections.some(this, f); | 88 return Collections.some(this, f); |
89 } | 89 } |
90 | 90 |
91 bool get isEmpty { | 91 bool get isEmpty { |
92 return this.length == 0; | 92 return this.length == 0; |
93 } | 93 } |
94 | 94 |
95 void sort([Comparator<E> compare = Comparable.compare]) { | 95 void sort([int compare(E a, E b)]) { |
| 96 if (compare == null) compare = Comparable.compare; |
96 _Sort.sort(this, compare); | 97 _Sort.sort(this, compare); |
97 } | 98 } |
98 | 99 |
99 int indexOf(E element, [int start = 0]) { | 100 int indexOf(E element, [int start = 0]) { |
100 return Arrays.indexOf(this, element, start, this.length); | 101 return Arrays.indexOf(this, element, start, this.length); |
101 } | 102 } |
102 | 103 |
103 int lastIndexOf(E element, [int start = null]) { | 104 int lastIndexOf(E element, [int start = null]) { |
104 if (start == null) start = length - 1; | 105 if (start == null) start = length - 1; |
105 return Arrays.lastIndexOf(this, element, start); | 106 return Arrays.lastIndexOf(this, element, start); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 232 } |
232 | 233 |
233 bool some(bool f(E element)) { | 234 bool some(bool f(E element)) { |
234 return Collections.some(this, f); | 235 return Collections.some(this, f); |
235 } | 236 } |
236 | 237 |
237 bool get isEmpty { | 238 bool get isEmpty { |
238 return this.length == 0; | 239 return this.length == 0; |
239 } | 240 } |
240 | 241 |
241 void sort([Comparator<E> compare]) { | 242 void sort([int compare(E a, E b)]) { |
242 throw new UnsupportedError( | 243 throw new UnsupportedError( |
243 "Cannot modify an immutable array"); | 244 "Cannot modify an immutable array"); |
244 } | 245 } |
245 | 246 |
246 String toString() { | 247 String toString() { |
247 return Collections.collectionToString(this); | 248 return Collections.collectionToString(this); |
248 } | 249 } |
249 | 250 |
250 int indexOf(E element, [int start = 0]) { | 251 int indexOf(E element, [int start = 0]) { |
251 return Arrays.indexOf(this, element, start, this.length); | 252 return Arrays.indexOf(this, element, start, this.length); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (!hasNext) { | 315 if (!hasNext) { |
315 throw new StateError("No more elements"); | 316 throw new StateError("No more elements"); |
316 } | 317 } |
317 return _array[_pos++]; | 318 return _array[_pos++]; |
318 } | 319 } |
319 | 320 |
320 final List<E> _array; | 321 final List<E> _array; |
321 final int _length; // Cache array length for faster access. | 322 final int _length; // Cache array length for faster access. |
322 int _pos; | 323 int _pos; |
323 } | 324 } |
OLD | NEW |