1 package com.mockobjects; 2 3 7 8 9 class HashSet extends java.util.Vector { 10 11 14 public HashSet() { 15 super(); 16 } 17 18 22 public HashSet(int initialCapacity) { 23 super(initialCapacity); 24 } 25 26 31 public HashSet(int initialCapacity, int capacityIncrement) { 32 super(initialCapacity, capacityIncrement); 33 } 34 35 public void add(Object 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 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 [] toArray(Object [] 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 |