| 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 LinkFactory { | 5 // TODO(regis): Move type parameter <T> from the class declaration to the |
| 6 // factory declarations after the new factory syntax is implemented. |
| 7 // See issues 226, 5257789, 5408808. |
| 8 class LinkFactory<T> { |
| 6 factory Link(head, [Link tail]) { | 9 factory Link(head, [Link tail]) { |
| 7 return new LinkEntry(head, (tail === null) ? const LinkTail() : tail); | 10 return new LinkEntry(head, (tail === null) ? const LinkTail() : tail); |
| 8 } | 11 } |
| 9 | 12 |
| 10 factory Link.fromList(List list) { | 13 factory Link.fromList(List list) { |
| 11 switch (list.length) { | 14 switch (list.length) { |
| 12 case 0: | 15 case 0: |
| 13 return const LinkTail(); | 16 return const LinkTail(); |
| 14 case 1: | 17 case 1: |
| 15 return new Link(list[0]); | 18 return new Link(list[0]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 } | 30 } |
| 28 | 31 |
| 29 class AbstractLink<T> implements Link<T> { | 32 class AbstractLink<T> implements Link<T> { |
| 30 T get head() { throw "bug"; } // TODO(ahe): Work around VM bug. | 33 T get head() { throw "bug"; } // TODO(ahe): Work around VM bug. |
| 31 T get tail() { throw "bug"; } // TODO(ahe): Work around VM bug. | 34 T get tail() { throw "bug"; } // TODO(ahe): Work around VM bug. |
| 32 abstract List<T> toList(); // TODO(ahe): Work around Frog bug #318. | 35 abstract List<T> toList(); // TODO(ahe): Work around Frog bug #318. |
| 33 abstract bool isEmpty(); // TODO(ahe): Work around Frog bug #318. | 36 abstract bool isEmpty(); // TODO(ahe): Work around Frog bug #318. |
| 34 | 37 |
| 35 const AbstractLink(); | 38 const AbstractLink(); |
| 36 | 39 |
| 37 Link prepend(T element) { | 40 Link<T> prepend(T element) { |
| 38 return new Link(element, this); | 41 return new Link<T>(element, this); |
| 39 } | 42 } |
| 40 | 43 |
| 41 Iterator<T> iterator() => toList().iterator(); | 44 Iterator<T> iterator() => toList().iterator(); |
| 42 | 45 |
| 43 void printOn(StringBuffer buffer, [separatedBy]) { | 46 void printOn(StringBuffer buffer, [separatedBy]) { |
| 44 if (isEmpty()) return; | 47 if (isEmpty()) return; |
| 45 // TODO(ngeofray): Work around Frog bug | 48 // TODO(ngeofray): Work around Frog bug |
| 46 buffer.add(head === null ? 'null' : head); | 49 buffer.add(head === null ? 'null' : head); |
| 47 if (separatedBy === null) separatedBy = ''; | 50 if (separatedBy === null) separatedBy = ''; |
| 48 for (Link link = tail; !link.isEmpty(); link = link.tail) { | 51 for (Link link = tail; !link.isEmpty(); link = link.tail) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void addLast(T t) { | 118 void addLast(T t) { |
| 116 LinkEntry<T> entry = new LinkEntry<T>(t, null); | 119 LinkEntry<T> entry = new LinkEntry<T>(t, null); |
| 117 if (head === null) { | 120 if (head === null) { |
| 118 head = entry; | 121 head = entry; |
| 119 } else { | 122 } else { |
| 120 lastLink.realTail = entry; | 123 lastLink.realTail = entry; |
| 121 } | 124 } |
| 122 lastLink = entry; | 125 lastLink = entry; |
| 123 } | 126 } |
| 124 } | 127 } |
| OLD | NEW |