| 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 ListFactory { | 5 class ListFactory { |
| 6 factory List<E>.from(Iterable<E> other) { | 6 factory List<E>.from(Iterable<E> other) { |
| 7 if (other == null) { |
| 8 throw const NullPointerException(); |
| 9 } |
| 7 List<E> list = new List<E>(); | 10 List<E> list = new List<E>(); |
| 8 for (final e in other) { | 11 for (final e in other) { |
| 9 list.add(e); | 12 list.add(e); |
| 10 } | 13 } |
| 11 return list; | 14 return list; |
| 12 } | 15 } |
| 13 | 16 |
| 14 factory List<E>([int length = null]) { | 17 factory List<E>([int length = null]) { |
| 15 bool isFixed = true; | 18 bool isFixed = true; |
| 16 if (length === null) { | 19 if (length === null) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 170 |
| 168 void addLast(T element) { | 171 void addLast(T element) { |
| 169 add(element); | 172 add(element); |
| 170 } | 173 } |
| 171 | 174 |
| 172 void addAll(Collection<T> elements) { | 175 void addAll(Collection<T> elements) { |
| 173 if (_isFixed) { | 176 if (_isFixed) { |
| 174 throw const UnsupportedOperationException( | 177 throw const UnsupportedOperationException( |
| 175 "Cannot add to a non-extendable list"); | 178 "Cannot add to a non-extendable list"); |
| 176 } else { | 179 } else { |
| 180 if (elements == null) { |
| 181 throw const NullPointerException(); |
| 182 } |
| 177 for (final e in elements) { | 183 for (final e in elements) { |
| 178 _add(e); | 184 _add(e); |
| 179 } | 185 } |
| 180 } | 186 } |
| 181 } | 187 } |
| 182 | 188 |
| 183 void clear() { | 189 void clear() { |
| 184 if (_isFixed) { | 190 if (_isFixed) { |
| 185 throw const UnsupportedOperationException( | 191 throw const UnsupportedOperationException( |
| 186 "Cannot clear a non-extendable list"); | 192 "Cannot clear a non-extendable list"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 265 } |
| 260 | 266 |
| 261 static List _newList(int len) native { | 267 static List _newList(int len) native { |
| 262 return new List(len); | 268 return new List(len); |
| 263 } | 269 } |
| 264 | 270 |
| 265 static void _throwIndexOutOfRangeException(int index) native { | 271 static void _throwIndexOutOfRangeException(int index) native { |
| 266 throw new IndexOutOfRangeException(index); | 272 throw new IndexOutOfRangeException(index); |
| 267 } | 273 } |
| 268 } | 274 } |
| OLD | NEW |