KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > ArrayList


1 package com.mockobjects;
2
3 /*
4  * TYPE TO PROVIDE VERY BASIC ARRAYLIST IMPLEMENTATION TO BRIDGE GAP BETWEEN
5  * JDK1.1.7 and JDK 1.2
6  */

7
8
9 class ArrayList extends java.util.Vector JavaDoc {
10
11     /**
12      * ArrayList constructor comment.
13      */

14     public ArrayList() {
15         super();
16     }
17
18     /**
19      * ArrayList constructor comment.
20      * @param initialCapacity int
21      */

22     public ArrayList(int initialCapacity) {
23         super(initialCapacity);
24     }
25
26     /**
27      * ArrayList constructor comment.
28      * @param initialCapacity int
29      * @param capacityIncrement int
30      */

31     public ArrayList(int initialCapacity, int capacityIncrement) {
32         super(initialCapacity, capacityIncrement);
33     }
34
35     public void add(Object JavaDoc item) {
36         super.addElement(item);
37     }
38
39     public void clear() {
40         super.removeAllElements();
41     }
42
43     public boolean equals(ArrayList list) {
44         if (size() != list.size())
45             return false;
46
47         for (int i = 0; i < size(); i++) {
48             if (!this.elementAt(i).equals(list.elementAt(i)))
49                 return false;
50         }
51         return true;
52     }
53
54     public boolean equals(Object JavaDoc obj) {
55         if(obj instanceof ArrayList)
56             return equals((ArrayList)obj);
57         else
58             return false;
59     }
60
61     public Object JavaDoc get(int index) {
62         return super.elementAt(index);
63     }
64
65     public Iterator iterator() {
66         return new Iterator(this);
67     }
68
69     public Object JavaDoc[] toArray(Object JavaDoc[] result) {
70         for(int i=0;i<this.size();i++) {
71             result[i] = this.elementAt(i);
72         }
73
74         return result;
75     }
76 }
77
Popular Tags