| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 bool every(bool f(E element)) { | 83 bool every(bool f(E element)) { |
| 84 return Collections.every(this, f); | 84 return Collections.every(this, f); |
| 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([Comparator<E> compare = Comparable.compare]) { |
| 96 coreSort(this, compare); | 96 coreSort(this, compare); |
| 97 } | 97 } |
| 98 | 98 |
| 99 int indexOf(E element, [int start = 0]) { | 99 int indexOf(E element, [int start = 0]) { |
| 100 return Arrays.indexOf(this, element, start, this.length); | 100 return Arrays.indexOf(this, element, start, this.length); |
| 101 } | 101 } |
| 102 | 102 |
| 103 int lastIndexOf(E element, [int start = null]) { | 103 int lastIndexOf(E element, [int start = null]) { |
| 104 if (start === null) start = length - 1; | 104 if (start == null) start = length - 1; |
| 105 return Arrays.lastIndexOf(this, element, start); | 105 return Arrays.lastIndexOf(this, element, start); |
| 106 } | 106 } |
| 107 | 107 |
| 108 Iterator<E> iterator() { | 108 Iterator<E> iterator() { |
| 109 return new _FixedSizeArrayIterator<E>(this); | 109 return new _FixedSizeArrayIterator<E>(this); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void add(E element) { | 112 void add(E element) { |
| 113 throw new UnsupportedError( | 113 throw new UnsupportedError( |
| 114 "Cannot add to a non-extendable array"); | 114 "Cannot add to a non-extendable array"); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 bool every(bool f(E element)) { | 225 bool every(bool f(E element)) { |
| 226 return Collections.every(this, f); | 226 return Collections.every(this, f); |
| 227 } | 227 } |
| 228 | 228 |
| 229 bool some(bool f(E element)) { | 229 bool some(bool f(E element)) { |
| 230 return Collections.some(this, f); | 230 return Collections.some(this, f); |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool get isEmpty { | 233 bool get isEmpty { |
| 234 return this.length === 0; | 234 return this.length == 0; |
| 235 } | 235 } |
| 236 | 236 |
| 237 void sort([Comparator<E> compare]) { | 237 void sort([Comparator<E> compare]) { |
| 238 throw new UnsupportedError( | 238 throw new UnsupportedError( |
| 239 "Cannot modify an immutable array"); | 239 "Cannot modify an immutable array"); |
| 240 } | 240 } |
| 241 | 241 |
| 242 String toString() { | 242 String toString() { |
| 243 return Collections.collectionToString(this); | 243 return Collections.collectionToString(this); |
| 244 } | 244 } |
| 245 | 245 |
| 246 int indexOf(E element, [int start = 0]) { | 246 int indexOf(E element, [int start = 0]) { |
| 247 return Arrays.indexOf(this, element, start, this.length); | 247 return Arrays.indexOf(this, element, start, this.length); |
| 248 } | 248 } |
| 249 | 249 |
| 250 int lastIndexOf(E element, [int start = null]) { | 250 int lastIndexOf(E element, [int start = null]) { |
| 251 if (start === null) start = length - 1; | 251 if (start == null) start = length - 1; |
| 252 return Arrays.lastIndexOf(this, element, start); | 252 return Arrays.lastIndexOf(this, element, start); |
| 253 } | 253 } |
| 254 | 254 |
| 255 Iterator<E> iterator() { | 255 Iterator<E> iterator() { |
| 256 return new _FixedSizeArrayIterator<E>(this); | 256 return new _FixedSizeArrayIterator<E>(this); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void add(E element) { | 259 void add(E element) { |
| 260 throw new UnsupportedError( | 260 throw new UnsupportedError( |
| 261 "Cannot add to an immutable array"); | 261 "Cannot add to an immutable array"); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (!hasNext) { | 306 if (!hasNext) { |
| 307 throw new StateError("No more elements"); | 307 throw new StateError("No more elements"); |
| 308 } | 308 } |
| 309 return _array[_pos++]; | 309 return _array[_pos++]; |
| 310 } | 310 } |
| 311 | 311 |
| 312 final List<E> _array; | 312 final List<E> _array; |
| 313 final int _length; // Cache array length for faster access. | 313 final int _length; // Cache array length for faster access. |
| 314 int _pos; | 314 int _pos; |
| 315 } | 315 } |
| OLD | NEW |