OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class GrowableObjectArray<T> implements Array<T> { | 5 class GrowableObjectArray<T> implements List<T> { |
6 ObjectArray<T> backingArray; | 6 ObjectArray<T> backingArray; |
7 | 7 |
8 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { | 8 void copyFrom(List<Object> src, int srcStart, int dstStart, int count) { |
9 Arrays.copy(src, srcStart, this, dstStart, count); | 9 Arrays.copy(src, srcStart, this, dstStart, count); |
10 } | 10 } |
11 | 11 |
12 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { | 12 void setRange(int start, int length, List<T> from, [int startFrom = 0]) { |
13 if (length < 0) { | 13 if (length < 0) { |
14 throw new IllegalArgumentException("negative length $length"); | 14 throw new IllegalArgumentException("negative length $length"); |
15 } | 15 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 : _length = 0, backingArray = new ObjectArray<T>(4) {} | 80 : _length = 0, backingArray = new ObjectArray<T>(4) {} |
81 | 81 |
82 GrowableObjectArray.withCapacity(int capacity) { | 82 GrowableObjectArray.withCapacity(int capacity) { |
83 _length = 0; | 83 _length = 0; |
84 if (capacity <= 0) { | 84 if (capacity <= 0) { |
85 capacity = 4; | 85 capacity = 4; |
86 } | 86 } |
87 backingArray = new ObjectArray<T>(capacity); | 87 backingArray = new ObjectArray<T>(capacity); |
88 } | 88 } |
89 | 89 |
90 GrowableObjectArray._usingArray(Array<T> array) { | 90 GrowableObjectArray._usingArray(List<T> array) { |
91 backingArray = array; | 91 backingArray = array; |
92 _length = array.length; | 92 _length = array.length; |
93 if (_length == 0) { | 93 if (_length == 0) { |
94 grow(4); | 94 grow(4); |
95 } | 95 } |
96 } | 96 } |
97 | 97 |
98 factory GrowableObjectArray.from(Collection<T> other) { | 98 factory GrowableObjectArray.from(Collection<T> other) { |
99 Array result = new GrowableObjectArray(); | 99 List result = new GrowableObjectArray(); |
100 result.addAll(other); | 100 result.addAll(other); |
101 return result; | 101 return result; |
102 } | 102 } |
103 | 103 |
104 int get length() { | 104 int get length() { |
105 return _length; | 105 return _length; |
106 } | 106 } |
107 | 107 |
108 void set length(int new_length) { | 108 void set length(int new_length) { |
109 if (new_length >= backingArray.length) { | 109 if (new_length >= backingArray.length) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 if (!hasNext()) { | 233 if (!hasNext()) { |
234 throw const NoMoreElementsException(); | 234 throw const NoMoreElementsException(); |
235 } | 235 } |
236 return _array[_pos++]; | 236 return _array[_pos++]; |
237 } | 237 } |
238 | 238 |
239 final GrowableObjectArray<T> _array; | 239 final GrowableObjectArray<T> _array; |
240 int _pos; | 240 int _pos; |
241 } | 241 } |
242 | 242 |
OLD | NEW |