Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** A reusable set used to identify cyclic lists during toString() calls. */ | 7 /** A reusable set used to identify cyclic lists during toString() calls. */ |
| 8 Set _toStringVisiting = new HashSet.identity(); | 8 Set _toStringVisiting = new HashSet.identity(); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 74 } |
| 75 | 75 |
| 76 E get single { | 76 E get single { |
| 77 if (length == 0) throw new StateError("No elements"); | 77 if (length == 0) throw new StateError("No elements"); |
| 78 if (length > 1) throw new StateError("Too many elements"); | 78 if (length > 1) throw new StateError("Too many elements"); |
| 79 return this[0]; | 79 return this[0]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 bool contains(Object element) { | 82 bool contains(Object element) { |
| 83 int length = this.length; | 83 int length = this.length; |
| 84 for (int i = 0; i < length; i++) { | 84 for (int i = 0; i < this.length; i++) { |
| 85 if (this[i] == element) return true; | 85 if (this[i] == element) return true; |
| 86 if (length != this.length) { | 86 if (length != this.length) { |
| 87 throw new ConcurrentModificationError(this); | 87 throw new ConcurrentModificationError(this); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool every(bool test(E element)) { | 93 bool every(bool test(E element)) { |
| 94 int length = this.length; | 94 int length = this.length; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 153 } |
| 154 if (length != this.length) { | 154 if (length != this.length) { |
| 155 throw new ConcurrentModificationError(this); | 155 throw new ConcurrentModificationError(this); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 if (matchFound) return match; | 158 if (matchFound) return match; |
| 159 throw new StateError("No matching element"); | 159 throw new StateError("No matching element"); |
| 160 } | 160 } |
| 161 | 161 |
| 162 String join([String separator = ""]) { | 162 String join([String separator = ""]) { |
| 163 int length = this.length; | 163 if (this.length == 0) return ""; |
| 164 if (!separator.isEmpty) { | 164 StringBuffer buffer = new StringBuffer(); |
| 165 if (length == 0) return ""; | 165 if (separator.isEmpty) { |
|
Lasse Reichstein Nielsen
2014/02/05 10:41:00
Just checked the StringBuffer code: This "if" isn'
vicb
2014/02/06 12:42:22
Indeed. Thank for the tip.
| |
| 166 String first = "${this[0]}"; | 166 buffer.writeAll(this); |
| 167 if (length != this.length) { | |
| 168 throw new ConcurrentModificationError(this); | |
| 169 } | |
| 170 StringBuffer buffer = new StringBuffer(first); | |
| 171 for (int i = 1; i < length; i++) { | |
| 172 buffer.write(separator); | |
| 173 buffer.write(this[i]); | |
| 174 if (length != this.length) { | |
| 175 throw new ConcurrentModificationError(this); | |
| 176 } | |
| 177 } | |
| 178 return buffer.toString(); | |
| 179 } else { | 167 } else { |
| 180 StringBuffer buffer = new StringBuffer(); | 168 buffer.writeAll(this, separator); |
| 181 for (int i = 0; i < length; i++) { | |
| 182 buffer.write(this[i]); | |
| 183 if (length != this.length) { | |
| 184 throw new ConcurrentModificationError(this); | |
| 185 } | |
| 186 } | |
| 187 return buffer.toString(); | |
| 188 } | 169 } |
| 170 return buffer.toString(); | |
| 189 } | 171 } |
| 190 | 172 |
| 191 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); | 173 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); |
| 192 | 174 |
| 193 Iterable map(f(E element)) => new MappedListIterable(this, f); | 175 Iterable map(f(E element)) => new MappedListIterable(this, f); |
| 194 | 176 |
| 195 Iterable expand(Iterable f(E element)) => | 177 Iterable expand(Iterable f(E element)) => |
| 196 new ExpandIterable<E, dynamic>(this, f); | 178 new ExpandIterable<E, dynamic>(this, f); |
| 197 | 179 |
| 198 E reduce(E combine(E previousValue, E element)) { | 180 E reduce(E combine(E previousValue, E element)) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 result.write('['); | 517 result.write('['); |
| 536 result.writeAll(this, ', '); | 518 result.writeAll(this, ', '); |
| 537 result.write(']'); | 519 result.write(']'); |
| 538 } finally { | 520 } finally { |
| 539 _toStringVisiting.remove(this); | 521 _toStringVisiting.remove(this); |
| 540 } | 522 } |
| 541 | 523 |
| 542 return result.toString(); | 524 return result.toString(); |
| 543 } | 525 } |
| 544 } | 526 } |
| OLD | NEW |