| OLD | NEW |
| 1 // -- start List<$E> mixins. | 1 // -- start List<$E> mixins. |
| 2 // $E is the element type. | 2 // $E is the element type. |
| 3 | 3 |
| 4 $if DEFINE_LENGTH_AS_NUM_ITEMS | 4 $if DEFINE_LENGTH_AS_NUM_ITEMS |
| 5 // SVG Collections expose numberOfItems rather than length. | 5 // SVG Collections expose numberOfItems rather than length. |
| 6 int get length => numberOfItems; | 6 int get length => numberOfItems; |
| 7 $endif | 7 $endif |
| 8 | 8 |
| 9 $if DEFINE_LENGTH_SETTER | 9 $if DEFINE_LENGTH_SETTER |
| 10 void set length(int value) { | 10 void set length(int value) { |
| 11 throw new UnsupportedError("Cannot resize immutable List."); | 11 throw new UnsupportedError("Cannot resize immutable List."); |
| 12 } | 12 } |
| 13 $endif | 13 $endif |
| 14 | 14 |
| 15 $E get first { |
| 16 if (this.length > 0) { |
| 17 $if DART2JS |
| 18 return JS('$E', '#[0]', this); |
| 19 $else |
| 20 return this[0]; |
| 21 $endif |
| 22 } |
| 23 throw new StateError("No elements"); |
| 24 } |
| 25 |
| 26 $E get last { |
| 27 int len = this.length; |
| 28 if (len > 0) { |
| 29 $if DART2JS |
| 30 return JS('$E', '#[#]', this, len - 1); |
| 31 $else |
| 32 return this[len - 1]; |
| 33 $endif |
| 34 } |
| 35 throw new StateError("No elements"); |
| 36 } |
| 37 |
| 38 $E get single { |
| 39 int len = this.length; |
| 40 if (len == 1) { |
| 41 $if DART2JS |
| 42 return JS('$E', '#[0]', this); |
| 43 $else |
| 44 return this[0]; |
| 45 $endif |
| 46 } |
| 47 if (len == 0) throw new StateError("No elements"); |
| 48 throw new StateError("More than one element"); |
| 49 } |
| 50 |
| 51 $E elementAt(int index) => this[index]; |
| 15 // -- end List<$E> mixins. | 52 // -- end List<$E> mixins. |
| OLD | NEW |