Chromium Code Reviews| 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 interface ByteArray extends List default _InternalByteArray { | 5 interface ByteArray default _Uint8Array { // TODO |
|
Ivan Posva
2012/05/02 08:19:17
Please document what is there TODO?
cshapiro
2012/05/03 04:01:50
Right. These TODO statements mark changes that sh
| |
| 6 ByteArray(int length); | 6 ByteArray(int length); // TODO |
| 7 | 7 |
| 8 int get length(); | 8 int lengthInBytes(); |
| 9 | |
| 10 ByteArray subByteArray([int start, int length]); | |
| 9 | 11 |
| 10 int getInt8(int byteOffset); | 12 int getInt8(int byteOffset); |
| 11 | 13 |
| 12 void setInt8(int byteOffset, int value); | 14 void setInt8(int byteOffset, int value); |
| 13 | 15 |
| 14 int getUint8(int byteOffset); | 16 int getUint8(int byteOffset); |
| 15 | 17 |
| 16 void setUint8(int byteOffset, int value); | 18 void setUint8(int byteOffset, int value); |
| 17 | 19 |
| 18 int getInt16(int byteOffset); | 20 int getInt16(int byteOffset); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 42 double getFloat32(int byteOffset); | 44 double getFloat32(int byteOffset); |
| 43 | 45 |
| 44 void setFloat32(int byteOffset, double value); | 46 void setFloat32(int byteOffset, double value); |
| 45 | 47 |
| 46 double getFloat64(int byteOffset); | 48 double getFloat64(int byteOffset); |
| 47 | 49 |
| 48 void setFloat64(int byteOffset, double value); | 50 void setFloat64(int byteOffset, double value); |
| 49 } | 51 } |
| 50 | 52 |
| 51 | 53 |
| 52 class _ByteArrayBase { | 54 interface ByteArrayViewable { |
|
Ivan Posva
2012/05/02 08:19:17
I am not sure I understand this interface and its
cshapiro
2012/05/03 04:01:50
This interface contains methods for viewing a type
| |
| 53 | 55 int bytesPerElement(); |
| 54 // Iterable interface | 56 |
| 55 | 57 int lengthInBytes(); |
| 56 Iterator iterator() { | 58 |
| 57 return new _ByteArrayIterator(this); | 59 ByteArray asByteArray([int offsetInBytes, int lengthInBytes]); |
| 58 } | 60 } |
| 59 | 61 |
| 60 // Collection interface | 62 |
| 63 interface Int8Array extends List<int>, ByteArrayViewable default _Int8Array { | |
| 64 Int8Array(int length); | |
| 65 Int8Array.view(ByteArray array, [int start, int length]); | |
| 66 } | |
| 67 | |
| 68 | |
| 69 interface Uint8Array extends List<int>, ByteArrayViewable default _Uint8Array { | |
| 70 Uint8Array(int length); | |
| 71 Uint8Array.view(ByteArray array, [int start, int length]); | |
| 72 } | |
| 73 | |
| 74 | |
| 75 interface Int16Array extends List<int>, ByteArrayViewable default _Int16Array { | |
| 76 Int16Array(int length); | |
| 77 Int16Array.view(ByteArray array, [int start, int length]); | |
| 78 } | |
| 79 | |
| 80 | |
| 81 interface Uint16Array extends List<int>, ByteArrayViewable default _Uint16Array { | |
| 82 Uint16Array(int length); | |
| 83 Uint16Array.view(ByteArray array, [int start, int length]); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 interface Int32Array extends List<int>, ByteArrayViewable default _Int32Array { | |
| 88 Int32Array(int length); | |
| 89 Int32Array.view(ByteArray array, [int start, int length]); | |
| 90 } | |
| 91 | |
| 92 | |
| 93 interface Uint32Array extends List<int>, ByteArrayViewable default _Uint32Array { | |
| 94 Uint32Array(int length); | |
| 95 Uint32Array.view(ByteArray array, [int start, int length]); | |
| 96 | |
| 97 } | |
| 98 | |
| 99 | |
| 100 interface Int64Array extends List<int>, ByteArrayViewable default _Int64Array { | |
| 101 Int64Array(int length); | |
| 102 Int64Array.view(ByteArray array, [int start, int length]); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 interface Uint64Array extends List<int>, ByteArrayViewable default _Uint64Array { | |
| 107 Uint64Array(int length); | |
| 108 Uint64Array.view(ByteArray array, [int start, int length]); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 interface Float32Array extends List<double>, ByteArrayViewable default _Float32A rray { | |
| 113 Float32Array(int length); | |
| 114 Float32Array.view(ByteArray array, [int start, int length]); | |
| 115 } | |
| 116 | |
| 117 | |
| 118 interface Float64Array extends List<double>, ByteArrayViewable default _Float64A rray { | |
| 119 Float64Array(int length); | |
| 120 Float64Array.view(ByteArray array, [int start, int length]); | |
| 121 } | |
| 122 | |
| 123 | |
| 124 class _ByteArray { | |
| 125 void add(int value) { | |
| 126 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
|
Ivan Posva
2012/05/02 08:19:17
Long line and many below.
cshapiro
2012/05/03 04:01:50
Wrapped. Done.
| |
| 127 } | |
| 128 | |
| 129 void addLast(int value) { | |
|
Ivan Posva
2012/05/02 08:19:17
The type here should be parameterized with E, wher
cshapiro
2012/05/03 04:01:50
Hmm...
The _Float64Array class extends _ByteArray
Ivan Posva
2012/05/03 05:53:19
I think that is fine for now. Another option would
| |
| 130 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 131 } | |
| 132 | |
| 133 void addAll(Collection<int> value) { | |
| 134 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 135 } | |
| 136 | |
| 137 void clear() { | |
| 138 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 139 } | |
| 140 | |
| 141 void insertRange(int start, int length, [initialValue]) { | |
| 142 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 143 } | |
| 61 | 144 |
| 62 int get length() { | 145 int get length() { |
| 63 return _length(); | 146 return _length(); |
| 64 } | 147 } |
| 65 | 148 |
| 66 bool every(bool f(int element)) { | 149 set length(int newLength) { |
| 67 return Collections.every(this, f); | 150 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); |
| 68 } | 151 } |
| 69 | 152 |
| 70 Collection map(f(int element)) { | 153 int removeLast() { |
| 71 return Collections.map(this, | 154 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 72 new GrowableObjectArray.withCapacity(length), | 155 } |
| 73 f); | 156 |
| 74 } | 157 void removeRange(int start, int length) { |
| 75 | 158 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 76 Collection filter(bool f(int element)) { | 159 } |
| 77 return Collections.filter(this, new GrowableObjectArray(), f); | 160 |
| 78 } | 161 ByteArray asByteArray([int offsetInBytes = 0, int lengthInBytes]) { |
| 79 | 162 if (lengthInBytes === null) { |
| 80 void forEach(f(int element)) { | 163 lengthInBytes = this.lengthInBytes(); |
| 81 Collections.forEach(this, f); | 164 } |
| 82 } | 165 return new _ByteArrayView(this, offsetInBytes, lengthInBytes); |
| 83 | 166 } |
| 84 bool isEmpty() { | 167 |
| 85 return this.length === 0; | 168 int _length() native "ByteArray_getLength"; |
| 86 } | 169 |
| 87 | 170 void _setRange(int startInBytes, int lengthInBytes, |
| 88 bool some(bool f(int element)) { | 171 _ByteArray from, int startFromInBytes) native "ByteArray_setRan ge"; |
|
Ivan Posva
2012/05/02 08:19:17
Long line.
cshapiro
2012/05/03 04:01:50
All long lines have now been wrapped.
As an aside
| |
| 89 return Collections.some(this, f); | 172 |
| 90 } | 173 int _getInt8(int byteOffset) native "ByteArray_getInt8"; |
| 91 | 174 void _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; |
| 92 // List interface | 175 |
| 93 | 176 int _getUint8(int byteOffset) native "ByteArray_getUint8"; |
| 94 int operator[](int index) { | 177 void _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; |
| 95 return getUint8(index); | 178 |
| 179 int _getInt16(int byteOffset) native "ByteArray_getInt16"; | |
| 180 void _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; | |
| 181 | |
| 182 int _getUint16(int byteOffset) native "ByteArray_getUint16"; | |
| 183 void _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; | |
| 184 | |
| 185 int _getInt32(int byteOffset) native "ByteArray_getInt32"; | |
| 186 void _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; | |
| 187 | |
| 188 int _getUint32(int byteOffset) native "ByteArray_getUint32"; | |
| 189 void _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; | |
| 190 | |
| 191 int _getInt64(int byteOffset) native "ByteArray_getInt64"; | |
| 192 void _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; | |
| 193 | |
| 194 int _getUint64(int byteOffset) native "ByteArray_getUint64"; | |
| 195 void _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; | |
| 196 | |
| 197 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; | |
| 198 void _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; | |
| 199 | |
| 200 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; | |
| 201 void _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; | |
| 202 } | |
| 203 | |
| 204 | |
| 205 int _toInt(int value, int mask) { | |
| 206 value &= mask; | |
| 207 if (value > (mask >> 1)) value -= mask + 1; | |
| 208 return value; | |
| 209 } | |
| 210 | |
| 211 int _toInt8(int value) { | |
| 212 return _toInt(value, 0xFF); | |
| 213 } | |
| 214 int _toUint8(int value) { | |
| 215 return value & 0xFF; | |
| 216 } | |
| 217 | |
| 218 | |
| 219 int _toInt16(int value) { | |
| 220 return _toInt(value, 0xFFFF); | |
| 221 } | |
| 222 int _toUint16(int value) { | |
| 223 return value & 0xFFFF; | |
| 224 } | |
| 225 | |
| 226 | |
| 227 int _toInt32(int value) { | |
| 228 return _toInt(value, 0xFFFFFFFF); | |
| 229 } | |
| 230 int _toUint32(int value) { | |
| 231 return value & 0xFFFFFFFF; | |
| 232 } | |
| 233 | |
| 234 | |
| 235 int _toInt64(int value) { | |
| 236 return _toInt(value, 0xFFFFFFFFFFFFFFFF); | |
| 237 } | |
| 238 int _toUint64(int value) { | |
| 239 return value & 0xFFFFFFFFFFFFFFFF; | |
| 240 } | |
| 241 | |
| 242 | |
| 243 class _Int8Array extends _ByteArray implements Int8Array { | |
| 244 factory _Int8Array(int length) { | |
| 245 return _new(length); | |
| 246 } | |
| 247 | |
| 248 factory _Int8Array.view(ByteArray array, [int start = 0, int length]) { | |
| 249 if (length === null) { | |
| 250 length = array.lengthInBytes(); | |
| 251 } | |
| 252 return new _Int8ArrayView(array, start, length); | |
| 253 } | |
| 254 | |
| 255 int operator[](int index) { | |
| 256 return _getIndexed(index); | |
| 96 } | 257 } |
| 97 | 258 |
| 98 void operator[]=(int index, int value) { | 259 void operator[]=(int index, int value) { |
| 99 setUint8(index, value); | 260 _setIndexed(index, _toInt8(value)); |
| 100 } | 261 } |
| 101 | 262 |
| 102 void set length(int newLength) { | 263 Iterator<int> iterator() { |
| 103 throw const UnsupportedOperationException("Cannot add to a byte array"); | 264 return new _ByteArrayIterator<int>(this); |
| 104 } | 265 } |
| 105 | 266 |
| 106 void add(int element) { | 267 List<int> getRange(int start, int length) { |
| 107 throw const UnsupportedOperationException("Cannot add to a byte array"); | 268 Arrays.rangeCheck(this, start, length); |
| 108 } | 269 _Int8Array result = _new(length); |
| 109 | 270 result.setRange(0, length, this, start); |
| 110 void addLast(int element) { | 271 return result; |
| 111 add(element); | 272 } |
| 112 } | 273 |
| 113 | 274 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 114 void addAll(Collection elements) { | 275 if (from is _Int8Array) { |
| 115 throw const UnsupportedOperationException("Cannot add to a byte array"); | 276 int startInBytes = start * bytesPerElement(); |
| 116 } | 277 int lengthInBytes = length * bytesPerElement(); |
| 117 | 278 int startFromInBytes = startFrom * bytesPerElement(); |
| 118 void sort(int compare(int a, b)) { | 279 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 119 DualPivotQuicksort.sort(this, compare); | |
| 120 } | |
| 121 | |
| 122 int indexOf(int element, [int start = 0]) { | |
| 123 return Arrays.indexOf(this, element, start, this.length); | |
| 124 } | |
| 125 | |
| 126 int lastIndexOf(int element, [int start = null]) { | |
| 127 if (start === null) start = length - 1; | |
| 128 return Arrays.lastIndexOf(this, element, start); | |
| 129 } | |
| 130 | |
| 131 void clear() { | |
| 132 throw const UnsupportedOperationException("Cannot clear a byte array"); | |
| 133 } | |
| 134 | |
| 135 int removeLast() { | |
| 136 throw const UnsupportedOperationException( | |
| 137 "Cannot remove from a byte array"); | |
| 138 } | |
| 139 | |
| 140 int last() { | |
| 141 return this[length - 1]; | |
| 142 } | |
| 143 | |
| 144 String toString() { | |
| 145 return Collections.collectionToString(this); | |
| 146 } | |
| 147 | |
| 148 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 149 if (length < 0) { | |
| 150 throw new IllegalArgumentException("negative length $length"); | |
| 151 } | |
| 152 if (from is ByteArray) { | |
| 153 _setRange(start, length, from, startFrom); | |
| 154 } else { | 280 } else { |
| 155 Arrays.copy(from, startFrom, this, start, length); | 281 Arrays.copy(from, startFrom, this, start, length); |
| 156 } | 282 } |
| 157 } | 283 } |
| 158 | 284 |
| 159 List getRange(int start, int length) { | 285 String toString() { |
| 160 if (length == 0) return []; | 286 return Collections.collectionToString(this); |
| 161 Arrays.rangeCheck(this, start, length); | 287 } |
| 162 ByteArray list = new ByteArray(length); | 288 |
| 163 list._setRange(0, length, this, start); | 289 int bytesPerElement() { |
| 164 return list; | 290 return 1; |
| 165 } | 291 } |
| 166 | 292 |
| 167 // Implementation | 293 int lengthInBytes() { |
| 168 | 294 return _length() * bytesPerElement(); |
| 169 static final int _UINT8_MAX = (1 << 8) - 1; | 295 } |
| 170 static final int _UINT16_MAX = (1 << 16) - 1; | 296 |
| 171 static final int _UINT32_MAX = (1 << 32) - 1; | 297 static _Int8Array _new(int length) native "Int8Array_new"; |
| 172 static final int _UINT64_MAX = (1 << 64) - 1; | 298 |
| 173 | 299 int _getIndexed(int index) native "Int8Array_getIndexed"; |
| 174 int _toInt(int value, int mask) { | 300 |
| 175 int result = value & mask; | 301 void _setIndexed(int index, int value) native "Int8Array_setIndexed"; |
| 176 return result > (mask >> 1) ? (result - mask) : result; | 302 } |
| 177 } | 303 |
| 178 | 304 |
| 179 int _toInt8(int value) { | 305 class _Uint8Array extends _ByteArray implements Uint8Array { |
| 180 return _toInt(value, _UINT8_MAX); | 306 factory _Uint8Array(int length) { |
| 181 } | 307 return _new(length); |
| 182 | 308 } |
| 183 int _toUint8(int value) { | 309 |
| 184 return value & _UINT8_MAX; | 310 factory _Uint8Array.view(ByteArray array, [int start = 0, int length]) { |
| 185 } | 311 if (length === null) { |
| 186 | 312 length = array.lengthInBytes(); |
| 187 int _toInt16(int value) { | 313 } |
| 188 return _toInt(value, _UINT16_MAX); | 314 return new _Uint8ArrayView(array, start, length); |
| 189 } | 315 } |
| 190 | 316 |
| 191 int _toUint16(int value) { | 317 factory ByteArray(int length) { return _new(length); } // TODO |
| 192 return value & _UINT16_MAX; | 318 |
| 193 } | 319 int operator[](int index) { |
| 194 | 320 return _getIndexed(index); |
| 195 int _toInt32(int value) { | 321 } |
| 196 return _toInt(value, _UINT32_MAX); | 322 |
| 197 } | 323 void operator[]=(int index, int value) { |
| 198 | 324 _setIndexed(index, _toUint8(value)); |
| 199 int _toUint32(int value) { | 325 } |
| 200 return value & _UINT32_MAX; | 326 |
| 201 } | 327 Iterator<int> iterator() { |
| 202 | 328 return new _ByteArrayIterator<int>(this); |
| 203 int _toInt64(int value) { | 329 } |
| 204 return _toInt(value, _UINT64_MAX); | 330 |
| 205 } | 331 List<int> getRange(int start, int length) { |
| 206 | 332 Arrays.rangeCheck(this, start, length); |
| 207 int _toUint64(int value) { | 333 _Uint8Array result = _new(length); |
| 208 return value & _UINT64_MAX; | 334 result.setRange(0, length, this, start); |
| 209 } | 335 return result; |
| 210 | 336 } |
| 211 int _length() native "ByteArray_getLength"; | 337 |
| 212 | 338 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 213 void _setRange(int start, int length, ByteArray from, int startFrom) | 339 if (from is _Uint8Array) { |
| 214 native "ByteArray_setRange"; | 340 int startInBytes = start * bytesPerElement(); |
| 215 } | 341 int lengthInBytes = length * bytesPerElement(); |
| 216 | 342 int startFromInBytes = startFrom * bytesPerElement(); |
| 217 | 343 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); |
| 218 class _ByteArrayIterator implements Iterator { | 344 } else { |
| 219 _ByteArrayIterator(List byteArray) | 345 Arrays.copy(from, startFrom, this, start, length); |
| 220 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { | 346 } |
| 221 assert(byteArray is ByteArray); | 347 } |
| 348 | |
| 349 String toString() { | |
| 350 return Collections.collectionToString(this); | |
| 351 } | |
| 352 | |
| 353 int bytesPerElement() { | |
| 354 return 1; | |
| 355 } | |
| 356 | |
| 357 int lengthInBytes() { | |
| 358 return _length() * bytesPerElement(); | |
| 359 } | |
| 360 | |
| 361 static _Uint8Array _new(int length) native "Uint8Array_new"; | |
| 362 | |
| 363 int _getIndexed(int index) native "Uint8Array_getIndexed"; | |
| 364 | |
| 365 void _setIndexed(int index, int value) native "Uint8Array_setIndexed"; | |
| 366 } | |
| 367 | |
| 368 | |
| 369 class _Int16Array extends _ByteArray implements Int16Array { | |
| 370 factory _Int16Array(int length) { | |
| 371 return _new(length); | |
| 372 } | |
| 373 | |
| 374 factory _Int16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 375 if (length === null) { | |
| 376 length = (array.lengthInBytes() - start) ~/ 2; | |
| 377 } | |
| 378 return new _Int16ArrayView(array, start, length); | |
| 379 } | |
| 380 | |
| 381 int operator[](int index) { | |
| 382 return _getIndexed(index); | |
| 383 } | |
| 384 | |
| 385 void operator[]=(int index, int value) { | |
| 386 _setIndexed(index, _toInt16(value)); | |
| 387 } | |
| 388 | |
| 389 Iterator<int> iterator() { | |
| 390 return new _ByteArrayIterator<int>(this); | |
| 391 } | |
| 392 | |
| 393 List<int> getRange(int start, int length) { | |
| 394 Arrays.rangeCheck(this, start, length); | |
| 395 _Int16Array result = _new(length); | |
| 396 result.setRange(0, length, this, start); | |
| 397 return result; | |
| 398 } | |
| 399 | |
| 400 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 401 if (from is _Int16Array) { | |
| 402 int startInBytes = start * bytesPerElement(); | |
| 403 int lengthInBytes = length * bytesPerElement(); | |
| 404 int startFromInBytes = startFrom * bytesPerElement(); | |
| 405 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 406 } else { | |
| 407 Arrays.copy(from, startFrom, this, start, length); | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 String toString() { | |
| 412 return Collections.collectionToString(this); | |
| 413 } | |
| 414 | |
| 415 int bytesPerElement() { | |
| 416 return 2; | |
| 417 } | |
| 418 | |
| 419 int lengthInBytes() { | |
| 420 return _length() * bytesPerElement(); | |
| 421 } | |
| 422 | |
| 423 static _Int16Array _new(int length) native "Int16Array_new"; | |
| 424 | |
| 425 int _getIndexed(int index) native "Int16Array_getIndexed"; | |
| 426 | |
| 427 void _setIndexed(int index, int value) native "Int16Array_setIndexed"; | |
| 428 } | |
| 429 | |
| 430 | |
| 431 class _Uint16Array extends _ByteArray implements Uint16Array { | |
| 432 factory _Uint16Array(int length) { | |
| 433 return _new(length); | |
| 434 } | |
| 435 | |
| 436 factory _Uint16Array.view(ByteArray array, [int start = 0, int length]) { | |
| 437 if (length === null) { | |
| 438 length = (array.lengthInBytes() - start) ~/ 2; | |
| 439 } | |
| 440 return new _Uint16ArrayView(array, start, length); | |
| 441 } | |
| 442 | |
| 443 int operator[](int index) { | |
| 444 return _getIndexed(index); | |
| 445 } | |
| 446 | |
| 447 void operator[]=(int index, int value) { | |
| 448 _setIndexed(index, _toUint16(value)); | |
| 449 } | |
| 450 | |
| 451 Iterator<int> iterator() { | |
| 452 return new _ByteArrayIterator<int>(this); | |
| 453 } | |
| 454 | |
| 455 List<int> getRange(int start, int length) { | |
| 456 Arrays.rangeCheck(this, start, length); | |
| 457 _Uint16Array result = _new(length); | |
| 458 result.setRange(0, length, this, start); | |
| 459 return result; | |
| 460 } | |
| 461 | |
| 462 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 463 if (from is _Uint16Array) { | |
| 464 int startInBytes = start * bytesPerElement(); | |
| 465 int lengthInBytes = length * bytesPerElement(); | |
| 466 int startFromInBytes = startFrom * bytesPerElement(); | |
| 467 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 468 } else { | |
| 469 Arrays.copy(from, startFrom, this, start, length); | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 String toString() { | |
| 474 return Collections.collectionToString(this); | |
| 475 } | |
| 476 | |
| 477 int bytesPerElement() { | |
| 478 return 2; | |
| 479 } | |
| 480 | |
| 481 int lengthInBytes() { | |
| 482 return _length() * bytesPerElement(); | |
| 483 } | |
| 484 | |
| 485 static _Uint16Array _new(int length) native "Uint16Array_new"; | |
| 486 | |
| 487 int _getIndexed(int index) native "Uint16Array_getIndexed"; | |
| 488 | |
| 489 void _setIndexed(int index, int value) native "Uint16Array_setIndexed"; | |
| 490 } | |
| 491 | |
| 492 | |
| 493 class _Int32Array extends _ByteArray implements Int32Array { | |
| 494 factory _Int32Array(int length) { | |
| 495 return _new(length); | |
| 496 } | |
| 497 | |
| 498 factory _Int32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 499 if (length === null) { | |
| 500 length = (array.lengthInBytes() - start) ~/ 4; | |
| 501 } | |
| 502 return new _Int32ArrayView(array, start, length); | |
| 503 } | |
| 504 | |
| 505 int operator[](int index) { | |
| 506 return _getIndexed(index); | |
| 507 } | |
| 508 | |
| 509 void operator[]=(int index, int value) { | |
| 510 _setIndexed(index, _toInt32(value)); | |
| 511 } | |
| 512 | |
| 513 Iterator<int> iterator() { | |
| 514 return new _ByteArrayIterator<int>(this); | |
| 515 } | |
| 516 | |
| 517 List<int> getRange(int start, int length) { | |
| 518 Arrays.rangeCheck(this, start, length); | |
| 519 _Int32Array result = _new(length); | |
| 520 result.setRange(0, length, this, start); | |
| 521 return result; | |
| 522 } | |
| 523 | |
| 524 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 525 if (from is _Int32Array) { | |
| 526 int startInBytes = start * bytesPerElement(); | |
| 527 int lengthInBytes = length * bytesPerElement(); | |
| 528 int startFromInBytes = startFrom * bytesPerElement(); | |
| 529 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 530 } else { | |
| 531 Arrays.copy(from, startFrom, this, start, length); | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 String toString() { | |
| 536 return Collections.collectionToString(this); | |
| 537 } | |
| 538 | |
| 539 int bytesPerElement() { | |
| 540 return 4; | |
| 541 } | |
| 542 | |
| 543 int lengthInBytes() { | |
| 544 return _length() * bytesPerElement(); | |
| 545 } | |
| 546 | |
| 547 static _Int32Array _new(int length) native "Int32Array_new"; | |
| 548 | |
| 549 int _getIndexed(int index) native "Int32Array_getIndexed"; | |
| 550 | |
| 551 void _setIndexed(int index, int value) native "Int32Array_setIndexed"; | |
| 552 } | |
| 553 | |
| 554 | |
| 555 class _Uint32Array extends _ByteArray implements Uint32Array { | |
| 556 factory _Uint32Array(int length) { | |
| 557 return _new(length); | |
| 558 } | |
| 559 | |
| 560 factory _Uint32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 561 if (length === null) { | |
| 562 length = (array.lengthInBytes() - start) ~/ 4; | |
| 563 } | |
| 564 return new _Uint32ArrayView(array, start, length); | |
| 565 } | |
| 566 | |
| 567 int operator[](int index) { | |
| 568 return _getIndexed(index); | |
| 569 } | |
| 570 | |
| 571 void operator[]=(int index, int value) { | |
| 572 _setIndexed(index, _toUint32(value)); | |
| 573 } | |
| 574 | |
| 575 Iterator<int> iterator() { | |
| 576 return new _ByteArrayIterator<int>(this); | |
| 577 } | |
| 578 | |
| 579 List<int> getRange(int start, int length) { | |
| 580 Arrays.rangeCheck(this, start, length); | |
| 581 _Uint32Array result = _new(length); | |
| 582 result.setRange(0, length, this, start); | |
| 583 return result; | |
| 584 } | |
| 585 | |
| 586 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 587 if (from is _Uint32Array) { | |
| 588 int startInBytes = start * bytesPerElement(); | |
| 589 int lengthInBytes = length * bytesPerElement(); | |
| 590 int startFromInBytes = startFrom * bytesPerElement(); | |
| 591 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 592 } else { | |
| 593 Arrays.copy(from, startFrom, this, start, length); | |
| 594 } | |
| 595 } | |
| 596 | |
| 597 String toString() { | |
| 598 return Collections.collectionToString(this); | |
| 599 } | |
| 600 | |
| 601 int bytesPerElement() { | |
| 602 return 4; | |
| 603 } | |
| 604 | |
| 605 int lengthInBytes() { | |
| 606 return _length() * bytesPerElement(); | |
| 607 } | |
| 608 | |
| 609 static _Uint32Array _new(int length) native "Uint32Array_new"; | |
| 610 | |
| 611 int _getIndexed(int index) native "Uint32Array_getIndexed"; | |
| 612 | |
| 613 void _setIndexed(int index, int value) native "Uint32Array_setIndexed"; | |
| 614 } | |
| 615 | |
| 616 | |
| 617 class _Int64Array extends _ByteArray implements Int64Array { | |
| 618 factory _Int64Array(int length) { | |
| 619 return _new(length); | |
| 620 } | |
| 621 | |
| 622 factory _Int64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 623 if (length === null) { | |
| 624 length = (array.lengthInBytes() - start) ~/ 8; | |
| 625 } | |
| 626 return new _Int64ArrayView(array, start, length); | |
| 627 } | |
| 628 | |
| 629 int operator[](int index) { | |
| 630 return _getIndexed(index); | |
| 631 } | |
| 632 | |
| 633 void operator[]=(int index, int value) { | |
| 634 _setIndexed(index, _toInt64(value)); | |
| 635 } | |
| 636 | |
| 637 Iterator<int> iterator() { | |
| 638 return new _ByteArrayIterator<int>(this); | |
| 639 } | |
| 640 | |
| 641 List<int> getRange(int start, int length) { | |
| 642 Arrays.rangeCheck(this, start, length); | |
| 643 _Int64Array result = _new(length); | |
| 644 result.setRange(0, length, this, start); | |
| 645 return result; | |
| 646 } | |
| 647 | |
| 648 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 649 if (from is _Int64Array) { | |
| 650 int startInBytes = start * bytesPerElement(); | |
| 651 int lengthInBytes = length * bytesPerElement(); | |
| 652 int startFromInBytes = startFrom * bytesPerElement(); | |
| 653 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 654 } else { | |
| 655 Arrays.copy(from, startFrom, this, start, length); | |
| 656 } | |
| 657 } | |
| 658 | |
| 659 String toString() { | |
| 660 return Collections.collectionToString(this); | |
| 661 } | |
| 662 | |
| 663 int bytesPerElement() { | |
| 664 return 8; | |
| 665 } | |
| 666 | |
| 667 int lengthInBytes() { | |
| 668 return _length() * bytesPerElement(); | |
| 669 } | |
| 670 | |
| 671 static _Int64Array _new(int length) native "Int64Array_new"; | |
| 672 | |
| 673 int _getIndexed(int index) native "Int64Array_getIndexed"; | |
| 674 | |
| 675 void _setIndexed(int index, int value) native "Int64Array_setIndexed"; | |
| 676 } | |
| 677 | |
| 678 | |
| 679 class _Uint64Array extends _ByteArray implements Uint64Array { | |
| 680 factory _Uint64Array(int length) { | |
| 681 return _new(length); | |
| 682 } | |
| 683 | |
| 684 factory _Uint64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 685 if (length === null) { | |
| 686 length = (array.lengthInBytes() - start) ~/ 8; | |
| 687 } | |
| 688 return new _Uint64ArrayView(array, start, length); | |
| 689 } | |
| 690 | |
| 691 int operator[](int index) { | |
| 692 return _getIndexed(index); | |
| 693 } | |
| 694 | |
| 695 void operator[]=(int index, int value) { | |
| 696 _setIndexed(index, _toUint64(value)); | |
| 697 } | |
| 698 | |
| 699 Iterator<int> iterator() { | |
| 700 return new _ByteArrayIterator<int>(this); | |
| 701 } | |
| 702 | |
| 703 List<int> getRange(int start, int length) { | |
| 704 Arrays.rangeCheck(this, start, length); | |
| 705 _Uint64Array result = _new(length); | |
| 706 result.setRange(0, length, this, start); | |
| 707 return result; | |
| 708 } | |
| 709 | |
| 710 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 711 if (from is _Uint64Array) { | |
| 712 int startInBytes = start * bytesPerElement(); | |
| 713 int lengthInBytes = length * bytesPerElement(); | |
| 714 int startFromInBytes = startFrom * bytesPerElement(); | |
| 715 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 716 } else { | |
| 717 Arrays.copy(from, startFrom, this, start, length); | |
| 718 } | |
| 719 } | |
| 720 | |
| 721 String toString() { | |
| 722 return Collections.collectionToString(this); | |
| 723 } | |
| 724 | |
| 725 int bytesPerElement() { | |
| 726 return 8; | |
| 727 } | |
| 728 | |
| 729 int lengthInBytes() { | |
| 730 return _length() * bytesPerElement(); | |
| 731 } | |
| 732 | |
| 733 static _Uint64Array _new(int length) native "Uint64Array_new"; | |
| 734 | |
| 735 int _getIndexed(int index) native "Uint64Array_getIndexed"; | |
| 736 | |
| 737 void _setIndexed(int index, int value) native "Uint64Array_setIndexed"; | |
| 738 } | |
| 739 | |
| 740 | |
| 741 class _Float32Array extends _ByteArray implements Float32Array { | |
| 742 factory _Float32Array(int length) { | |
| 743 return _new(length); | |
| 744 } | |
| 745 | |
| 746 factory _Float32Array.view(ByteArray array, [int start = 0, int length]) { | |
| 747 if (length === null) { | |
| 748 length = (array.lengthInBytes() - start) ~/ 4; | |
| 749 } | |
| 750 return new _Float32ArrayView(array, start, length); | |
| 751 } | |
| 752 | |
| 753 double operator[](int index) { | |
| 754 return _getIndexed(index); | |
| 755 } | |
| 756 | |
| 757 void operator[]=(int index, double value) { | |
| 758 _setIndexed(index, value); | |
| 759 } | |
| 760 | |
| 761 Iterator<double> iterator() { | |
| 762 return new _ByteArrayIterator<double>(this); | |
| 763 } | |
| 764 | |
| 765 List<double> getRange(int start, int length) { | |
| 766 Arrays.rangeCheck(this, start, length); | |
| 767 _Float32Array result = _new(length); | |
| 768 result.setRange(0, length, this, start); | |
| 769 return result; | |
| 770 } | |
| 771 | |
| 772 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 773 if (from is _Float32Array) { | |
| 774 int startInBytes = start * _bytesPerElement; | |
| 775 int lengthInBytes = length * _bytesPerElement; | |
| 776 int startFromInBytes = startFrom * _bytesPerElement; | |
| 777 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 778 } else { | |
| 779 Arrays.copy(from, startFrom, this, start, length); | |
| 780 } | |
| 781 } | |
| 782 | |
| 783 String toString() { | |
| 784 return Collections.collectionToString(this); | |
| 785 } | |
| 786 | |
| 787 int bytesPerElement() { | |
| 788 return _bytesPerElement; | |
| 789 } | |
| 790 | |
| 791 int lengthInBytes() { | |
| 792 return _length() * _bytesPerElement; | |
| 793 } | |
| 794 | |
| 795 static final int _bytesPerElement = 4; | |
| 796 | |
| 797 static _Float32Array _new(int length) native "Float32Array_new"; | |
| 798 | |
| 799 int _getIndexed(int index) native "Float32Array_getIndexed"; | |
| 800 | |
| 801 void _setIndexed(int index, double value) native "Float32Array_setIndexed"; | |
| 802 } | |
| 803 | |
| 804 | |
| 805 class _Float64Array extends _ByteArray implements Float64Array { | |
| 806 factory _Float64Array(int length) { | |
| 807 return _new(length); | |
| 808 } | |
| 809 | |
| 810 factory _Float64Array.view(ByteArray array, [int start = 0, int length]) { | |
| 811 if (length === null) { | |
| 812 length = array.lengthInBytes() ~/ 8; | |
| 813 } | |
| 814 return new _Float64ArrayView(array, start, length); | |
| 815 } | |
| 816 | |
| 817 double operator[](int index) { | |
| 818 return _getIndexed(index); | |
| 819 } | |
| 820 | |
| 821 void operator[]=(int index, double value) { | |
| 822 _setIndexed(index, value); | |
| 823 } | |
| 824 | |
| 825 Iterator<double> iterator() { | |
| 826 return new _ByteArrayIterator<double>(this); | |
| 827 } | |
| 828 | |
| 829 List<double> getRange(int start, int length) { | |
| 830 Arrays.rangeCheck(this, start, length); | |
| 831 _Float64Array result = _new(length); | |
| 832 result.setRange(0, length, this, start); | |
| 833 return result; | |
| 834 } | |
| 835 | |
| 836 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 837 if (from is _Float64Array) { | |
| 838 int startInBytes = start * _bytesPerElement; | |
| 839 int lengthInBytes = length * _bytesPerElement; | |
| 840 int startFromInBytes = startFrom * _bytesPerElement; | |
| 841 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 842 } else { | |
| 843 Arrays.copy(from, startFrom, this, start, length); | |
| 844 } | |
| 845 } | |
| 846 | |
| 847 String toString() { | |
| 848 return Collections.collectionToString(this); | |
| 849 } | |
| 850 | |
| 851 int bytesPerElement() { | |
| 852 return 8; | |
| 853 } | |
| 854 | |
| 855 int lengthInBytes() { | |
| 856 return _length() * bytesPerElement(); | |
| 857 } | |
| 858 | |
| 859 static final int _bytesPerElement = 8; | |
| 860 | |
| 861 static _Float64Array _new(int length) native "Float64Array_new"; | |
| 862 | |
| 863 int _getIndexed(int index) native "Float64Array_getIndexed"; | |
| 864 | |
| 865 void _setIndexed(int index, double value) native "Float64Array_setIndexed"; | |
| 866 } | |
| 867 | |
| 868 | |
| 869 class _ExternalInt8Array extends _ByteArray implements Int8Array { | |
| 870 int operator[](int index) { | |
| 871 return _getIndexed(index); | |
| 872 } | |
| 873 | |
| 874 int operator[]=(int index, int value) { | |
| 875 _setIndexed(index, _toInt8(value)); | |
| 876 } | |
| 877 | |
| 878 Iterator<int> iterator() { | |
| 879 return new _ByteArrayIterator<int>(this); | |
| 880 } | |
| 881 | |
| 882 _Int8Array getRange(int start, int length) { | |
| 883 Arrays.rangeCheck(this, start, length); | |
| 884 _Int8Array result = new Int8Array(length); | |
| 885 result.setRange(0, length, this, start); | |
| 886 return result; | |
| 887 } | |
| 888 | |
| 889 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 890 if (from is _ExternalInt8Array) { | |
| 891 int startInBytes = start * bytesPerElement(); | |
| 892 int lengthInBytes = length * bytesPerElement(); | |
| 893 int startFromInBytes = startFrom * bytesPerElement(); | |
| 894 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 895 } else { | |
| 896 Arrays.copy(from, startFrom, this, start, length); | |
| 897 } | |
| 898 } | |
| 899 | |
| 900 String toString() { | |
| 901 return Collections.collectionToString(this); | |
| 902 } | |
| 903 | |
| 904 int bytesPerElement() { | |
| 905 return 1; | |
| 906 } | |
| 907 | |
| 908 int lengthInBytes() { | |
| 909 return _length() * bytesPerElement(); | |
| 910 } | |
| 911 | |
| 912 int _getIndexed(int index) native "ExternalInt8Array_getIndexed"; | |
| 913 | |
| 914 void _setIndexed(int index, int value) native "ExternalInt8Array_setIndexed"; | |
| 915 } | |
| 916 | |
| 917 | |
| 918 class _ExternalUint8Array extends _ByteArray implements Uint8Array { | |
| 919 int operator[](int index) { | |
| 920 return _getIndexed(index); | |
| 921 } | |
| 922 | |
| 923 int operator[]=(int index, int value) { | |
| 924 _setIndexed(index, _toUint8(value)); | |
| 925 } | |
| 926 | |
| 927 Iterator<int> iterator() { | |
| 928 return new _ByteArrayIterator<int>(this); | |
| 929 } | |
| 930 | |
| 931 _Uint8Array getRange(int start, int length) { | |
| 932 Arrays.rangeCheck(this, start, length); | |
| 933 _Uint8Array result = new Uint8Array(length); | |
| 934 result.setRange(0, length, this, start); | |
| 935 return result; | |
| 936 } | |
| 937 | |
| 938 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 939 if (from is _ExternalUint8Array) { | |
| 940 int startInBytes = start * bytesPerElement(); | |
| 941 int lengthInBytes = length * bytesPerElement(); | |
| 942 int startFromInBytes = startFrom * bytesPerElement(); | |
| 943 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 944 } else { | |
| 945 Arrays.copy(from, startFrom, this, start, length); | |
| 946 } | |
| 947 } | |
| 948 | |
| 949 String toString() { | |
| 950 return Collections.collectionToString(this); | |
| 951 } | |
| 952 | |
| 953 int bytesPerElement() { | |
| 954 return 1; | |
| 955 } | |
| 956 | |
| 957 int lengthInBytes() { | |
| 958 return _length() * bytesPerElement(); | |
| 959 } | |
| 960 | |
| 961 int _getIndexed(int index) native "ExternalUint8Array_getIndexed"; | |
| 962 | |
| 963 void _setIndexed(int index, int value) native "ExternalUint8Array_setIndexed"; | |
| 964 } | |
| 965 | |
| 966 | |
| 967 class _ExternalInt16Array extends _ByteArray implements Int16Array { | |
| 968 int operator[](int index) { | |
| 969 return _getIndexed(index); | |
| 970 } | |
| 971 | |
| 972 int operator[]=(int index, int value) { | |
| 973 _setIndexed(index, _toInt16(value)); | |
| 974 } | |
| 975 | |
| 976 Iterator<int> iterator() { | |
| 977 return new _ByteArrayIterator<int>(this); | |
| 978 } | |
| 979 | |
| 980 _Int16Array getRange(int start, int length) { | |
| 981 Arrays.rangeCheck(this, start, length); | |
| 982 _Int16Array result = new Int16Array(length); | |
| 983 result.setRange(0, length, this, start); | |
| 984 return result; | |
| 985 } | |
| 986 | |
| 987 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 988 if (from is _ExternalInt16Array) { | |
| 989 int startInBytes = start * bytesPerElement(); | |
| 990 int lengthInBytes = length * bytesPerElement(); | |
| 991 int startFromInBytes = startFrom * bytesPerElement(); | |
| 992 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 993 } else { | |
| 994 Arrays.copy(from, startFrom, this, start, length); | |
| 995 } | |
| 996 } | |
| 997 | |
| 998 String toString() { | |
| 999 return Collections.collectionToString(this); | |
| 1000 } | |
| 1001 | |
| 1002 int bytesPerElement() { | |
| 1003 return 2; | |
| 1004 } | |
| 1005 | |
| 1006 int lengthInBytes() { | |
| 1007 return _length() * bytesPerElement(); | |
| 1008 } | |
| 1009 | |
| 1010 int _getIndexed(int index) native "ExternalInt16Array_getIndexed"; | |
| 1011 | |
| 1012 void _setIndexed(int index, int value) native "ExternalInt16Array_setIndexed"; | |
| 1013 } | |
| 1014 | |
| 1015 | |
| 1016 class _ExternalUint16Array extends _ByteArray implements Uint16Array { | |
| 1017 int operator[](int index) { | |
| 1018 return _getIndexed(index); | |
| 1019 } | |
| 1020 | |
| 1021 int operator[]=(int index, int value) { | |
| 1022 _setIndexed(index, _toUint16(value)); | |
| 1023 } | |
| 1024 | |
| 1025 Iterator<int> iterator() { | |
| 1026 return new _ByteArrayIterator<int>(this); | |
| 1027 } | |
| 1028 | |
| 1029 _Uint16Array getRange(int start, int length) { | |
| 1030 Arrays.rangeCheck(this, start, length); | |
| 1031 _Uint16Array result = new Uint16Array(length); | |
| 1032 result.setRange(0, length, this, start); | |
| 1033 return result; | |
| 1034 } | |
| 1035 | |
| 1036 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1037 if (from is _ExternalUint16Array) { | |
| 1038 int startInBytes = start * bytesPerElement(); | |
| 1039 int lengthInBytes = length * bytesPerElement(); | |
| 1040 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1041 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1042 } else { | |
| 1043 Arrays.copy(from, startFrom, this, start, length); | |
| 1044 } | |
| 1045 } | |
| 1046 | |
| 1047 String toString() { | |
| 1048 return Collections.collectionToString(this); | |
| 1049 } | |
| 1050 | |
| 1051 int bytesPerElement() { | |
| 1052 return 2; | |
| 1053 } | |
| 1054 | |
| 1055 int lengthInBytes() { | |
| 1056 return _length() * bytesPerElement(); | |
| 1057 } | |
| 1058 | |
| 1059 int _getIndexed(int index) native "ExternalUint16Array_getIndexed"; | |
| 1060 | |
| 1061 void _setIndexed(int index, int value) native "ExternalUint16Array_setIndexed" ; | |
| 1062 } | |
| 1063 | |
| 1064 | |
| 1065 class _ExternalInt32Array extends _ByteArray implements Int32Array { | |
| 1066 int operator[](int index) { | |
| 1067 return _getIndexed(index); | |
| 1068 } | |
| 1069 | |
| 1070 int operator[]=(int index, int value) { | |
| 1071 _setIndexed(index, _toInt32(value)); | |
| 1072 } | |
| 1073 | |
| 1074 Iterator<int> iterator() { | |
| 1075 return new _ByteArrayIterator<int>(this); | |
| 1076 } | |
| 1077 | |
| 1078 _Int32Array getRange(int start, int length) { | |
| 1079 Arrays.rangeCheck(this, start, length); | |
| 1080 _Int32Array result = new Int32Array(length); | |
| 1081 result.setRange(0, length, this, start); | |
| 1082 return result; | |
| 1083 } | |
| 1084 | |
| 1085 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1086 if (from is _ExternalInt32Array) { | |
| 1087 int startInBytes = start * bytesPerElement(); | |
| 1088 int lengthInBytes = length * bytesPerElement(); | |
| 1089 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1090 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1091 } else { | |
| 1092 Arrays.copy(from, startFrom, this, start, length); | |
| 1093 } | |
| 1094 } | |
| 1095 | |
| 1096 String toString() { | |
| 1097 return Collections.collectionToString(this); | |
| 1098 } | |
| 1099 | |
| 1100 int bytesPerElement() { | |
| 1101 return 4; | |
| 1102 } | |
| 1103 | |
| 1104 int lengthInBytes() { | |
| 1105 return _length() * bytesPerElement(); | |
| 1106 } | |
| 1107 | |
| 1108 int _getIndexed(int index) native "ExternalInt32Array_getIndexed"; | |
| 1109 | |
| 1110 void _setIndexed(int index, int value) native "ExternalInt32Array_setIndexed"; | |
| 1111 } | |
| 1112 | |
| 1113 | |
| 1114 class _ExternalUint32Array extends _ByteArray implements Uint32Array { | |
| 1115 int operator[](int index) { | |
| 1116 return _getIndexed(index); | |
| 1117 } | |
| 1118 | |
| 1119 int operator[]=(int index, int value) { | |
| 1120 _setIndexed(index, _toUint32(value)); | |
| 1121 } | |
| 1122 | |
| 1123 Iterator<int> iterator() { | |
| 1124 return new _ByteArrayIterator<int>(this); | |
| 1125 } | |
| 1126 | |
| 1127 _Uint32Array getRange(int start, int length) { | |
| 1128 Arrays.rangeCheck(this, start, length); | |
| 1129 _Uint32Array result = new Uint32Array(length); | |
| 1130 result.setRange(0, length, this, start); | |
| 1131 return result; | |
| 1132 } | |
| 1133 | |
| 1134 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1135 if (from is _ExternalUint32Array) { | |
| 1136 int startInBytes = start * bytesPerElement(); | |
| 1137 int lengthInBytes = length * bytesPerElement(); | |
| 1138 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1139 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1140 } else { | |
| 1141 Arrays.copy(from, startFrom, this, start, length); | |
| 1142 } | |
| 1143 } | |
| 1144 | |
| 1145 String toString() { | |
| 1146 return Collections.collectionToString(this); | |
| 1147 } | |
| 1148 | |
| 1149 int bytesPerElement() { | |
| 1150 return 4; | |
| 1151 } | |
| 1152 | |
| 1153 int lengthInBytes() { | |
| 1154 return _length() * bytesPerElement(); | |
| 1155 } | |
| 1156 | |
| 1157 int _getIndexed(int index) native "ExternalUint32Array_getIndexed"; | |
| 1158 | |
| 1159 void _setIndexed(int index, int value) native "ExternalUint32Array_setIndexed" ; | |
| 1160 } | |
| 1161 | |
| 1162 | |
| 1163 class _ExternalInt64Array extends _ByteArray implements Int64Array { | |
| 1164 int operator[](int index) { | |
| 1165 return _getIndexed(index); | |
| 1166 } | |
| 1167 | |
| 1168 int operator[]=(int index, int value) { | |
| 1169 _setIndexed(index, _toInt64(value)); | |
| 1170 } | |
| 1171 | |
| 1172 Iterator<int> iterator() { | |
| 1173 return new _ByteArrayIterator<int>(this); | |
| 1174 } | |
| 1175 | |
| 1176 _Int64Array getRange(int start, int length) { | |
| 1177 Arrays.rangeCheck(this, start, length); | |
| 1178 _Int64Array result = new Int64Array(length); | |
| 1179 result.setRange(0, length, this, start); | |
| 1180 return result; | |
| 1181 } | |
| 1182 | |
| 1183 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1184 if (from is _ExternalInt64Array) { | |
| 1185 int startInBytes = start * bytesPerElement(); | |
| 1186 int lengthInBytes = length * bytesPerElement(); | |
| 1187 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1188 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1189 } else { | |
| 1190 Arrays.copy(from, startFrom, this, start, length); | |
| 1191 } | |
| 1192 } | |
| 1193 | |
| 1194 String toString() { | |
| 1195 return Collections.collectionToString(this); | |
| 1196 } | |
| 1197 | |
| 1198 int bytesPerElement() { | |
| 1199 return 8; | |
| 1200 } | |
| 1201 | |
| 1202 int lengthInBytes() { | |
| 1203 return _length() * bytesPerElement(); | |
| 1204 } | |
| 1205 | |
| 1206 int _getIndexed(int index) native "ExternalInt64Array_getIndexed"; | |
| 1207 | |
| 1208 void _setIndexed(int index, int value) native "ExternalInt64Array_setIndexed"; | |
| 1209 } | |
| 1210 | |
| 1211 | |
| 1212 class _ExternalUint64Array extends _ByteArray implements Uint64Array { | |
| 1213 int operator[](int index) { | |
| 1214 return _getIndexed(index); | |
| 1215 } | |
| 1216 | |
| 1217 int operator[]=(int index, int value) { | |
| 1218 _setIndexed(index, _toUint64(value)); | |
| 1219 } | |
| 1220 | |
| 1221 Iterator<int> iterator() { | |
| 1222 return new _ByteArrayIterator<int>(this); | |
| 1223 } | |
| 1224 | |
| 1225 _Uint64Array getRange(int start, int length) { | |
| 1226 Arrays.rangeCheck(this, start, length); | |
| 1227 _Uint64Array result = new Uint64Array(length); | |
| 1228 result.setRange(0, length, this, start); | |
| 1229 return result; | |
| 1230 } | |
| 1231 | |
| 1232 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1233 if (from is _ExternalUint64Array) { | |
| 1234 int startInBytes = start * bytesPerElement(); | |
| 1235 int lengthInBytes = length * bytesPerElement(); | |
| 1236 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1237 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1238 } else { | |
| 1239 Arrays.copy(from, startFrom, this, start, length); | |
| 1240 } | |
| 1241 } | |
| 1242 | |
| 1243 String toString() { | |
| 1244 return Collections.collectionToString(this); | |
| 1245 } | |
| 1246 | |
| 1247 int bytesPerElement() { | |
| 1248 return 8; | |
| 1249 } | |
| 1250 | |
| 1251 int lengthInBytes() { | |
| 1252 return _length() * bytesPerElement(); | |
| 1253 } | |
| 1254 | |
| 1255 int _getIndexed(int index) native "ExternalUint64Array_getIndexed"; | |
| 1256 | |
| 1257 void _setIndexed(int index, int value) native "ExternalUint64Array_setIndexed" ; | |
| 1258 } | |
| 1259 | |
| 1260 | |
| 1261 class _ExternalFloat32Array extends _ByteArray implements Float32Array { | |
| 1262 int operator[](int index) { | |
| 1263 return _getIndexed(index); | |
| 1264 } | |
| 1265 | |
| 1266 int operator[]=(int index, double value) { | |
| 1267 _setIndexed(index, value); | |
| 1268 } | |
| 1269 | |
| 1270 Iterator<int> iterator() { | |
| 1271 return new _ByteArrayIterator<double>(this); | |
| 1272 } | |
| 1273 | |
| 1274 _Float32Array getRange(int start, int length) { | |
| 1275 Arrays.rangeCheck(this, start, length); | |
| 1276 _Float32Array result = new Float32Array(length); | |
| 1277 result.setRange(0, length, this, start); | |
| 1278 return result; | |
| 1279 } | |
| 1280 | |
| 1281 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1282 if (from is _ExternalFloat32Array) { | |
| 1283 int startInBytes = start * bytesPerElement(); | |
| 1284 int lengthInBytes = length * bytesPerElement(); | |
| 1285 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1286 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1287 } else { | |
| 1288 Arrays.copy(from, startFrom, this, start, length); | |
| 1289 } | |
| 1290 } | |
| 1291 | |
| 1292 String toString() { | |
| 1293 return Collections.collectionToString(this); | |
| 1294 } | |
| 1295 | |
| 1296 int bytesPerElement() { | |
| 1297 return 4; | |
| 1298 } | |
| 1299 | |
| 1300 int lengthInBytes() { | |
| 1301 return _length() * bytesPerElement(); | |
| 1302 } | |
| 1303 | |
| 1304 int _getIndexed(int index) native "ExternalFloat32Array_getIndexed"; | |
| 1305 | |
| 1306 void _setIndexed(int index, int value) native "ExternalFloat32Array_setIndexed "; | |
| 1307 } | |
| 1308 | |
| 1309 | |
| 1310 class _ExternalFloat64Array extends _ByteArray implements Float64Array { | |
| 1311 int operator[](int index) { | |
| 1312 return _getIndexed(index); | |
| 1313 } | |
| 1314 | |
| 1315 int operator[]=(int index, double value) { | |
| 1316 _setIndexed(index, value); | |
| 1317 } | |
| 1318 | |
| 1319 Iterator<int> iterator() { | |
| 1320 return new _ByteArrayIterator<double>(this); | |
| 1321 } | |
| 1322 | |
| 1323 _Float64Array getRange(int start, int length) { | |
| 1324 Arrays.rangeCheck(this, start, length); | |
| 1325 _Float64Array result = new Float64Array(length); | |
| 1326 result.setRange(0, length, this, start); | |
| 1327 return result; | |
| 1328 } | |
| 1329 | |
| 1330 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1331 if (from is _ExternalFloat64Array) { | |
| 1332 int startInBytes = start * bytesPerElement(); | |
| 1333 int lengthInBytes = length * bytesPerElement(); | |
| 1334 int startFromInBytes = startFrom * bytesPerElement(); | |
| 1335 _setRange(startInBytes, lengthInBytes, from, startFromInBytes); | |
| 1336 } else { | |
| 1337 Arrays.copy(from, startFrom, this, start, length); | |
| 1338 } | |
| 1339 } | |
| 1340 | |
| 1341 String toString() { | |
| 1342 return Collections.collectionToString(this); | |
| 1343 } | |
| 1344 | |
| 1345 int bytesPerElement() { | |
| 1346 return 8; | |
| 1347 } | |
| 1348 | |
| 1349 int lengthInBytes() { | |
| 1350 return _length() * bytesPerElement(); | |
| 1351 } | |
| 1352 | |
| 1353 int _getIndexed(int index) native "ExternalFloat64Array_getIndexed"; | |
| 1354 | |
| 1355 void _setIndexed(int index, int value) native "ExternalFloat64Array_setIndexed "; | |
| 1356 } | |
| 1357 | |
| 1358 | |
| 1359 class _ByteArrayIterator<E> implements Iterator<E> { | |
| 1360 _ByteArrayIterator(_ByteArray array) | |
| 1361 : _array = array, _length = array.length, _pos = 0 { | |
| 1362 assert(array is _ByteArray); | |
| 222 } | 1363 } |
| 223 | 1364 |
| 224 bool hasNext() { | 1365 bool hasNext() { |
| 225 return _length > _pos; | 1366 return _length > _pos; |
| 226 } | 1367 } |
| 227 | 1368 |
| 228 int next() { | 1369 E next() { |
| 229 if (!hasNext()) { | 1370 if (!hasNext()) { |
| 230 throw const NoMoreElementsException(); | 1371 throw const NoMoreElementsException(); |
| 231 } | 1372 } |
| 232 return _byteArray[_pos++]; | 1373 return _array[_pos++]; |
| 233 } | 1374 } |
| 234 | 1375 |
| 235 final List _byteArray; | 1376 final List<E> _array; |
| 236 | 1377 |
| 237 final int _length; | 1378 final int _length; |
| 238 | 1379 |
| 239 int _pos; | 1380 int _pos; |
| 240 } | 1381 } |
| 241 | 1382 |
| 242 | 1383 |
| 243 class _InternalByteArray extends _ByteArrayBase implements ByteArray { | 1384 class _ByteArrayView implements ByteArray { |
| 244 factory _InternalByteArray(int length) { | 1385 _ByteArrayView(this._array, this._offset, this._length) { |
| 245 return _allocate(length); | 1386 } |
| 246 } | 1387 |
| 247 | 1388 int lengthInBytes() { |
| 248 // ByteArray interface | 1389 return _length; |
| 1390 } | |
| 1391 | |
| 1392 ByteArray subByteArray([int start = 0, int length]) { | |
| 1393 if (length === null) { | |
| 1394 length = this.lengthInBytes(); | |
| 1395 } | |
| 1396 Arrays.rangeCheck(start, length); | |
| 1397 return new _ByteArrayView(_array, _offset + start, length); | |
| 1398 } | |
| 249 | 1399 |
| 250 int getInt8(int byteOffset) { | 1400 int getInt8(int byteOffset) { |
| 251 return _getInt8(byteOffset); | 1401 return _array._getInt8(_offset + byteOffset); |
| 252 } | 1402 } |
| 253 | |
| 254 void setInt8(int byteOffset, int value) { | 1403 void setInt8(int byteOffset, int value) { |
| 255 _setInt8(byteOffset, _toInt8(value)); | 1404 _array._setInt8(_offset + byteOffset, value); |
| 256 } | 1405 } |
| 257 | 1406 |
| 258 int getUint8(int byteOffset) { | 1407 int getUint8(int byteOffset) { |
| 259 return _getUint8(byteOffset); | 1408 return _array._getUint8(_offset + byteOffset); |
| 260 } | 1409 } |
| 261 | |
| 262 void setUint8(int byteOffset, int value) { | 1410 void setUint8(int byteOffset, int value) { |
| 263 _setUint8(byteOffset, _toUint8(value)); | 1411 _array._setUint8(_offset + byteOffset, value); |
| 264 } | 1412 } |
| 265 | 1413 |
| 266 int getInt16(int byteOffset) { | 1414 int getInt16(int byteOffset) { |
| 267 return _getInt16(byteOffset); | 1415 return _array._getInt16(_offset + byteOffset); |
| 268 } | 1416 } |
| 269 | |
| 270 void setInt16(int byteOffset, int value) { | 1417 void setInt16(int byteOffset, int value) { |
| 271 _setInt16(byteOffset, _toInt16(value)); | 1418 _array._setInt16(_offset + byteOffset, value); |
| 272 } | 1419 } |
| 273 | 1420 |
| 274 int getUint16(int byteOffset) { | 1421 int getUint16(int byteOffset) { |
| 275 return _getInt16(byteOffset); | 1422 return _array._getUint16(_offset + byteOffset); |
| 276 } | 1423 } |
| 277 | |
| 278 void setUint16(int byteOffset, int value) { | 1424 void setUint16(int byteOffset, int value) { |
| 279 _setUint16(byteOffset, _toUint16(value)); | 1425 _array._setUint16(_offset + byteOffset, value); |
| 280 } | 1426 } |
| 281 | 1427 |
| 282 int getInt32(int byteOffset) { | 1428 int getInt32(int byteOffset) { |
| 283 return _getInt32(byteOffset); | 1429 return _array._getInt32(_offset + byteOffset); |
| 284 } | 1430 } |
| 285 | |
| 286 void setInt32(int byteOffset, int value) { | 1431 void setInt32(int byteOffset, int value) { |
| 287 _setInt32(byteOffset, _toInt32(value)); | 1432 _array._setInt32(_offset + byteOffset, value); |
| 288 } | 1433 } |
| 289 | 1434 |
| 290 int getUint32(int byteOffset) { | 1435 int getUint32(int byteOffset) { |
| 291 return _getUint32(byteOffset); | 1436 return _array._getUint32(_offset + byteOffset); |
| 292 } | 1437 } |
| 293 | |
| 294 void setUint32(int byteOffset, int value) { | 1438 void setUint32(int byteOffset, int value) { |
| 295 _setUint32(byteOffset, _toUint32(value)); | 1439 _array._setUint32(_offset + byteOffset, value); |
| 296 } | 1440 } |
| 297 | 1441 |
| 298 int getInt64(int byteOffset) { | 1442 int getInt64(int byteOffset) { |
| 299 return _getInt64(byteOffset); | 1443 return _array._getInt64(_offset + byteOffset); |
| 300 } | 1444 } |
| 301 | |
| 302 void setInt64(int byteOffset, int value) { | 1445 void setInt64(int byteOffset, int value) { |
| 303 _setInt64(byteOffset, _toInt64(value)); | 1446 _array._setInt64(_offset + byteOffset, value); |
| 304 } | 1447 } |
| 305 | 1448 |
| 306 int getUint64(int byteOffset) { | 1449 int getUint64(int byteOffset) { |
| 307 return _getUint64(byteOffset); | 1450 return _array._getUint64(_offset + byteOffset); |
| 308 } | 1451 } |
| 309 | |
| 310 void setUint64(int byteOffset, int value) { | 1452 void setUint64(int byteOffset, int value) { |
| 311 _setUint64(byteOffset, _toUint64(value)); | 1453 _array._setUint64(_offset + byteOffset, value); |
| 312 } | 1454 } |
| 313 | 1455 |
| 314 double getFloat32(int byteOffset) { | 1456 double getFloat32(int byteOffset) { |
| 315 return _getFloat32(byteOffset); | 1457 return _array._getFloat32(_offset + byteOffset); |
| 316 } | 1458 } |
| 317 | |
| 318 void setFloat32(int byteOffset, double value) { | 1459 void setFloat32(int byteOffset, double value) { |
| 319 _setFloat32(byteOffset, value); | 1460 _array._setFloat32(_offset + byteOffset, value); |
| 320 } | 1461 } |
| 321 | 1462 |
| 322 double getFloat64(int byteOffset) { | 1463 double getFloat64(int byteOffset) { |
| 323 return _getFloat64(byteOffset); | 1464 return _array._getFloat64(_offset + byteOffset); |
| 324 } | 1465 } |
| 325 | |
| 326 void setFloat64(int byteOffset, double value) { | 1466 void setFloat64(int byteOffset, double value) { |
| 327 _setFloat64(byteOffset, value); | 1467 _array._setFloat64(_offset + byteOffset, value); |
| 328 } | 1468 } |
| 329 | 1469 |
| 330 // Implementation | 1470 final _ByteArray _array; |
| 331 | 1471 final int _offset; |
| 332 static _InternalByteArray _allocate(int length) | 1472 final int _length; |
| 333 native "InternalByteArray_allocate"; | 1473 } |
| 334 | 1474 |
| 335 int _getInt8(int byteOffset) | 1475 |
| 336 native "InternalByteArray_getInt8"; | 1476 class _Int8ArrayView implements Int8Array { |
| 337 | 1477 _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 338 void _setInt8(int byteOffset, int value) | 1478 : _array = array, |
| 339 native "InternalByteArray_setInt8"; | 1479 _offset = offsetInBytes, |
| 340 | 1480 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { |
| 341 int _getUint8(int byteOffset) | 1481 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 342 native "InternalByteArray_getUint8"; | 1482 throw new IndexOutOfRangeException(offsetInBytes); |
| 343 | 1483 } |
| 344 void _setUint8(int byteOffset, int value) | 1484 int lengthInBytes = length * bytesPerElement(); |
| 345 native "InternalByteArray_setUint8"; | 1485 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 346 | 1486 throw new IndexOutOfRangeException(length); |
| 347 int _getInt16(int byteOffset) | 1487 } |
| 348 native "InternalByteArray_getInt16"; | 1488 } |
| 349 | 1489 |
| 350 void _setInt16(int byteOffset, int value) | 1490 get length() { |
| 351 native "InternalByteArray_setInt16"; | 1491 return _length; |
| 352 | 1492 } |
| 353 int _getUint16(int byteOffset) | 1493 |
| 354 native "InternalByteArray_getUint16"; | 1494 int operator[](int index) { |
| 355 | 1495 if (index < 0 || index >= _length) { |
| 356 void _setUint16(int byteOffset, int value) | 1496 throw new IndexOutOfRangeException(index); |
| 357 native "InternalByteArray_setUint16"; | 1497 } |
| 358 | 1498 return _array.getInt8(_offset + (index * bytesPerElement())); |
| 359 int _getInt32(int byteOffset) | |
| 360 native "InternalByteArray_getInt32"; | |
| 361 | |
| 362 void _setInt32(int byteOffset, int value) | |
| 363 native "InternalByteArray_setInt32"; | |
| 364 | |
| 365 int _getUint32(int byteOffset) | |
| 366 native "InternalByteArray_getUint32"; | |
| 367 | |
| 368 void _setUint32(int byteOffset, int value) | |
| 369 native "InternalByteArray_setUint32"; | |
| 370 | |
| 371 int _getInt64(int byteOffset) | |
| 372 native "InternalByteArray_getInt64"; | |
| 373 | |
| 374 void _setInt64(int byteOffset, int value) | |
| 375 native "InternalByteArray_setInt64"; | |
| 376 | |
| 377 int _getUint64(int byteOffset) | |
| 378 native "InternalByteArray_getUint64"; | |
| 379 | |
| 380 void _setUint64(int byteOffset, int value) | |
| 381 native "InternalByteArray_setUint64"; | |
| 382 | |
| 383 double _getFloat32(int byteOffset) | |
| 384 native "InternalByteArray_getFloat32"; | |
| 385 | |
| 386 void _setFloat32(int byteOffset, double value) | |
| 387 native "InternalByteArray_setFloat32"; | |
| 388 | |
| 389 double _getFloat64(int byteOffset) | |
| 390 native "InternalByteArray_getFloat64"; | |
| 391 | |
| 392 void _setFloat64(int byteOffset, double value) | |
| 393 native "InternalByteArray_setFloat64"; | |
| 394 } | |
| 395 | |
| 396 | |
| 397 class _ExternalByteArray extends _ByteArrayBase implements ByteArray { | |
| 398 // Collection interface | |
| 399 | |
| 400 int get length() { | |
| 401 return _length(); | |
| 402 } | |
| 403 | |
| 404 // List interface | |
| 405 | |
| 406 int operator[](int index) { | |
| 407 return _getUint8(index); | |
| 408 } | 1499 } |
| 409 | 1500 |
| 410 void operator[]=(int index, int value) { | 1501 void operator[]=(int index, int value) { |
| 411 _setUint8(index, value); | 1502 if (index < 0 || index >= _length) { |
| 412 } | 1503 throw new IndexOutOfRangeException(index); |
| 413 | 1504 } |
| 414 // ByteArray interface | 1505 _array.setInt8(_offset + (index * bytesPerElement()), _toInt8(value)); |
| 415 | 1506 } |
| 416 int getInt8(int byteOffset) { | 1507 |
| 417 return _getInt8(byteOffset); | 1508 Iterator<int> iterator() { |
| 418 } | 1509 return new _ByteArrayIterator<int>(this); |
| 419 | 1510 } |
| 420 void setInt8(int byteOffset, int value) { | 1511 |
| 421 _setInt8(byteOffset, _toInt8(value)); | 1512 List<int> getRange(int start, int length) { |
| 422 } | 1513 Arrays.rangeCheck(this, start, length); |
| 423 | 1514 Int8Array result = new Int8Array(length); |
| 424 int getUint8(int byteOffset) { | 1515 result.setRange(0, length, this, start); |
| 425 return _getUint8(byteOffset); | 1516 return result; |
| 426 } | 1517 } |
| 427 | 1518 |
| 428 void setUint8(int byteOffset, int value) { | 1519 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 429 _setUint8(byteOffset, _toUint8(value)); | 1520 Arrays.copy(from, startFrom, this, start, length); |
| 430 } | 1521 } |
| 431 | 1522 |
| 432 int getInt16(int byteOffset) { | 1523 void add(int value) { |
| 433 return _getInt16(byteOffset); | 1524 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
|
Ivan Posva
2012/05/02 08:19:17
Why not add a base class _ByteArrayView similar to
cshapiro
2012/05/03 04:01:50
Sounds good. Done.
| |
| 434 } | 1525 } |
| 435 | 1526 |
| 436 void setInt16(int byteOffset, int value) { | 1527 void addLast(int value) { |
| 437 _setInt16(byteOffset, _toInt16(value)); | 1528 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 438 } | 1529 } |
| 439 | 1530 |
| 440 int getUint16(int byteOffset) { | 1531 void addAll(Collection<int> value) { |
| 441 return _getInt16(byteOffset); | 1532 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 442 } | 1533 } |
| 443 | 1534 |
| 444 void setUint16(int byteOffset, int value) { | 1535 void clear() { |
| 445 _setUint16(byteOffset, _toUint16(value)); | 1536 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 446 } | 1537 } |
| 447 | 1538 |
| 448 int getInt32(int byteOffset) { | 1539 void insertRange(int start, int length, [initialValue]) { |
| 449 return _getInt32(byteOffset); | 1540 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 450 } | 1541 } |
| 451 | 1542 |
| 452 void setInt32(int byteOffset, int value) { | 1543 set length(int newLength) { |
| 453 _setInt32(byteOffset, _toInt32(value)); | 1544 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); |
| 454 } | 1545 } |
| 455 | 1546 |
| 456 int getUint32(int byteOffset) { | 1547 int removeLast() { |
| 457 return _getUint32(byteOffset); | 1548 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 458 } | 1549 } |
| 459 | 1550 |
| 460 void setUint32(int byteOffset, int value) { | 1551 void removeRange(int start, int length) { |
| 461 _setUint32(byteOffset, _toUint32(value)); | 1552 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 462 } | 1553 } |
| 463 | 1554 |
| 464 int getInt64(int byteOffset) { | 1555 String toString() { |
| 465 return _getInt64(byteOffset); | 1556 return Collections.collectionToString(this); |
| 466 } | 1557 } |
| 467 | 1558 |
| 468 void setInt64(int byteOffset, int value) { | 1559 int bytesPerElement() { |
| 469 _setInt64(byteOffset, _toInt64(value)); | 1560 return 1; |
| 470 } | 1561 } |
| 471 | 1562 |
| 472 int getUint64(int byteOffset) { | 1563 int lengthInBytes() { |
| 473 return _getUint64(byteOffset); | 1564 return _length * bytesPerElement(); |
| 474 } | 1565 } |
| 475 | 1566 |
| 476 void setUint64(int byteOffset, int value) { | 1567 ByteArray asByteArray([int start = 0, int length]) { |
| 477 _setUint64(byteOffset, _toUint64(value)); | 1568 if (length == null) { |
| 478 } | 1569 length = this.lengthInBytes(); |
| 479 | 1570 } |
| 480 double getFloat32(int byteOffset) { | 1571 Arrays.rangeCheck(start, length); |
| 481 return _getFloat32(byteOffset); | 1572 return _array.subByteArray(_offset + start, length); |
| 482 } | 1573 } |
| 483 | 1574 |
| 484 void setFloat32(int byteOffset, double value) { | 1575 final ByteArray _array; |
| 485 _setFloat32(byteOffset, value); | 1576 final int _offset; |
| 486 } | 1577 final int _length; |
| 487 | 1578 } |
| 488 double getFloat64(int byteOffset) { | 1579 |
| 489 return _getFloat64(byteOffset); | 1580 |
| 490 } | 1581 class _Uint8ArrayView implements Uint8Array { |
| 491 | 1582 _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) |
| 492 void setFloat64(int byteOffset, double value) { | 1583 : _array = array, |
| 493 _setFloat64(byteOffset, value); | 1584 _offset = offsetInBytes, |
| 494 } | 1585 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { |
| 495 | 1586 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { |
| 496 // Implementation | 1587 throw new IndexOutOfRangeException(offsetInBytes); |
| 497 | 1588 } |
| 498 int _getInt8(int byteOffset) | 1589 int lengthInBytes = length * bytesPerElement(); |
| 499 native "ExternalByteArray_getInt8"; | 1590 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { |
| 500 | 1591 throw new IndexOutOfRangeException(length); |
| 501 void _setInt8(int byteOffset, int value) | 1592 } |
| 502 native "ExternalByteArray_setInt8"; | 1593 } |
| 503 | 1594 |
| 504 int _getUint8(int byteOffset) | 1595 get length() { |
| 505 native "ExternalByteArray_getUint8"; | 1596 return _length; |
| 506 | 1597 } |
| 507 void _setUint8(int byteOffset, int value) | 1598 |
| 508 native "ExternalByteArray_setUint8"; | 1599 int operator[](int index) { |
| 509 | 1600 if (index < 0 || index >= _length) { |
| 510 int _getInt16(int byteOffset) | 1601 throw new IndexOutOfRangeException(index); |
| 511 native "ExternalByteArray_getInt16"; | 1602 } |
| 512 | 1603 return _array.getUint8(_offset + (index * bytesPerElement())); |
| 513 void _setInt16(int byteOffset, int value) | 1604 } |
| 514 native "ExternalByteArray_setInt16"; | 1605 |
| 515 | 1606 void operator[]=(int index, int value) { |
| 516 int _getUint16(int byteOffset) | 1607 if (index < 0 || index >= _length) { |
| 517 native "ExternalByteArray_getUint16"; | 1608 throw new IndexOutOfRangeException(index); |
| 518 | 1609 } |
| 519 void _setUint16(int byteOffset, int value) | 1610 _array.setUint8(_offset + (index * bytesPerElement()), _toUint8(value)); |
| 520 native "ExternalByteArray_setUint16"; | 1611 } |
| 521 | 1612 |
| 522 int _getInt32(int byteOffset) | 1613 Iterator<int> iterator() { |
| 523 native "ExternalByteArray_getInt32"; | 1614 return new _ByteArrayIterator<int>(this); |
| 524 | 1615 } |
| 525 void _setInt32(int byteOffset, int value) | 1616 |
| 526 native "ExternalByteArray_setInt32"; | 1617 List<int> getRange(int start, int length) { |
| 527 | 1618 Arrays.rangeCheck(this, start, length); |
| 528 int _getUint32(int byteOffset) | 1619 Uint8Array result = new Uint8Array(length); |
| 529 native "ExternalByteArray_getUint32"; | 1620 result.setRange(0, length, this, start); |
| 530 | 1621 return result; |
| 531 void _setUint32(int byteOffset, int value) | 1622 } |
| 532 native "ExternalByteArray_setUint32"; | 1623 |
| 533 | 1624 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| 534 int _getInt64(int byteOffset) | 1625 Arrays.copy(from, startFrom, this, start, length); |
| 535 native "ExternalByteArray_getInt64"; | 1626 } |
| 536 | 1627 |
| 537 void _setInt64(int byteOffset, int value) | 1628 void add(int value) { |
| 538 native "ExternalByteArray_setInt64"; | 1629 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 539 | 1630 } |
| 540 int _getUint64(int byteOffset) | 1631 |
| 541 native "ExternalByteArray_getUint64"; | 1632 void addLast(int value) { |
| 542 | 1633 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 543 void _setUint64(int byteOffset, int value) | 1634 } |
| 544 native "ExternalByteArray_setUint64"; | 1635 |
| 545 | 1636 void addAll(Collection<int> value) { |
| 546 double _getFloat32(int byteOffset) | 1637 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 547 native "ExternalByteArray_getFloat32"; | 1638 } |
| 548 | 1639 |
| 549 void _setFloat32(int byteOffset, double value) | 1640 void clear() { |
| 550 native "ExternalByteArray_setFloat32"; | 1641 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); |
| 551 | 1642 } |
| 552 double _getFloat64(int byteOffset) | 1643 |
| 553 native "ExternalByteArray_getFloat64"; | 1644 void insertRange(int start, int length, [initialValue]) { |
| 554 | 1645 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); |
| 555 void _setFloat64(int byteOffset, double value) | 1646 } |
| 556 native "ExternalByteArray_setFloat64"; | 1647 |
| 557 } | 1648 set length(int newLength) { |
| 1649 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 1650 } | |
| 1651 | |
| 1652 int removeLast() { | |
| 1653 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1654 } | |
| 1655 | |
| 1656 void removeRange(int start, int length) { | |
| 1657 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1658 } | |
| 1659 | |
| 1660 String toString() { | |
| 1661 return Collections.collectionToString(this); | |
| 1662 } | |
| 1663 | |
| 1664 int bytesPerElement() { | |
| 1665 return 1; | |
| 1666 } | |
| 1667 | |
| 1668 int lengthInBytes() { | |
| 1669 return _length * bytesPerElement(); | |
| 1670 } | |
| 1671 | |
| 1672 ByteArray asByteArray([int start = 0, int length]) { | |
| 1673 if (length == null) { | |
| 1674 length = this.lengthInBytes(); | |
| 1675 } | |
| 1676 Arrays.rangeCheck(start, length); | |
| 1677 return _array.subByteArray(_offset + start, length); | |
| 1678 } | |
| 1679 | |
| 1680 final ByteArray _array; | |
| 1681 final int _offset; | |
| 1682 final int _length; | |
| 1683 } | |
| 1684 | |
| 1685 | |
| 1686 class _Int16ArrayView implements Int16Array { | |
| 1687 _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1688 : _array = array, | |
| 1689 _offset = offsetInBytes, | |
| 1690 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 1691 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1692 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1693 } | |
| 1694 int lengthInBytes = length * bytesPerElement(); | |
| 1695 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1696 throw new IndexOutOfRangeException(length); | |
| 1697 } | |
| 1698 } | |
| 1699 | |
| 1700 get length() { | |
| 1701 return _length; | |
| 1702 } | |
| 1703 | |
| 1704 int operator[](int index) { | |
| 1705 if (index < 0 || index >= _length) { | |
| 1706 throw new IndexOutOfRangeException(index); | |
| 1707 } | |
| 1708 return _array.getInt16(_offset + (index * bytesPerElement())); | |
| 1709 } | |
| 1710 | |
| 1711 void operator[]=(int index, int value) { | |
| 1712 if (index < 0 || index >= _length) { | |
| 1713 throw new IndexOutOfRangeException(index); | |
| 1714 } | |
| 1715 _array.setInt16(_offset + (index * bytesPerElement()), _toInt16(value)); | |
| 1716 } | |
| 1717 | |
| 1718 Iterator<int> iterator() { | |
| 1719 return new _ByteArrayIterator<int>(this); | |
| 1720 } | |
| 1721 | |
| 1722 List<int> getRange(int start, int length) { | |
| 1723 Arrays.rangeCheck(this, start, length); | |
| 1724 Int16Array result = new Int16Array(length); | |
| 1725 result.setRange(0, length, this, start); | |
| 1726 return result; | |
| 1727 } | |
| 1728 | |
| 1729 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1730 Arrays.copy(from, startFrom, this, start, length); | |
| 1731 } | |
| 1732 | |
| 1733 void add(int value) { | |
| 1734 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1735 } | |
| 1736 | |
| 1737 void addLast(int value) { | |
| 1738 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1739 } | |
| 1740 | |
| 1741 void addAll(Collection<int> value) { | |
| 1742 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1743 } | |
| 1744 | |
| 1745 void clear() { | |
| 1746 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1747 } | |
| 1748 | |
| 1749 void insertRange(int start, int length, [initialValue]) { | |
| 1750 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1751 } | |
| 1752 | |
| 1753 set length(int newLength) { | |
| 1754 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 1755 } | |
| 1756 | |
| 1757 int removeLast() { | |
| 1758 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1759 } | |
| 1760 | |
| 1761 void removeRange(int start, int length) { | |
| 1762 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1763 } | |
| 1764 | |
| 1765 String toString() { | |
| 1766 return Collections.collectionToString(this); | |
| 1767 } | |
| 1768 | |
| 1769 int bytesPerElement() { | |
| 1770 return 2; | |
| 1771 } | |
| 1772 | |
| 1773 int lengthInBytes() { | |
| 1774 return _length * bytesPerElement(); | |
| 1775 } | |
| 1776 | |
| 1777 ByteArray asByteArray([int start = 0, int length]) { | |
| 1778 if (length == null) { | |
| 1779 length = this.lengthInBytes(); | |
| 1780 } | |
| 1781 Arrays.rangeCheck(start, length); | |
| 1782 return _array.subByteArray(_offset + start, length); | |
| 1783 } | |
| 1784 | |
| 1785 final ByteArray _array; | |
| 1786 final int _offset; | |
| 1787 final int _length; | |
| 1788 } | |
| 1789 | |
| 1790 | |
| 1791 class _Uint16ArrayView implements Uint16Array { | |
| 1792 _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1793 : _array = array, | |
| 1794 _offset = offsetInBytes, | |
| 1795 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 1796 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1797 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1798 } | |
| 1799 int lengthInBytes = length * bytesPerElement(); | |
| 1800 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1801 throw new IndexOutOfRangeException(length); | |
| 1802 } | |
| 1803 } | |
| 1804 | |
| 1805 get length() { | |
| 1806 return _length; | |
| 1807 } | |
| 1808 | |
| 1809 int operator[](int index) { | |
| 1810 if (index < 0 || index >= _length) { | |
| 1811 throw new IndexOutOfRangeException(index); | |
| 1812 } | |
| 1813 return _array.getUint16(_offset + (index * bytesPerElement())); | |
| 1814 } | |
| 1815 | |
| 1816 void operator[]=(int index, int value) { | |
| 1817 if (index < 0 || index >= _length) { | |
| 1818 throw new IndexOutOfRangeException(index); | |
| 1819 } | |
| 1820 _array.setUint16(_offset + (index * bytesPerElement()), _toUint16(value)); | |
| 1821 } | |
| 1822 | |
| 1823 Iterator<int> iterator() { | |
| 1824 return new _ByteArrayIterator<int>(this); | |
| 1825 } | |
| 1826 | |
| 1827 List<int> getRange(int start, int length) { | |
| 1828 Arrays.rangeCheck(this, start, length); | |
| 1829 Uint16Array result = new Uint16Array(length); | |
| 1830 result.setRange(0, length, this, start); | |
| 1831 return result; | |
| 1832 } | |
| 1833 | |
| 1834 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1835 Arrays.copy(from, startFrom, this, start, length); | |
| 1836 } | |
| 1837 | |
| 1838 void add(int value) { | |
| 1839 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1840 } | |
| 1841 | |
| 1842 void addLast(int value) { | |
| 1843 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1844 } | |
| 1845 | |
| 1846 void addAll(Collection<int> value) { | |
| 1847 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1848 } | |
| 1849 | |
| 1850 void clear() { | |
| 1851 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1852 } | |
| 1853 | |
| 1854 void insertRange(int start, int length, [initialValue]) { | |
| 1855 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1856 } | |
| 1857 | |
| 1858 set length(int newLength) { | |
| 1859 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 1860 } | |
| 1861 | |
| 1862 int removeLast() { | |
| 1863 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1864 } | |
| 1865 | |
| 1866 void removeRange(int start, int length) { | |
| 1867 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1868 } | |
| 1869 | |
| 1870 String toString() { | |
| 1871 return Collections.collectionToString(this); | |
| 1872 } | |
| 1873 | |
| 1874 int bytesPerElement() { | |
| 1875 return 2; | |
| 1876 } | |
| 1877 | |
| 1878 int lengthInBytes() { | |
| 1879 return _length * bytesPerElement(); | |
| 1880 } | |
| 1881 | |
| 1882 ByteArray asByteArray([int start = 0, int length]) { | |
| 1883 if (length == null) { | |
| 1884 length = this.lengthInBytes(); | |
| 1885 } | |
| 1886 Arrays.rangeCheck(start, length); | |
| 1887 return _array.subByteArray(_offset + start, length); | |
| 1888 } | |
| 1889 | |
| 1890 final ByteArray _array; | |
| 1891 final int _offset; | |
| 1892 final int _length; | |
| 1893 } | |
| 1894 | |
| 1895 | |
| 1896 class _Int32ArrayView implements Int32Array { | |
| 1897 _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 1898 : _array = array, | |
| 1899 _offset = offsetInBytes, | |
| 1900 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 1901 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 1902 throw new IndexOutOfRangeException(offsetInBytes); | |
| 1903 } | |
| 1904 int lengthInBytes = length * bytesPerElement(); | |
| 1905 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 1906 throw new IndexOutOfRangeException(length); | |
| 1907 } | |
| 1908 } | |
| 1909 | |
| 1910 get length() { | |
| 1911 return _length; | |
| 1912 } | |
| 1913 | |
| 1914 int operator[](int index) { | |
| 1915 if (index < 0 || index >= _length) { | |
| 1916 throw new IndexOutOfRangeException(index); | |
| 1917 } | |
| 1918 return _array.getInt32(_offset + (index * bytesPerElement())); | |
| 1919 } | |
| 1920 | |
| 1921 void operator[]=(int index, int value) { | |
| 1922 if (index < 0 || index >= _length) { | |
| 1923 throw new IndexOutOfRangeException(index); | |
| 1924 } | |
| 1925 _array.setInt32(_offset + (index * bytesPerElement()), _toInt32(value)); | |
| 1926 } | |
| 1927 | |
| 1928 Iterator<int> iterator() { | |
| 1929 return new _ByteArrayIterator<int>(this); | |
| 1930 } | |
| 1931 | |
| 1932 List<int> getRange(int start, int length) { | |
| 1933 Arrays.rangeCheck(this, start, length); | |
| 1934 Int32Array result = new Int32Array(length); | |
| 1935 result.setRange(0, length, this, start); | |
| 1936 return result; | |
| 1937 } | |
| 1938 | |
| 1939 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 1940 Arrays.copy(from, startFrom, this, start, length); | |
| 1941 } | |
| 1942 | |
| 1943 void add(int value) { | |
| 1944 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1945 } | |
| 1946 | |
| 1947 void addLast(int value) { | |
| 1948 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1949 } | |
| 1950 | |
| 1951 void addAll(Collection<int> value) { | |
| 1952 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1953 } | |
| 1954 | |
| 1955 void clear() { | |
| 1956 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1957 } | |
| 1958 | |
| 1959 void insertRange(int start, int length, [initialValue]) { | |
| 1960 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 1961 } | |
| 1962 | |
| 1963 set length(int newLength) { | |
| 1964 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 1965 } | |
| 1966 | |
| 1967 int removeLast() { | |
| 1968 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1969 } | |
| 1970 | |
| 1971 void removeRange(int start, int length) { | |
| 1972 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 1973 } | |
| 1974 | |
| 1975 String toString() { | |
| 1976 return Collections.collectionToString(this); | |
| 1977 } | |
| 1978 | |
| 1979 int bytesPerElement() { | |
| 1980 return 4; | |
| 1981 } | |
| 1982 | |
| 1983 int lengthInBytes() { | |
| 1984 return _length * bytesPerElement(); | |
| 1985 } | |
| 1986 | |
| 1987 ByteArray asByteArray([int start = 0, int length]) { | |
| 1988 if (length == null) { | |
| 1989 length = this.lengthInBytes(); | |
| 1990 } | |
| 1991 Arrays.rangeCheck(start, length); | |
| 1992 return _array.subByteArray(_offset + start, length); | |
| 1993 } | |
| 1994 | |
| 1995 final ByteArray _array; | |
| 1996 final int _offset; | |
| 1997 final int _length; | |
| 1998 } | |
| 1999 | |
| 2000 | |
| 2001 class _Uint32ArrayView implements Uint32Array { | |
| 2002 _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2003 : _array = array, | |
| 2004 _offset = offsetInBytes, | |
| 2005 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 2006 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2007 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2008 } | |
| 2009 int lengthInBytes = length * bytesPerElement(); | |
| 2010 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2011 throw new IndexOutOfRangeException(length); | |
| 2012 } | |
| 2013 } | |
| 2014 | |
| 2015 get length() { | |
| 2016 return _length; | |
| 2017 } | |
| 2018 | |
| 2019 int operator[](int index) { | |
| 2020 if (index < 0 || index >= _length) { | |
| 2021 throw new IndexOutOfRangeException(index); | |
| 2022 } | |
| 2023 return _array.getUint32(_offset + (index * bytesPerElement())); | |
| 2024 } | |
| 2025 | |
| 2026 void operator[]=(int index, int value) { | |
| 2027 if (index < 0 || index >= _length) { | |
| 2028 throw new IndexOutOfRangeException(index); | |
| 2029 } | |
| 2030 _array.setUint32(_offset + (index * bytesPerElement()), _toUint32(value)); | |
| 2031 } | |
| 2032 | |
| 2033 Iterator<int> iterator() { | |
| 2034 return new _ByteArrayIterator<int>(this); | |
| 2035 } | |
| 2036 | |
| 2037 List<int> getRange(int start, int length) { | |
| 2038 Arrays.rangeCheck(this, start, length); | |
| 2039 Uint32Array result = new Uint32Array(length); | |
| 2040 result.setRange(0, length, this, start); | |
| 2041 return result; | |
| 2042 } | |
| 2043 | |
| 2044 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2045 Arrays.copy(from, startFrom, this, start, length); | |
| 2046 } | |
| 2047 | |
| 2048 void add(int value) { | |
| 2049 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2050 } | |
| 2051 | |
| 2052 void addLast(int value) { | |
| 2053 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2054 } | |
| 2055 | |
| 2056 void addAll(Collection<int> value) { | |
| 2057 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2058 } | |
| 2059 | |
| 2060 void clear() { | |
| 2061 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2062 } | |
| 2063 | |
| 2064 void insertRange(int start, int length, [initialValue]) { | |
| 2065 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2066 } | |
| 2067 | |
| 2068 set length(int newLength) { | |
| 2069 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 2070 } | |
| 2071 | |
| 2072 int removeLast() { | |
| 2073 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2074 } | |
| 2075 | |
| 2076 void removeRange(int start, int length) { | |
| 2077 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2078 } | |
| 2079 | |
| 2080 String toString() { | |
| 2081 return Collections.collectionToString(this); | |
| 2082 } | |
| 2083 | |
| 2084 int bytesPerElement() { | |
| 2085 return 4; | |
| 2086 } | |
| 2087 | |
| 2088 int lengthInBytes() { | |
| 2089 return _length * bytesPerElement(); | |
| 2090 } | |
| 2091 | |
| 2092 ByteArray asByteArray([int start = 0, int length]) { | |
| 2093 if (length == null) { | |
| 2094 length = this.lengthInBytes(); | |
| 2095 } | |
| 2096 Arrays.rangeCheck(start, length); | |
| 2097 return _array.subByteArray(_offset + start, length); | |
| 2098 } | |
| 2099 | |
| 2100 final ByteArray _array; | |
| 2101 final int _offset; | |
| 2102 final int _length; | |
| 2103 } | |
| 2104 | |
| 2105 | |
| 2106 class _Int64ArrayView implements Int64Array { | |
| 2107 _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2108 : _array = array, | |
| 2109 _offset = offsetInBytes, | |
| 2110 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 2111 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2112 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2113 } | |
| 2114 int lengthInBytes = length * bytesPerElement(); | |
| 2115 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2116 throw new IndexOutOfRangeException(length); | |
| 2117 } | |
| 2118 } | |
| 2119 | |
| 2120 get length() { | |
| 2121 return _length; | |
| 2122 } | |
| 2123 | |
| 2124 int operator[](int index) { | |
| 2125 if (index < 0 || index >= _length) { | |
| 2126 throw new IndexOutOfRangeException(index); | |
| 2127 } | |
| 2128 return _array.getInt64(_offset + (index * bytesPerElement())); | |
| 2129 } | |
| 2130 | |
| 2131 void operator[]=(int index, int value) { | |
| 2132 if (index < 0 || index >= _length) { | |
| 2133 throw new IndexOutOfRangeException(index); | |
| 2134 } | |
| 2135 _array.setInt64(_offset + (index * bytesPerElement()), _toInt64(value)); | |
| 2136 } | |
| 2137 | |
| 2138 Iterator<int> iterator() { | |
| 2139 return new _ByteArrayIterator<int>(this); | |
| 2140 } | |
| 2141 | |
| 2142 List<int> getRange(int start, int length) { | |
| 2143 Arrays.rangeCheck(this, start, length); | |
| 2144 Int64Array result = new Int64Array(length); | |
| 2145 result.setRange(0, length, this, start); | |
| 2146 return result; | |
| 2147 } | |
| 2148 | |
| 2149 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2150 Arrays.copy(from, startFrom, this, start, length); | |
| 2151 } | |
| 2152 | |
| 2153 void add(int value) { | |
| 2154 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2155 } | |
| 2156 | |
| 2157 void addLast(int value) { | |
| 2158 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2159 } | |
| 2160 | |
| 2161 void addAll(Collection<int> value) { | |
| 2162 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2163 } | |
| 2164 | |
| 2165 void clear() { | |
| 2166 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2167 } | |
| 2168 | |
| 2169 void insertRange(int start, int length, [initialValue]) { | |
| 2170 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2171 } | |
| 2172 | |
| 2173 set length(int newLength) { | |
| 2174 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 2175 } | |
| 2176 | |
| 2177 int removeLast() { | |
| 2178 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2179 } | |
| 2180 | |
| 2181 void removeRange(int start, int length) { | |
| 2182 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2183 } | |
| 2184 | |
| 2185 String toString() { | |
| 2186 return Collections.collectionToString(this); | |
| 2187 } | |
| 2188 | |
| 2189 int bytesPerElement() { | |
| 2190 return 8; | |
| 2191 } | |
| 2192 | |
| 2193 int lengthInBytes() { | |
| 2194 return _length * bytesPerElement(); | |
| 2195 } | |
| 2196 | |
| 2197 ByteArray asByteArray([int start = 0, int length]) { | |
| 2198 if (length == null) { | |
| 2199 length = this.lengthInBytes(); | |
| 2200 } | |
| 2201 Arrays.rangeCheck(start, length); | |
| 2202 return _array.subByteArray(_offset + start, length); | |
| 2203 } | |
| 2204 | |
| 2205 final ByteArray _array; | |
| 2206 final int _offset; | |
| 2207 final int _length; | |
| 2208 } | |
| 2209 | |
| 2210 | |
| 2211 class _Uint64ArrayView implements Uint64Array { | |
| 2212 _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2213 : _array = array, | |
| 2214 _offset = offsetInBytes, | |
| 2215 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 2216 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2217 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2218 } | |
| 2219 int lengthInBytes = length * bytesPerElement(); | |
| 2220 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2221 throw new IndexOutOfRangeException(length); | |
| 2222 } | |
| 2223 } | |
| 2224 | |
| 2225 get length() { | |
| 2226 return _length; | |
| 2227 } | |
| 2228 | |
| 2229 int operator[](int index) { | |
| 2230 if (index < 0 || index >= _length) { | |
| 2231 throw new IndexOutOfRangeException(index); | |
| 2232 } | |
| 2233 return _array.getUint64(_offset + (index * bytesPerElement())); | |
| 2234 } | |
| 2235 | |
| 2236 void operator[]=(int index, int value) { | |
| 2237 if (index < 0 || index >= _length) { | |
| 2238 throw new IndexOutOfRangeException(index); | |
| 2239 } | |
| 2240 _array.setUint64(_offset + (index * bytesPerElement()), _toUint64(value)); | |
| 2241 } | |
| 2242 | |
| 2243 Iterator<int> iterator() { | |
| 2244 return new _ByteArrayIterator<int>(this); | |
| 2245 } | |
| 2246 | |
| 2247 List<int> getRange(int start, int length) { | |
| 2248 Arrays.rangeCheck(this, start, length); | |
| 2249 Uint64Array result = new Uint64Array(length); | |
| 2250 result.setRange(0, length, this, start); | |
| 2251 return result; | |
| 2252 } | |
| 2253 | |
| 2254 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
| 2255 Arrays.copy(from, startFrom, this, start, length); | |
| 2256 } | |
| 2257 | |
| 2258 void add(int value) { | |
| 2259 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2260 } | |
| 2261 | |
| 2262 void addLast(int value) { | |
| 2263 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2264 } | |
| 2265 | |
| 2266 void addAll(Collection<int> value) { | |
| 2267 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2268 } | |
| 2269 | |
| 2270 void clear() { | |
| 2271 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2272 } | |
| 2273 | |
| 2274 void insertRange(int start, int length, [initialValue]) { | |
| 2275 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2276 } | |
| 2277 | |
| 2278 set length(int newLength) { | |
| 2279 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 2280 } | |
| 2281 | |
| 2282 int removeLast() { | |
| 2283 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2284 } | |
| 2285 | |
| 2286 void removeRange(int start, int length) { | |
| 2287 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2288 } | |
| 2289 | |
| 2290 String toString() { | |
| 2291 return Collections.collectionToString(this); | |
| 2292 } | |
| 2293 | |
| 2294 int bytesPerElement() { | |
| 2295 return 8; | |
| 2296 } | |
| 2297 | |
| 2298 int lengthInBytes() { | |
| 2299 return _length * bytesPerElement(); | |
| 2300 } | |
| 2301 | |
| 2302 ByteArray asByteArray([int start = 0, int length]) { | |
| 2303 if (length == null) { | |
| 2304 length = this.lengthInBytes(); | |
| 2305 } | |
| 2306 Arrays.rangeCheck(start, length); | |
| 2307 return _array.subByteArray(_offset + start, length); | |
| 2308 } | |
| 2309 | |
| 2310 final ByteArray _array; | |
| 2311 final int _offset; | |
| 2312 final int _length; | |
| 2313 } | |
| 2314 | |
| 2315 | |
| 2316 class _Float32ArrayView implements Float32Array { | |
| 2317 _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2318 : _array = array, | |
| 2319 _offset = offsetInBytes, | |
| 2320 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 2321 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2322 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2323 } | |
| 2324 int lengthInBytes = length * bytesPerElement(); | |
| 2325 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2326 throw new IndexOutOfRangeException(length); | |
| 2327 } | |
| 2328 } | |
| 2329 | |
| 2330 get length() { | |
| 2331 return _length; | |
| 2332 } | |
| 2333 | |
| 2334 double operator[](int index) { | |
| 2335 if (index < 0 || index >= _length) { | |
| 2336 throw new IndexOutOfRangeException(index); | |
| 2337 } | |
| 2338 return _array.getFloat32(_offset + (index * bytesPerElement())); | |
| 2339 } | |
| 2340 | |
| 2341 void operator[]=(int index, double value) { | |
| 2342 if (index < 0 || index >= _length) { | |
| 2343 throw new IndexOutOfRangeException(index); | |
| 2344 } | |
| 2345 _array.setFloat32(_offset + (index * bytesPerElement()), value); | |
| 2346 } | |
| 2347 | |
| 2348 Iterator<double> iterator() { | |
| 2349 return new _ByteArrayIterator<double>(this); | |
| 2350 } | |
| 2351 | |
| 2352 List<double> getRange(int start, int length) { | |
| 2353 Arrays.rangeCheck(this, start, length); | |
| 2354 Float32Array result = new Float32Array(length); | |
| 2355 result.setRange(0, length, this, start); | |
| 2356 return result; | |
| 2357 } | |
| 2358 | |
| 2359 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2360 Arrays.copy(from, startFrom, this, start, length); | |
| 2361 } | |
| 2362 | |
| 2363 void add(double value) { | |
| 2364 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2365 } | |
| 2366 | |
| 2367 void addLast(double value) { | |
| 2368 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2369 } | |
| 2370 | |
| 2371 void addAll(Collection<double> value) { | |
| 2372 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2373 } | |
| 2374 | |
| 2375 void clear() { | |
| 2376 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2377 } | |
| 2378 | |
| 2379 void insertRange(int start, int length, [initialValue]) { | |
| 2380 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2381 } | |
| 2382 | |
| 2383 set length(int newLength) { | |
| 2384 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 2385 } | |
| 2386 | |
| 2387 double removeLast() { | |
| 2388 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2389 } | |
| 2390 | |
| 2391 void removeRange(int start, int length) { | |
| 2392 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2393 } | |
| 2394 | |
| 2395 String toString() { | |
| 2396 return Collections.collectionToString(this); | |
| 2397 } | |
| 2398 | |
| 2399 int bytesPerElement() { | |
| 2400 return 4; | |
| 2401 } | |
| 2402 | |
| 2403 int lengthInBytes() { | |
| 2404 return _length * bytesPerElement(); | |
| 2405 } | |
| 2406 | |
| 2407 ByteArray asByteArray([int start = 0, int length]) { | |
| 2408 if (length == null) { | |
| 2409 length = this.lengthInBytes(); | |
| 2410 } | |
| 2411 Arrays.rangeCheck(start, length); | |
| 2412 return _array.subByteArray(_offset + start, length); | |
| 2413 } | |
| 2414 | |
| 2415 final ByteArray _array; | |
| 2416 final int _offset; | |
| 2417 final int _length; | |
| 2418 } | |
| 2419 | |
| 2420 class _Float64ArrayView implements Float64Array { | |
| 2421 _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length]) | |
| 2422 : _array = array, | |
| 2423 _offset = offsetInBytes, | |
| 2424 _length = (length === null) ? (array.lengthInBytes() - offsetInBytes) : le ngth { | |
| 2425 if (offsetInBytes < 0 || offsetInBytes >= array.lengthInBytes()) { | |
| 2426 throw new IndexOutOfRangeException(offsetInBytes); | |
| 2427 } | |
| 2428 int lengthInBytes = length * bytesPerElement(); | |
| 2429 if (length < 0 || (lengthInBytes + _offset) > array.lengthInBytes()) { | |
| 2430 throw new IndexOutOfRangeException(length); | |
| 2431 } | |
| 2432 } | |
| 2433 | |
| 2434 get length() { | |
| 2435 return _length; | |
| 2436 } | |
| 2437 | |
| 2438 double operator[](int index) { | |
| 2439 if (index < 0 || index >= _length) { | |
| 2440 throw new IndexOutOfRangeException(index); | |
| 2441 } | |
| 2442 return _array.getFloat64(_offset + (index * bytesPerElement())); | |
| 2443 } | |
| 2444 | |
| 2445 void operator[]=(int index, double value) { | |
| 2446 if (index < 0 || index >= _length) { | |
| 2447 throw new IndexOutOfRangeException(index); | |
| 2448 } | |
| 2449 _array.setFloat64(_offset + (index * bytesPerElement()), value); | |
| 2450 } | |
| 2451 | |
| 2452 Iterator<double> iterator() { | |
| 2453 return new _ByteArrayIterator<double>(this); | |
| 2454 } | |
| 2455 | |
| 2456 List<double> getRange(int start, int length) { | |
| 2457 Arrays.rangeCheck(this, start, length); | |
| 2458 Float64Array result = new Float64Array(length); | |
| 2459 result.setRange(0, length, this, start); | |
| 2460 return result; | |
| 2461 } | |
| 2462 | |
| 2463 void setRange(int start, int length, List<double> from, [int startFrom = 0]) { | |
| 2464 Arrays.copy(from, startFrom, this, start, length); | |
| 2465 } | |
| 2466 | |
| 2467 void add(double value) { | |
| 2468 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2469 } | |
| 2470 | |
| 2471 void addLast(double value) { | |
| 2472 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2473 } | |
| 2474 | |
| 2475 void addAll(Collection<double> value) { | |
| 2476 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2477 } | |
| 2478 | |
| 2479 void clear() { | |
| 2480 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2481 } | |
| 2482 | |
| 2483 void insertRange(int start, int length, [initialValue]) { | |
| 2484 throw const UnsupportedOperationException("Cannot add to a non-extendable ar ray"); | |
| 2485 } | |
| 2486 | |
| 2487 set length(int newLength) { | |
| 2488 throw const UnsupportedOperationException("Cannot resize a non-extendable ar ray"); | |
| 2489 } | |
| 2490 | |
| 2491 double removeLast() { | |
| 2492 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2493 } | |
| 2494 | |
| 2495 void removeRange(int start, int length) { | |
| 2496 throw const UnsupportedOperationException("Cannot remove from a non-extendab le array"); | |
| 2497 } | |
| 2498 | |
| 2499 String toString() { | |
| 2500 return Collections.collectionToString(this); | |
| 2501 } | |
| 2502 | |
| 2503 int bytesPerElement() { | |
| 2504 return 8; | |
| 2505 } | |
| 2506 | |
| 2507 int lengthInBytes() { | |
| 2508 return _length * bytesPerElement(); | |
| 2509 } | |
| 2510 | |
| 2511 ByteArray asByteArray([int start = 0, int length]) { | |
| 2512 if (length == null) { | |
| 2513 length = this.lengthInBytes(); | |
| 2514 } | |
| 2515 Arrays.rangeCheck(start, length); | |
| 2516 return _array.subByteArray(_offset + start, length); | |
| 2517 } | |
| 2518 | |
| 2519 final ByteArray _array; | |
| 2520 final int _offset; | |
| 2521 final int _length; | |
| 2522 } | |
| OLD | NEW |