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 extends List default _InternalByteArray { |
6 ByteArray(int length); | 6 ByteArray(int length); |
7 | 7 |
8 int get length(); | 8 int get length(); |
9 | 9 |
10 int getInt8(int byteOffset); | 10 int getInt8(int byteOffset); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return Collections.some(this, f); | 89 return Collections.some(this, f); |
90 } | 90 } |
91 | 91 |
92 // List interface | 92 // List interface |
93 | 93 |
94 int operator[](int index) { | 94 int operator[](int index) { |
95 return getUint8(index); | 95 return getUint8(index); |
96 } | 96 } |
97 | 97 |
98 void operator[]=(int index, int value) { | 98 void operator[]=(int index, int value) { |
99 setUint8(index, value); | 99 if (value is int && value >= 0 && value <= 255) { |
100 setUint8(index, value); | |
101 } else { | |
102 throw const IllegalArgumentException( | |
103 "value is not an integer in byte range"); | |
Søren Gjesse
2012/02/01 08:16:08
"in byte range" -> "in the byte range"
Start mess
Anders Johnsen
2012/02/01 18:54:53
Done.
| |
104 } | |
100 } | 105 } |
101 | 106 |
102 void set length(int newLength) { | 107 void set length(int newLength) { |
103 throw const UnsupportedOperationException("Cannot add to a byte array"); | 108 throw const UnsupportedOperationException("Cannot add to a byte array"); |
104 } | 109 } |
105 | 110 |
106 void add(int element) { | 111 void add(int element) { |
107 throw const UnsupportedOperationException("Cannot add to a byte array"); | 112 throw const UnsupportedOperationException("Cannot add to a byte array"); |
108 } | 113 } |
109 | 114 |
(...skipping 24 matching lines...) Expand all Loading... | |
134 | 139 |
135 int removeLast() { | 140 int removeLast() { |
136 throw const UnsupportedOperationException( | 141 throw const UnsupportedOperationException( |
137 "Cannot remove from a byte array"); | 142 "Cannot remove from a byte array"); |
138 } | 143 } |
139 | 144 |
140 int last() { | 145 int last() { |
141 return this[length - 1]; | 146 return this[length - 1]; |
142 } | 147 } |
143 | 148 |
149 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
150 if (length < 0) { | |
151 throw new IllegalArgumentException("negative length $length"); | |
152 } | |
153 if (from is ByteArray) { | |
154 _setRange(start, length, from, startFrom); | |
155 } else { | |
156 Arrays.copy(from, startFrom, this, start, length); | |
157 } | |
158 } | |
159 | |
160 List getRange(int start, int length) { | |
161 if (length == 0) return []; | |
162 Arrays.rangeCheck(this, start, length); | |
163 ByteArray list = new ByteArray(length); | |
164 list._setRange(0, length, this, start); | |
165 return list; | |
166 } | |
167 | |
168 | |
144 // Implementation | 169 // Implementation |
145 | 170 |
146 int _length() native "ByteArray_getLength"; | 171 int _length() native "ByteArray_getLength"; |
172 | |
173 void _setRange(int start, | |
174 int length, | |
175 ByteArray from, | |
176 int startFrom) | |
Søren Gjesse
2012/02/01 08:16:08
I think the parameter list can fit on a single lin
Anders Johnsen
2012/02/01 18:54:53
Done.
| |
177 native "ByteArray_setRange"; | |
178 | |
147 } | 179 } |
148 | 180 |
149 | 181 |
150 class _ByteArrayIterator implements Iterator { | 182 class _ByteArrayIterator implements Iterator { |
151 _ByteArrayIterator(List byteArray) | 183 _ByteArrayIterator(List byteArray) |
152 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { | 184 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { |
153 assert(byteArray is ByteArray); | 185 assert(byteArray is ByteArray); |
154 } | 186 } |
155 | 187 |
156 bool hasNext() { | 188 bool hasNext() { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 | 512 |
481 void _setFloat32(int byteOffset, double value) | 513 void _setFloat32(int byteOffset, double value) |
482 native "ExternalByteArray_setFloat32"; | 514 native "ExternalByteArray_setFloat32"; |
483 | 515 |
484 double _getFloat64(int byteOffset) | 516 double _getFloat64(int byteOffset) |
485 native "ExternalByteArray_getFloat64"; | 517 native "ExternalByteArray_getFloat64"; |
486 | 518 |
487 void _setFloat64(int byteOffset, double value) | 519 void _setFloat64(int byteOffset, double value) |
488 native "ExternalByteArray_setFloat64"; | 520 native "ExternalByteArray_setFloat64"; |
489 } | 521 } |
OLD | NEW |