HashSet is an implementation of a Set. All optional operations (adding and removing) are supported. The elements can be any objects.
| 24 | * removing) are supported. The elements can be any objects. |
| 25 | */ |
| 26 | public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, |
| 27 | Serializable { |
| 28 | |
| 29 | private static final long serialVersionUID = -5024744406713321676L; |
| 30 | |
| 31 | transient HashMap<E, HashSet<E>> backingMap; |
| 32 | |
| 33 | /** |
| 34 | * Constructs a new empty instance of {@code HashSet}. |
| 35 | */ |
| 36 | public HashSet() { |
| 37 | this(new HashMap<E, HashSet<E>>()); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Constructs a new instance of {@code HashSet} with the specified capacity. |
| 42 | * |
| 43 | * @param capacity |
| 44 | * the initial capacity of this {@code HashSet}. |
| 45 | */ |
| 46 | public HashSet(int capacity) { |
| 47 | this(new HashMap<E, HashSet<E>>(capacity)); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Constructs a new instance of {@code HashSet} with the specified capacity |
| 52 | * and load factor. |
| 53 | * |
| 54 | * @param capacity |
| 55 | * the initial capacity. |
| 56 | * @param loadFactor |
| 57 | * the initial load factor. |
| 58 | */ |
| 59 | public HashSet(int capacity, float loadFactor) { |
| 60 | this(new HashMap<E, HashSet<E>>(capacity, loadFactor)); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Constructs a new instance of {@code HashSet} containing the unique |
| 65 | * elements in the specified collection. |
| 66 | * |
| 67 | * @param collection |
| 68 | * the collection of elements to add. |
| 69 | */ |
| 70 | public HashSet(Collection<? extends E> collection) { |
| 71 | this(new HashMap<E, HashSet<E>>(collection.size() < 6 ? 11 : collection |
| 72 | .size() * 2)); |
| 73 | for (E e : collection) { |
| 74 | add(e); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | HashSet(HashMap<E, HashSet<E>> backingMap) { |
| 79 | this.backingMap = backingMap; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Adds the specified object to this {@code HashSet} if not already present. |
nothing calls this directly
no outgoing calls
no test coverage detected