1 import org.aswing.utils.ListNode;
2 import org.aswing.utils.ObjectUtils;
3
4
5
6
7
8
12 class org.aswing.utils.List{
13
14
17 private var head:ListNode;
18
21 private var tail:ListNode;
22
25 private var current:ListNode;
26
27
30 private var count:Number;
31
32
33
34 public function List(){
35 this.count = 0;
36 this.head = null;
37 this.tail = null;
38 }
39
40
41 public function size():Number{
42 return this.count;
43 }
44
45 public function getHead():ListNode{
46 return this.head;
47 }
48
49 public function getTail():ListNode{
50 return this.tail;
51 }
52
53 public function append(data:Object):Void{
54 if(this.size() == 0){
55 this.setFirstNode(data);
56 return;
57 }
58
59 var newNode:ListNode = new ListNode(data , this.tail , null);
60 this.tail.setNextNode(newNode);
61 this.tail = newNode;
62 this.count += 1;
63 }
64
65 public function prepend(data:Object):Void{
66 if(this.size() == 0){
67 this.setFirstNode(data);
68 return;
69 }
70 var newNode:ListNode = new ListNode(data , null , this.head);
71 this.head.setPreNode(newNode);
72 this.head = newNode;
73 this.count += 1;
74 }
75
76 private function setFirstNode(data:Object):Void{
77 var newNode:ListNode = new ListNode(data , null , null);
78 this.head = newNode;
79 this.tail = newNode;
80 this.count = 1;
81 }
82
83
84 public static function clone(existList:List):List{
85 if(existList == null){
86 return null;
87 }
88 if(existList.size() <= 0){
89 return null;
90 }
91 var list:List = new List();
92 var loopNode:ListNode = existList.getHead();
93 while(loopNode != null){
94 list.append(ObjectUtils.baseClone(loopNode.getData()));
95 loopNode = loopNode.getNextNode();
96 }
97 return list;
98 }
99
100
101 }