| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 Arrays.rangeCheck(this, start, length); | 55 Arrays.rangeCheck(this, start, length); |
| 56 List list = new _GrowableObjectArray<E>.withCapacity(length); | 56 List list = new _GrowableObjectArray<E>.withCapacity(length); |
| 57 list.length = length; | 57 list.length = length; |
| 58 Arrays.copy(this, start, list, 0, length); | 58 Arrays.copy(this, start, list, 0, length); |
| 59 return list; | 59 return list; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Collection interface. | 62 // Collection interface. |
| 63 | 63 |
| 64 bool contains(E element) { | 64 bool contains(E element) { |
| 65 return IterableMixinWorkaround.contains(this, element); | 65 return Collections.contains(this, element); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void forEach(f(E element)) { | 68 void forEach(f(E element)) { |
| 69 IterableMixinWorkaround.forEach(this, f); | 69 Collections.forEach(this, f); |
| 70 } | 70 } |
| 71 | 71 |
| 72 String join([String separator]) { | 72 String join([String separator]) { |
| 73 return IterableMixinWorkaround.joinList(this, separator); | 73 return Collections.joinList(this, separator); |
| 74 } | 74 } |
| 75 | 75 |
| 76 List mappedBy(f(E element)) { | 76 List mappedBy(f(E element)) { |
| 77 return IterableMixinWorkaround.mappedByList(this, f); | 77 return new MappedList<E, dynamic>(this, f); |
| 78 } | 78 } |
| 79 | 79 |
| 80 reduce(initialValue, combine(previousValue, E element)) { | 80 reduce(initialValue, combine(previousValue, E element)) { |
| 81 return IterableMixinWorkaround.reduce(this, initialValue, combine); | 81 return Collections.reduce(this, initialValue, combine); |
| 82 } | 82 } |
| 83 | 83 |
| 84 Iterable<E> where(bool f(E element)) { | 84 Iterable<E> where(bool f(E element)) { |
| 85 return IterableMixinWorkaround.where(this, f); | 85 return new WhereIterable<E>(this, f); |
| 86 } | 86 } |
| 87 | 87 |
| 88 List<E> take(int n) { | 88 List<E> take(int n) { |
| 89 return IterableMixinWorkaround.takeList(this, n); | 89 return new ListView<E>(this, 0, n); |
| 90 } | 90 } |
| 91 | 91 |
| 92 Iterable<E> takeWhile(bool test(E value)) { | 92 Iterable<E> takeWhile(bool test(E value)) { |
| 93 return IterableMixinWorkaround.takeWhile(this, test); | 93 return new TakeWhileIterable<E>(this, test); |
| 94 } | 94 } |
| 95 | 95 |
| 96 List<E> skip(int n) { | 96 List<E> skip(int n) { |
| 97 return IterableMixinWorkaround.skipList(this, n); | 97 return new ListView<E>(this, n, null); |
| 98 } | 98 } |
| 99 | 99 |
| 100 Iterable<E> skipWhile(bool test(E value)) { | 100 Iterable<E> skipWhile(bool test(E value)) { |
| 101 return IterableMixinWorkaround.skipWhile(this, test); | 101 return new SkipWhileIterable<E>(this, test); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool every(bool f(E element)) { | 104 bool every(bool f(E element)) { |
| 105 return IterableMixinWorkaround.every(this, f); | 105 return Collections.every(this, f); |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool any(bool f(E element)) { | 108 bool any(bool f(E element)) { |
| 109 return IterableMixinWorkaround.any(this, f); | 109 return Collections.any(this, f); |
| 110 } | 110 } |
| 111 | 111 |
| 112 E firstMatching(bool test(E value), {E orElse()}) { | 112 E firstMatching(bool test(E value), {E orElse()}) { |
| 113 return IterableMixinWorkaround.firstMatching(this, test, orElse); | 113 return Collections.firstMatching(this, test, orElse); |
| 114 } | 114 } |
| 115 | 115 |
| 116 E lastMatching(bool test(E value), {E orElse()}) { | 116 E lastMatching(bool test(E value), {E orElse()}) { |
| 117 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); | 117 return Collections.lastMatchingInList(this, test, orElse); |
| 118 } | 118 } |
| 119 | 119 |
| 120 E singleMatching(bool test(E value)) { | 120 E singleMatching(bool test(E value)) { |
| 121 return IterableMixinWorkaround.singleMatching(this, test); | 121 return Collections.singleMatching(this, test); |
| 122 } | 122 } |
| 123 | 123 |
| 124 E elementAt(int index) { | 124 E elementAt(int index) { |
| 125 return this[index]; | 125 return this[index]; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool get isEmpty { | 128 bool get isEmpty { |
| 129 return this.length == 0; | 129 return this.length == 0; |
| 130 } | 130 } |
| 131 | 131 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (length > 0) return this[length - 1]; | 185 if (length > 0) return this[length - 1]; |
| 186 throw new StateError("No elements"); | 186 throw new StateError("No elements"); |
| 187 } | 187 } |
| 188 | 188 |
| 189 E get single { | 189 E get single { |
| 190 if (length == 1) return this[0]; | 190 if (length == 1) return this[0]; |
| 191 if (length == 0) throw new StateError("No elements"); | 191 if (length == 0) throw new StateError("No elements"); |
| 192 throw new StateError("More than one element"); | 192 throw new StateError("More than one element"); |
| 193 } | 193 } |
| 194 | 194 |
| 195 E min([int compare(E a, E b)]) => IterableMixinWorkaround.min(this, compare); | 195 E min([int compare(E a, E b)]) => Collections.min(this, compare); |
| 196 | 196 |
| 197 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare); | 197 E max([int compare(E a, E b)]) => Collections.max(this, compare); |
| 198 | 198 |
| 199 List<E> toList() { | 199 List<E> toList() { |
| 200 return new List<E>.from(this); | 200 return new List<E>.from(this); |
| 201 } | 201 } |
| 202 | 202 |
| 203 Set<E> toSet() { | 203 Set<E> toSet() { |
| 204 return new Set<E>.from(this); | 204 return new Set<E>.from(this); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 Arrays.rangeCheck(this, start, length); | 259 Arrays.rangeCheck(this, start, length); |
| 260 List list = new List<E>(); | 260 List list = new List<E>(); |
| 261 list.length = length; | 261 list.length = length; |
| 262 Arrays.copy(this, start, list, 0, length); | 262 Arrays.copy(this, start, list, 0, length); |
| 263 return list; | 263 return list; |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Collection interface. | 266 // Collection interface. |
| 267 | 267 |
| 268 bool contains(E element) { | 268 bool contains(E element) { |
| 269 return IterableMixinWorkaround.contains(this, element); | 269 return Collections.contains(this, element); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void forEach(f(E element)) { | 272 void forEach(f(E element)) { |
| 273 IterableMixinWorkaround.forEach(this, f); | 273 Collections.forEach(this, f); |
| 274 } | 274 } |
| 275 | 275 |
| 276 List mappedBy(f(E element)) { | 276 List mappedBy(f(E element)) { |
| 277 return IterableMixinWorkaround.mappedByList(this, f); | 277 return new MappedList<E, dynamic>(this, f); |
| 278 } | 278 } |
| 279 | 279 |
| 280 String join([String separator]) { | 280 String join([String separator]) { |
| 281 return IterableMixinWorkaround.joinList(this, separator); | 281 return Collections.joinList(this, separator); |
| 282 } | 282 } |
| 283 | 283 |
| 284 reduce(initialValue, combine(previousValue, E element)) { | 284 reduce(initialValue, combine(previousValue, E element)) { |
| 285 return IterableMixinWorkaround.reduce(this, initialValue, combine); | 285 return Collections.reduce(this, initialValue, combine); |
| 286 } | 286 } |
| 287 | 287 |
| 288 Iterable<E> where(bool f(E element)) { | 288 Iterable<E> where(bool f(E element)) { |
| 289 return IterableMixinWorkaround.where(this, f); | 289 return new WhereIterable<E>(this, f); |
| 290 } | 290 } |
| 291 | 291 |
| 292 List<E> take(int n) { | 292 List<E> take(int n) { |
| 293 return IterableMixinWorkaround.takeList(this, n); | 293 return new ListView<E>(this, 0, n); |
| 294 } | 294 } |
| 295 | 295 |
| 296 Iterable<E> takeWhile(bool test(E value)) { | 296 Iterable<E> takeWhile(bool test(E value)) { |
| 297 return IterableMixinWorkaround.takeWhile(this, test); | 297 return new TakeWhileIterable<E>(this, test); |
| 298 } | 298 } |
| 299 | 299 |
| 300 List<E> skip(int n) { | 300 List<E> skip(int n) { |
| 301 return IterableMixinWorkaround.skipList(this, n); | 301 return new ListView<E>(this, n, null); |
| 302 } | 302 } |
| 303 | 303 |
| 304 Iterable<E> skipWhile(bool test(E value)) { | 304 Iterable<E> skipWhile(bool test(E value)) { |
| 305 return IterableMixinWorkaround.skipWhile(this, test); | 305 return new SkipWhileIterable<E>(this, test); |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool every(bool f(E element)) { | 308 bool every(bool f(E element)) { |
| 309 return IterableMixinWorkaround.every(this, f); | 309 return Collections.every(this, f); |
| 310 } | 310 } |
| 311 | 311 |
| 312 bool any(bool f(E element)) { | 312 bool any(bool f(E element)) { |
| 313 return IterableMixinWorkaround.any(this, f); | 313 return Collections.any(this, f); |
| 314 } | 314 } |
| 315 | 315 |
| 316 E firstMatching(bool test(E value), {E orElse()}) { | 316 E firstMatching(bool test(E value), {E orElse()}) { |
| 317 return IterableMixinWorkaround.firstMatching(this, test, orElse); | 317 return Collections.firstMatching(this, test, orElse); |
| 318 } | 318 } |
| 319 | 319 |
| 320 E lastMatching(bool test(E value), {E orElse()}) { | 320 E lastMatching(bool test(E value), {E orElse()}) { |
| 321 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); | 321 return Collections.lastMatchingInList(this, test, orElse); |
| 322 } | 322 } |
| 323 | 323 |
| 324 E singleMatching(bool test(E value)) { | 324 E singleMatching(bool test(E value)) { |
| 325 return IterableMixinWorkaround.singleMatching(this, test); | 325 return Collections.singleMatching(this, test); |
| 326 } | 326 } |
| 327 | 327 |
| 328 E elementAt(int index) { | 328 E elementAt(int index) { |
| 329 return this[index]; | 329 return this[index]; |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool get isEmpty { | 332 bool get isEmpty { |
| 333 return this.length == 0; | 333 return this.length == 0; |
| 334 } | 334 } |
| 335 | 335 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 if (length > 0) return this[length - 1]; | 393 if (length > 0) return this[length - 1]; |
| 394 throw new StateError("No elements"); | 394 throw new StateError("No elements"); |
| 395 } | 395 } |
| 396 | 396 |
| 397 E get single { | 397 E get single { |
| 398 if (length == 1) return this[0]; | 398 if (length == 1) return this[0]; |
| 399 if (length == 0) throw new StateError("No elements"); | 399 if (length == 0) throw new StateError("No elements"); |
| 400 throw new StateError("More than one element"); | 400 throw new StateError("More than one element"); |
| 401 } | 401 } |
| 402 | 402 |
| 403 E min([int compare(E a, E b)]) => IterableMixinWorkaround.min(this, compare); | 403 E min([int compare(E a, E b)]) => Collections.min(this, compare); |
| 404 | 404 |
| 405 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare); | 405 E max([int compare(E a, E b)]) => Collections.max(this, compare); |
| 406 | 406 |
| 407 List<E> toList() { | 407 List<E> toList() { |
| 408 return new List<E>.from(this); | 408 return new List<E>.from(this); |
| 409 } | 409 } |
| 410 | 410 |
| 411 Set<E> toSet() { | 411 Set<E> toSet() { |
| 412 return new Set<E>.from(this); | 412 return new Set<E>.from(this); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 435 } | 435 } |
| 436 _position = _length; | 436 _position = _length; |
| 437 _current = null; | 437 _current = null; |
| 438 return false; | 438 return false; |
| 439 } | 439 } |
| 440 | 440 |
| 441 E get current { | 441 E get current { |
| 442 return _current; | 442 return _current; |
| 443 } | 443 } |
| 444 } | 444 } |
| OLD | NEW |