package java.util; public class HashSet implements Set { private static final Object Value = new Object(); private final HashMap map; public HashSet(int capacity) { map = new HashMap(capacity); } public HashSet() { this(0); } public int size() { return map.size(); } public boolean contains(T element) { return map.containsKey(element); } public boolean add(T element) { return map.put(element, Value) != Value; } public boolean remove(T element) { return map.remove(element) != Value; } public void clear() { map.clear(); } public Iterator iterator() { return new MyIterator(map.iterator()); } private static class MyIterator implements Iterator { private final Iterator> it; public MyIterator(Iterator> it) { this.it = it; } public T next() { return it.next().getKey(); } public boolean hasNext() { return it.hasNext(); } public void remove() { it.remove(); } } }