KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > HashSet


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

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

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

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

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