samer@0
|
1 package samer.silk;
|
samer@0
|
2 import java.util.*;
|
samer@0
|
3 import jscheme.*;
|
samer@0
|
4
|
samer@0
|
5 public class SchemeList extends AbstractSequentialList {
|
samer@0
|
6 SchemePair head;
|
samer@0
|
7
|
samer@0
|
8 public SchemeList(SchemePair pair) { head=pair; }
|
samer@0
|
9
|
samer@0
|
10 public ListIterator listIterator(int index) {
|
samer@0
|
11 return new Iterator(head,index);
|
samer@0
|
12 }
|
samer@0
|
13
|
samer@0
|
14 public int size() {
|
samer@0
|
15 int i=0;
|
samer@0
|
16 for (SchemePair p=head; !p.isEmpty(); p=(SchemePair)p.getRest()) i++;
|
samer@0
|
17 return i;
|
samer@0
|
18 }
|
samer@0
|
19
|
samer@0
|
20 class Iterator implements ListIterator {
|
samer@0
|
21 SchemePair current, previous=null;
|
samer@0
|
22 int index=0;
|
samer@0
|
23
|
samer@0
|
24 public Iterator(SchemePair head, int index) {
|
samer@0
|
25 current=head;
|
samer@0
|
26 for (int i=0; i<index; i++) next();
|
samer@0
|
27 }
|
samer@0
|
28
|
samer@0
|
29 public void add(Object o) {
|
samer@0
|
30 if (previous==null) no();
|
samer@0
|
31 current=new jsint.Pair(o,current);
|
samer@0
|
32 previous.setRest(current);
|
samer@0
|
33 }
|
samer@0
|
34
|
samer@0
|
35 public void remove() { no(); }
|
samer@0
|
36 // if (previous==null) no();
|
samer@0
|
37 // previous.setRest(current.getRest());
|
samer@0
|
38 // current=(SchemePair)current.getRest();
|
samer@0
|
39 // }
|
samer@0
|
40
|
samer@0
|
41 public void set(Object o) { previous.setFirst(o); }
|
samer@0
|
42
|
samer@0
|
43 public boolean hasNext() {
|
samer@0
|
44 return !current.isEmpty();
|
samer@0
|
45 }
|
samer@0
|
46
|
samer@0
|
47 public Object next() {
|
samer@0
|
48 Object rc=current.getFirst();
|
samer@0
|
49 previous=current;
|
samer@0
|
50 current=(SchemePair)current.getRest();
|
samer@0
|
51 index++;
|
samer@0
|
52 return rc;
|
samer@0
|
53 }
|
samer@0
|
54
|
samer@0
|
55 public int nextIndex() { return index; }
|
samer@0
|
56 public boolean hasPrevious() { no(); return false; }
|
samer@0
|
57 public Object previous() { no(); return null; }
|
samer@0
|
58 public int previousIndex() { no(); return 0; }
|
samer@0
|
59
|
samer@0
|
60 private void no() { throw new Error("Unsupported"); }
|
samer@0
|
61 }
|
samer@0
|
62 }
|