|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.util.HashSet
public class HashSet
A custom HashSet implementation.
This implementation is designed for realtime work and in particular with the goal of absolute minimum garbage generation. The standard implementation in java.util generates excessive amounts of garbage and is unsuitable for the task.
The implementation does not have a backing class and the internals are based on the hashing code in IntHashMap. The method signature is almost the same as java.util.HashSet, except we leave out garbage generating methods like iterator().
Constructor Summary | |
---|---|
HashSet()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75). |
|
HashSet(int initialCapacity)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor, which is 0.75. |
|
HashSet(int initialCapacity,
float loadFactor)
Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and the specified load factor. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object o)
Adds the specified element to this set if it is not already present. |
boolean |
addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this set. |
boolean |
addAll(HashSet hs)
Adds all of the elements in the specified hash set to this set. |
void |
clear()
Removes all of the elements from this set. |
boolean |
contains(java.lang.Object o)
Returns true if this set contains the specified element. |
boolean |
equals(java.lang.Object o)
Compares the specified object with this set for equality. |
int |
hashCode()
Returns the hash code value for this set. |
boolean |
isEmpty()
Check to see if this set contains elements. |
boolean |
remove(java.lang.Object o)
Removes the specified element from this set if it is present. |
boolean |
removeAll(java.util.Collection c)
Removes from this set all of its elements that are contained in the specified collection. |
boolean |
removeAll(HashSet hs)
Removes from this collection all of its elements that are contained in the specified hash set. |
void |
retainAll(HashSet set)
Retain everything that is in the given set, in this set. |
void |
retainAll(HashSet set,
HashSet diff)
Retain everything that is in the given set, in this set, and move anything that is not, into the alternate set. |
int |
size()
Returns the number of elements in this set (its cardinality). |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
java.lang.String |
toString()
Returns a string representation of this set. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public HashSet()
public HashSet(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of the hash map.loadFactor
- the load factor of the hash map.
java.lang.IllegalArgumentException
- if the initial capacity is less
than zero, or if the load factor is nonpositive.public HashSet(int initialCapacity)
initialCapacity
- the initial capacity of the hash table.
java.lang.IllegalArgumentException
- if the initial capacity is less
than zero.Method Detail |
---|
public int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
o
- element whose presence in this set is to be tested.
public void retainAll(HashSet set)
set
- The set to compare againstpublic void retainAll(HashSet set, HashSet diff)
set
- The set to compare againstdiff
- The set to place the non-equal values intopublic boolean add(java.lang.Object o)
o
- element to be added to this set.
public boolean remove(java.lang.Object o)
o
- object to be removed from this set, if present.
public void clear()
public boolean addAll(java.util.Collection c)
This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.
c
- collection whose elements are to be added to this collection.
java.lang.UnsupportedOperationException
- if this collection does not
support the addAll method.
java.lang.NullPointerException
- if the specified collection is null.public boolean addAll(HashSet hs)
hs
- The set whose elements are to be added to this set
java.lang.UnsupportedOperationException
- if this collection does not
support the addAll method
java.lang.NullPointerException
- if the specified collection is nullpublic boolean removeAll(java.util.Collection c)
This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.
c
- elements to be removed from this set.
java.lang.UnsupportedOperationException
- if the removeAll method
is not supported by this collection.
java.lang.NullPointerException
- if the specified collection is null.remove(Object)
,
contains(Object)
public boolean removeAll(HashSet hs)
This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.
hs
- elements to be removed from this set.
java.lang.UnsupportedOperationException
- if the removeAll method
is not supported by this collection.
java.lang.NullPointerException
- if the specified collection is null.public java.lang.Object[] toArray()
This implementation allocates the array to be returned, and iterates over the elements in the collection, storing each object reference in the next consecutive element of the array, starting with element 0.
public java.lang.Object[] toArray(java.lang.Object[] array)
If the collection fits in the specified array with room to spare (i.e., the array has more elements than the collection), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the collection only if the caller knows that the collection does not contain any null elements.)
If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
This implementation checks if the array is large enough to contain the collection; if not, it allocates a new array of the correct size and type (using reflection). Then, it iterates over the collection, storing each object reference in the next consecutive element of the array, starting with element 0. If the array is larger than the collection, a null is stored in the first location after the end of the collection.
array
- the array into which the elements of the set are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
java.lang.NullPointerException
- if the specified array is null.
java.lang.ArrayStoreException
- if the runtime type of the specified array
is not a supertype of the runtime type of every element in this
collection.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to be compared for equality with this set.
public int hashCode()
This implementation enumerates over the set, calling the hashCode method on each element in the collection, and adding up the results.
hashCode
in class java.lang.Object
public java.lang.String toString()
This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.
toString
in class java.lang.Object
|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |