OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "dart:collection"; | 5 import "dart:collection"; |
6 | 6 |
7 abstract class Link<T> extends IterableBase<T> { | 7 abstract class Link<T> extends IterableBase<T> { |
8 // does not match constructor for LinkFactory | 8 // does not match constructor for LinkFactory |
9 factory Link(T head, [Link<T> tail]) = LinkFactory<T>; //# static type warning | 9 factory Link(T head, [Link<T> tail]) = LinkFactory<T>; //# static type warning |
10 Link<T> prepend(T element); | 10 Link<T> prepend(T element); |
11 } | 11 } |
12 | 12 |
13 abstract class EmptyLink<T> extends Link<T> { | 13 abstract class EmptyLink<T> extends Link<T> { |
14 const factory EmptyLink() = LinkTail<T>; | 14 const factory EmptyLink() = LinkTail<T>; |
15 } | 15 } |
16 | 16 |
17 class LinkFactory<T> { | 17 class LinkFactory<T> { |
18 factory LinkFactory(head, [Link tail]) { } | 18 factory LinkFactory(head, [Link tail]) {} |
19 } | 19 } |
20 | 20 |
21 // Does not implement all of Iterable | 21 // Does not implement all of Iterable |
22 class AbstractLink<T> implements Link<T> { | 22 class AbstractLink<T> implements Link<T> { |
23 const AbstractLink(); | 23 const AbstractLink(); |
24 Link<T> prepend(T element) { | 24 Link<T> prepend(T element) { |
25 return new Link<T>(element, this); | 25 return new Link<T>(element, this); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 // Does not implement all of Iterable | 29 // Does not implement all of Iterable |
30 class LinkTail<T> extends AbstractLink<T> | 30 class LinkTail<T> extends AbstractLink<T> implements EmptyLink<T> { |
31 implements EmptyLink<T> { | |
32 const LinkTail(); | 31 const LinkTail(); |
33 } | 32 } |
34 | 33 |
35 // Does not implement all of Iterable | 34 // Does not implement all of Iterable |
36 class LinkEntry<T> extends AbstractLink<T> { | 35 class LinkEntry<T> extends AbstractLink<T> { |
37 LinkEntry(T head, Link<T> realTail); | 36 LinkEntry(T head, Link<T> realTail); |
38 } | 37 } |
39 | 38 |
40 class Fisk { | 39 class Fisk { |
41 // instantiation of abstract class | 40 // instantiation of abstract class |
42 Link<String> nodes = const EmptyLink(); // //# static type warning | 41 Link<String> nodes = const EmptyLink(); // //# static type warning |
43 } | 42 } |
44 | 43 |
45 main() { | 44 main() { |
46 new Fisk(); | 45 new Fisk(); |
47 // instantiation of abstract class | 46 // instantiation of abstract class |
48 new EmptyLink<String>().prepend('hest'); //# static type warning | 47 new EmptyLink<String>().prepend('hest'); //# static type warning |
49 // instantiation of abstract class | 48 // instantiation of abstract class |
50 const EmptyLink<String>().prepend('fisk'); //# static type warning | 49 const EmptyLink<String>().prepend('fisk'); //# static type warning |
51 } | 50 } |
52 | |
OLD | NEW |