Chromium Code Reviews| 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 ArrayFactory { | 5 class ArrayFactory { |
| 6 factory Array<E>.from(Iterable<E> other) { | 6 factory Array<E>.from(Iterable<E> other) { |
| 7 Array<E> array = new Array<E>(); | 7 Array<E> array = new Array<E>(); |
| 8 for (final e in other) { | 8 for (final e in other) { |
| 9 array.add(e); | 9 array.add(e); |
| 10 } | 10 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 } else { | 113 } else { |
| 114 return new VariableSizeArrayIterator<T>(this); | 114 return new VariableSizeArrayIterator<T>(this); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 T _indexOperator(int index) native; | 118 T _indexOperator(int index) native; |
| 119 void _indexAssignOperator(int index, T value) native; | 119 void _indexAssignOperator(int index, T value) native; |
| 120 int get length() native; | 120 int get length() native; |
| 121 void _setLength(int length) native; | 121 void _setLength(int length) native; |
| 122 void _add(T value) native; | 122 void _add(T value) native; |
| 123 void _splice(int start, int length) native; | |
| 123 | 124 |
| 124 void forEach(void f(T element)) { | 125 void forEach(void f(T element)) { |
| 125 Collections.forEach(this, f); | 126 Collections.forEach(this, f); |
| 126 } | 127 } |
| 127 | 128 |
| 128 Collection<T> filter(bool f(T element)) { | 129 Collection<T> filter(bool f(T element)) { |
| 129 return Collections.filter(this, new Array<T>(), f); | 130 return Collections.filter(this, new Array<T>(), f); |
| 130 } | 131 } |
| 131 | 132 |
| 132 bool every(bool f(T element)) { | 133 bool every(bool f(T element)) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 143 | 144 |
| 144 void sort(int compare(T a, T b)) { | 145 void sort(int compare(T a, T b)) { |
| 145 DualPivotQuicksort.sort(this, compare); | 146 DualPivotQuicksort.sort(this, compare); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void copyFrom(Array<Object> src, int srcStart, int dstStart, int count) { | 149 void copyFrom(Array<Object> src, int srcStart, int dstStart, int count) { |
| 149 Arrays.copy(src, srcStart, this, dstStart, count); | 150 Arrays.copy(src, srcStart, this, dstStart, count); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 153 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
| 154 if (_isFixed) { | |
|
Anton Muhin
2011/10/18 07:44:20
may we have this in Arrays? Ditto for removeRange
ngeoffray
2011/10/18 07:46:09
There is a 'rangeCheck' method in Arrays.
Anton Muhin
2011/10/18 08:54:46
Sorry, I meant the whole logic of methods. Even f
ngeoffray
2011/10/18 08:58:01
The _splice is really tight to the implementation,
Anton Muhin
2011/10/18 14:33:49
I believe yes, but didn't double check. Anyway, l
| |
| 155 throw const UnsupportedOperationException( | |
| 156 "Cannot remove range of a non-extendable array"); | |
| 157 } | |
| 158 if (length == 0) { | |
| 159 return; | |
| 160 } | |
| 161 if (length < 0) { | |
| 162 throw const IllegalArgumentException(); | |
| 163 } | |
| 153 Arrays.copy(from, startFrom, this, start, length); | 164 Arrays.copy(from, startFrom, this, start, length); |
| 154 } | 165 } |
| 155 | 166 |
| 156 void removeRange(int start, int length) { | 167 void removeRange(int start, int length) { |
| 157 throw const NotImplementedException(); | 168 if (_isFixed) { |
| 169 throw const UnsupportedOperationException( | |
| 170 "Cannot remove range of a non-extendable array"); | |
| 171 } | |
| 172 if (length == 0) { | |
| 173 return; | |
| 174 } | |
| 175 if (length < 0) { | |
| 176 throw const IllegalArgumentException(); | |
| 177 } | |
| 178 if (start < 0 || start >= this.length) { | |
| 179 throw new IndexOutOfRangeException(start); | |
| 180 } | |
| 181 if (start + length > this.length) { | |
| 182 throw new IndexOutOfRangeException(start + length); | |
| 183 } | |
| 184 _splice(start, length); | |
| 158 } | 185 } |
| 159 | 186 |
| 160 void insertRange(int start, int length, [T initialValue = null]) { | 187 void insertRange(int start, int length, [T initialValue = null]) { |
| 161 throw const NotImplementedException(); | 188 throw const NotImplementedException(); |
| 162 } | 189 } |
| 163 | 190 |
| 164 List<T> getRange(int start, int length) { | 191 List<T> getRange(int start, int length) { |
| 165 throw const NotImplementedException(); | 192 throw const NotImplementedException(); |
| 166 } | 193 } |
| 167 | 194 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 } | 303 } |
| 277 | 304 |
| 278 static Array _newArray(int len) native { | 305 static Array _newArray(int len) native { |
| 279 return new Array(len); | 306 return new Array(len); |
| 280 } | 307 } |
| 281 | 308 |
| 282 static void _throwIndexOutOfRangeException(int index) native { | 309 static void _throwIndexOutOfRangeException(int index) native { |
| 283 throw new IndexOutOfRangeException(index); | 310 throw new IndexOutOfRangeException(index); |
| 284 } | 311 } |
| 285 } | 312 } |
| OLD | NEW |