Chromium Code Reviews| Index: runtime/lib/byte_array.dart |
| =================================================================== |
| --- runtime/lib/byte_array.dart (revision 7508) |
| +++ runtime/lib/byte_array.dart (working copy) |
| @@ -240,6 +240,49 @@ |
| abstract class _ByteArrayBase { |
| + |
| + // Methods implementing the Collection interface. |
| + |
| + void forEach(void f(element)) { |
| + var len = this.length; |
| + for (var i = 0; i < len; i++) { |
| + f(this[i]); |
| + } |
| + } |
| + |
| + Collection map(f(element)) { |
| + return Collections.map(this, |
| + new GrowableObjectArray.withCapacity(length), |
|
Anders Johnsen
2012/05/11 08:38:54
This could be end up slowing down some users code.
|
| + f); |
| + } |
| + |
| + Collection filter(bool f(element)) { |
| + return Collections.filter(this, new GrowableObjectArray(), f); |
|
Anders Johnsen
2012/05/11 08:38:54
Ditto.
|
| + } |
| + |
| + bool every(bool f(element)) { |
| + return Collections.every(this, f); |
| + } |
| + |
| + bool some(bool f(element)) { |
| + return Collections.some(this, f);; |
| + } |
| + |
| + bool isEmpty() { |
| + return this.length === 0; |
| + } |
| + |
| + int get length() { |
| + return _length(); |
| + } |
| + |
| + // Methods implementing the List interface. |
| + |
| + set length(newLength) { |
| + throw const UnsupportedOperationException( |
| + "Cannot resize a non-extendable array"); |
| + } |
| + |
| void add(value) { |
| throw const UnsupportedOperationException( |
| "Cannot add to a non-extendable array"); |
| @@ -255,30 +298,22 @@ |
| "Cannot add to a non-extendable array"); |
| } |
| - void clear() { |
| - throw const UnsupportedOperationException( |
| - "Cannot remove from a non-extendable array"); |
| + void sort(int compare(a, b)) { |
| + DualPivotQuicksort.sort(this, compare); |
| } |
| int indexOf(element, [int start = 0]) { |
| - for (int i = start; i < length; i++) { |
| - if (this[i] == element) return i; |
| - } |
| - return -1; |
| + return Arrays.indexOf(this, element, start, this.length); |
| } |
| - void insertRange(int start, int length, [initialValue]) { |
| - throw const UnsupportedOperationException( |
| - "Cannot add to a non-extendable array"); |
| + int lastIndexOf(element, [int start = null]) { |
| + if (start === null) start = length - 1; |
| + return Arrays.lastIndexOf(this, element, start); |
| } |
| - int get length() { |
| - return _length(); |
| - } |
| - |
| - set length(newLength) { |
| + void clear() { |
| throw const UnsupportedOperationException( |
| - "Cannot resize a non-extendable array"); |
| + "Cannot remove from a non-extendable array"); |
| } |
| int removeLast() { |
| @@ -286,11 +321,20 @@ |
| "Cannot remove from a non-extendable array"); |
| } |
| + last() { |
| + return this[length - 1]; |
| + } |
| + |
| void removeRange(int start, int length) { |
| throw const UnsupportedOperationException( |
| "Cannot remove from a non-extendable array"); |
| } |
| + void insertRange(int start, int length, [initialValue]) { |
| + throw const UnsupportedOperationException( |
| + "Cannot add to a non-extendable array"); |
| + } |
| + |
| ByteArray asByteArray([int start = 0, int length]) { |
| if (length === null) { |
| length = this.lengthInBytes(); |
| @@ -1647,6 +1691,49 @@ |
| class _ByteArrayViewBase { |
| + |
| + // Methods implementing the Collection interface. |
| + |
| + void forEach(void f(element)) { |
| + var len = this.length; |
| + for (var i = 0; i < len; i++) { |
| + f(this[i]); |
| + } |
| + } |
| + |
| + Collection map(f(element)) { |
| + return Collections.map(this, |
| + new GrowableObjectArray.withCapacity(length), |
| + f); |
| + } |
| + |
| + Collection filter(bool f(element)) { |
| + return Collections.filter(this, new GrowableObjectArray(), f); |
| + } |
| + |
| + bool every(bool f(element)) { |
| + return Collections.every(this, f); |
| + } |
| + |
| + bool some(bool f(element)) { |
| + return Collections.some(this, f);; |
| + } |
| + |
| + bool isEmpty() { |
| + return this.length === 0; |
| + } |
| + |
| + int get length() { |
| + return _length(); |
| + } |
| + |
| + // Methods implementing the List interface. |
| + |
| + set length(newLength) { |
| + throw const UnsupportedOperationException( |
| + "Cannot resize a non-extendable array"); |
| + } |
| + |
| void add(value) { |
| throw const UnsupportedOperationException( |
| "Cannot add to a non-extendable array"); |
| @@ -1662,19 +1749,22 @@ |
| "Cannot add to a non-extendable array"); |
| } |
| - void clear() { |
| - throw const UnsupportedOperationException( |
| - "Cannot remove from a non-extendable array"); |
| + void sort(int compare(a, b)) { |
| + DualPivotQuicksort.sort(this, compare); |
| } |
| - void insertRange(int start, int length, [initialValue]) { |
| - throw const UnsupportedOperationException( |
| - "Cannot add to a non-extendable array"); |
| + int indexOf(element, [int start = 0]) { |
| + return Arrays.indexOf(this, element, start, this.length); |
| } |
| - set length(int newLength) { |
| + int lastIndexOf(element, [int start = null]) { |
| + if (start === null) start = length - 1; |
| + return Arrays.lastIndexOf(this, element, start); |
| + } |
| + |
| + void clear() { |
| throw const UnsupportedOperationException( |
| - "Cannot resize a non-extendable array"); |
| + "Cannot remove from a non-extendable array"); |
| } |
| int removeLast() { |
| @@ -1682,10 +1772,19 @@ |
| "Cannot remove from a non-extendable array"); |
| } |
| + last() { |
| + return this[length - 1]; |
| + } |
| + |
| void removeRange(int start, int length) { |
| throw const UnsupportedOperationException( |
| "Cannot remove from a non-extendable array"); |
| } |
| + |
| + void insertRange(int start, int length, [initialValue]) { |
| + throw const UnsupportedOperationException( |
| + "Cannot add to a non-extendable array"); |
| + } |
| } |