| 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 part of dart2js.util; | 5 part of dart2js.util; |
| 6 | 6 |
| 7 class Link<T> { | 7 class Link<T> { |
| 8 T get head => null; | 8 T get head => null; |
| 9 Link<T> get tail => null; | 9 Link<T> get tail => null; |
| 10 | 10 |
| 11 factory Link.fromList(List<T> list) { | |
| 12 switch (list.length) { | |
| 13 case 0: | |
| 14 return new Link<T>(); | |
| 15 case 1: | |
| 16 return new LinkEntry<T>(list[0]); | |
| 17 case 2: | |
| 18 return new LinkEntry<T>(list[0], new LinkEntry<T>(list[1])); | |
| 19 case 3: | |
| 20 return new LinkEntry<T>( | |
| 21 list[0], new LinkEntry<T>(list[1], new LinkEntry<T>(list[2]))); | |
| 22 } | |
| 23 Link link = new Link<T>(); | |
| 24 for (int i = list.length ; i > 0; i--) { | |
| 25 link = link.prepend(list[i - 1]); | |
| 26 } | |
| 27 return link; | |
| 28 } | |
| 29 | |
| 30 const Link(); | 11 const Link(); |
| 31 | 12 |
| 32 Link<T> prepend(T element) { | 13 Link<T> prepend(T element) { |
| 33 return new LinkEntry<T>(element, this); | 14 return new LinkEntry<T>(element, this); |
| 34 } | 15 } |
| 35 | 16 |
| 36 Iterator<T> get iterator => new LinkIterator<T>(this); | 17 Iterator<T> get iterator => new LinkIterator<T>(this); |
| 37 | 18 |
| 38 void printOn(StringBuffer buffer, [separatedBy]) { | 19 void printOn(StringBuffer buffer, [separatedBy]) { |
| 39 } | 20 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 * Prepends all elements added to the builder to [tail]. The resulting list is | 104 * Prepends all elements added to the builder to [tail]. The resulting list is |
| 124 * returned and the builder is cleared. | 105 * returned and the builder is cleared. |
| 125 */ | 106 */ |
| 126 Link<T> toLink([Link<T> tail = const Link()]); | 107 Link<T> toLink([Link<T> tail = const Link()]); |
| 127 | 108 |
| 128 void addLast(T t); | 109 void addLast(T t); |
| 129 | 110 |
| 130 final int length; | 111 final int length; |
| 131 final bool isEmpty; | 112 final bool isEmpty; |
| 132 } | 113 } |
| OLD | NEW |