public class KeyedHashSet extends Object
KeyedElement
objects as elements of the set.
Unlike typical set implementations this set requires each element to provide its own key. This helps
reduce the overhead of storing the keys of each individual elementThis class in not thread safe, clients must ensure synchronization when modifying an object of this type.
Modifier and Type | Field and Description |
---|---|
static int |
MINIMUM_SIZE |
Constructor and Description |
---|
KeyedHashSet()
Constructs an KeyedHashSet which allows elements to be replaced and with the minimum initial capacity.
|
KeyedHashSet(boolean replace)
Constructs an KeyedHashSet with the minimum initial capacity.
|
KeyedHashSet(int capacity)
Constructs an KeyedHashSet which allows elements to be replaced.
|
KeyedHashSet(int capacity,
boolean replace)
Constructs an KeyedHashSet
|
KeyedHashSet(KeyedHashSet original)
Constructs a new KeyedHashSet and copies to specified KeyedHashSet's contents to the new KeyedHashSet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(KeyedElement element)
Adds an element to this set.
|
void |
addAll(KeyedElement[] toAdd)
Adds the specified list of elements to this set.
|
void |
clear()
Clears all elements from this set
|
boolean |
contains(KeyedElement element)
Returns true if the specified element exists in this set.
|
boolean |
containsKey(Object key)
Returns true if an element with the specified key exists in this set.
|
int |
countCollisions()
Returns the number of collisions this set currently has
|
KeyedElement[] |
elements()
Returns all elements that exist in this set
|
Object[] |
elements(Object[] result)
Copies all elements that exist in this set into the specified array.
|
protected void |
expand()
The array isn't large enough so double its size and rehash
all its current values.
|
KeyedElement |
get(KeyedElement otherElement)
Returns the element which compares to the specified element, or null if not found.
|
KeyedElement |
getByKey(Object key)
Returns the element with the specified key, or null if not found.
|
boolean |
isEmpty()
Returns true if this set is empty
|
Iterator<KeyedElement> |
iterator()
Returns an iterator of elements in this set
|
protected void |
rehashTo(int anIndex)
The element at the given index has been removed so move
elements to keep the set properly hashed.
|
boolean |
remove(KeyedElement toRemove)
Removes the element which compares to the specified element
|
void |
removeAll(KeyedElement[] toRemove)
Removes all of the specified elements from this set
|
boolean |
removeByKey(Object key)
Removes the element with the specified key
|
int |
size()
Returns the number of elements in this set
|
String |
toString() |
public static final int MINIMUM_SIZE
public KeyedHashSet()
public KeyedHashSet(boolean replace)
replace
- true if this set allows elements to be replacedpublic KeyedHashSet(int capacity)
capacity
- the initial capacity of this setpublic KeyedHashSet(int capacity, boolean replace)
capacity
- the initial capacity of this setreplace
- true if this set allows elements to be replacedpublic KeyedHashSet(KeyedHashSet original)
original
- the KeyedHashSet to copypublic boolean add(KeyedElement element)
public void addAll(KeyedElement[] toAdd)
toAdd
- the list of elements to add to this set.public boolean contains(KeyedElement element)
element
- the requested elementpublic boolean containsKey(Object key)
key
- the key of the requested elementpublic KeyedElement[] elements()
public Object[] elements(Object[] result)
result
- the array to copy the existing elements into.ArrayIndexOutOfBoundsException
- if the specified array is to small.protected void expand()
public KeyedElement getByKey(Object key)
key
- the requested element's keypublic KeyedElement get(KeyedElement otherElement)
otherElement
- the requested elementKeyedElement.compare(KeyedElement)
public boolean isEmpty()
protected void rehashTo(int anIndex)
anIndex
- the index that has been removedpublic boolean removeByKey(Object key)
key
- the requested element's keypublic boolean remove(KeyedElement toRemove)
toRemove
- the requested element to removepublic void removeAll(KeyedElement[] toRemove)
toRemove
- the requested elements to removepublic int size()
public int countCollisions()
public Iterator<KeyedElement> iterator()
public void clear()
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.