1 package antlr.collections;
2
3 import antlr.collections.List;
4 import antlr.collections.impl.LList;
5 import java.util.Enumeration;
6 import java.util.NoSuchElementException;
7
8 public class LListTest {
9
10
11 public static void main(String[] args) {
12 LList l = new LList();
14 List list = l;
15 list.add("Hi there");
16 list.add("Frank");
17 list.add("Zappa");
18 list.add(new Integer(4));
19
20 if ( list.length()!=4 )
22 System.out.println("incorrect length");
23 else
24 System.out.println("correct: length is 4");
25
26 Enumeration e = l.elements();
28 for (; e.hasMoreElements();) {
29 System.out.println(e.nextElement());
30 }
31
32 if ( list.includes("Frank") )
34 System.out.println("correct: contains Frank");
35 else
36 System.out.println("incorrect: does not contain Frank");
37
38 Object o;
40 o = list.elementAt(2);
41 System.out.println("elementAt(2) replies: "+o);
42 try {
43 o = list.elementAt(200);
44 System.out.println("elementAt(200) replies: "+o);
45 } catch (NoSuchElementException ex) {
46 System.out.println("correct: no such element: 200");
47 }
48 }
49 }
50