T - the type of elements in the setpublic class KeyEntryHashSet<T> extends AbstractCollection<T>
KeyEntry objects where the key is
a specified input element. For this purpose, these objects should redefine
the Object.equals(Object) and Object.hashCode() methods accordingly. A
factory for producing KeyEntry objects from the elements should be
provided during construction of this collection.
The main method provided is merging a entry into collection, which returns an
equal element from the collection, if there is one (according to the
specified way to compare elements), or, otherwise, inserts the input element
into the collection returning itself. Other methods include finding an
element in the collection that is equal to the given one, deleting such an
element from the collection, if found, and iterating over the entries.| Modifier and Type | Field and Description |
|---|---|
protected EntryHashSet<KeyEntry<T,? extends T>> |
entryHashSet
The underlying entry collection used to back this collection
|
protected KeyEntryFactory<T> |
keyEntryFactory
The factory used for wrapping keys into entries
|
| Constructor and Description |
|---|
KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory)
Create an empty set associated with a given factory for creating
KeyEntry wrapper objects. |
KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory,
int initialCapacity)
Create an empty set associated with a given factory for creating
KeyEntry wrapper objects and with the given initial capacity. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T key) |
void |
clear() |
T |
get(T key)
Retrieves the element in the set that is equal to the given object, if it
exists, or returns null otherwise.
|
Iterator<T> |
iterator() |
T |
merge(T key)
Get the element in set that is equal to the input entry if there is one,
or otherwise insert the given entry into the set and return itself.
|
boolean |
remove(Object o) |
T |
removeEntry(T key)
Removes and returns the element in the set that is equal to the input
element.
|
int |
size() |
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCodeprotected final KeyEntryFactory<T> keyEntryFactory
protected final EntryHashSet<KeyEntry<T,? extends T>> entryHashSet
public KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory, int initialCapacity)
KeyEntry wrapper objects and with the given initial capacity. The
set will be resized as necessary to accommodate new elements.keyEntryFactory - factory for creating KeyEntry wrapper objectsinitialCapacity - the estimatedpublic KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory)
KeyEntry wrapper objects.keyEntryFactory - public T merge(T key)
KeyEntry objects using the factory.key - the element to be merged into the setpublic boolean add(T key)
add in interface Collection<T>add in class AbstractCollection<T>public T get(T key)
KeyEntry objects using the
factory.key - the object that is used for finding the entrypublic T removeEntry(T key)
KeyEntry
objects using the factory.key - the element that is used for finding the element to removenull if no element that is equal
to the given one is foundpublic boolean remove(Object o)
remove in interface Collection<T>remove in class AbstractCollection<T>public void clear()
clear in interface Collection<T>clear in class AbstractCollection<T>public int size()
size in interface Collection<T>size in class AbstractCollection<T>Copyright © 2011-2015 Department of Computer Science, University of Oxford. All Rights Reserved.