Class jgl.HashSet
All Packages Class Hierarchy This Package Previous Next Index
Class jgl.HashSet
java.lang.Object
|
+----jgl.HashSet
- public class HashSet
- extends Object
- implements Set
A HashSet is a container that is optimized for fast associative lookup. Items are
matched using a BinaryPredicate which is EqualTo() by default. When an item is
inserted into a HashSet, it is stored in a data structure that allows the item
to be found very quickly. Items are stored in buckets based on their hash value,
computed using the standard function hashCode().
By default, a HashSet cannot contain items that match.
The HashSet class supports the full range of generic set algorithms such as union()
and intersection() in a user-friendly manner.
HashSets are useful when fast associate lookup is important, when index-based lookup is
unnecessary, and when duplicates are not allowed.
Insertion can invalidate iterators.
Removal can invalidate iterators.
- See Also:
- SetOperations, HashSetExamples
-
HashSet()
- Construct myself to be an empty HashSet that compares objects using equals() and
does not allow duplicates.
-
HashSet(BinaryPredicate)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and does not allow duplicates.
-
HashSet(BinaryPredicate, boolean)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and conditionally allows duplicates.
-
HashSet(BinaryPredicate, boolean, int, float)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and conditionally allows duplicates.
-
HashSet(boolean)
- Construct myself to be an empty HashSet that compares objects using equals() and
that conditionally allows duplicates.
-
HashSet(HashSet)
- Construct myself to be a shallow copy of an existing HashSet.
-
add(Object)
- If the object doesn't exist or duplicates are allowed, add the object and return null,
otherwise don't modify the set and return the matching object.
-
allowsDuplicates()
- Return true if I allow duplicate objects.
-
begin()
- Return an iterator positioned at my first item.
-
clear()
- Remove all of my elements.
-
clone()
- Return a shallow copy of myself.
-
copy(HashSet)
- Become a shallow copy of an existing HashSet.
-
count(Object)
- Return the number of items that match a particular object.
-
difference(HashSet)
- Return a new HashSet that contains the elements that are in me but not in a
specified set.
-
elements()
- Return an Enumeration of my objects.
-
end()
- Return an iterator positioned immediately after my last item.
-
equalRange(Object)
- Return a range whose first element is an iterator positioned
at the first occurence of a specific object and whose second element is an
iterator positioned immediately after the last occurence of that object.
-
equals(HashSet)
- Return true if I contain exactly the same items as another HashSet.
-
equals(Object)
- Return true if I'm equal to another object.
-
find(Object)
- Find an object and return its position.
-
finish()
- Return an iterator positioned immediately afer my last item.
-
get(Object)
- Return the first object that matches the given object, or null if no match exists.
-
getComparator()
- Return my comparator.
-
getLoadRatio()
- Return my load ratio.
-
hashCode()
- Return my hash code for support of hashing containers
-
intersection(HashSet)
- Return a new HashSet that contains the elements that are both in me and in
a specified set.
-
isEmpty()
- Return true if I contain no entries.
-
maxSize()
- Return the maximum number of entries that I can contain.
-
properSubsetOf(HashSet)
- Return true if every element in me is also in a specified HashSet and I'm smaller
than the specified HashSet.
-
put(Object)
- If the object doesn't exist, add the object and return null, otherwise replace the
first object that matches and return the old object.
-
remove(Enumeration)
- Remove the element at a particular position.
-
remove(Enumeration, Enumeration)
- Remove the elements within a specified range.
-
remove(Object)
- Remove all objects that match the given object.
-
size()
-
Return the number of entries that I contain.
-
start()
- Return an iterator positioned at my first item.
-
subsetOf(HashSet)
- Return true if every element in me is also in a specified HashSet.
-
swap(HashSet)
- Swap my contents with another HashSet.
-
symmetricDifference(HashSet)
- Return a new HashSet that contains the elements that are either in me or in
a specified HashSet, but not both.
-
toString()
- Return a string that describes me.
-
union(HashSet)
- Return a new HashSet that contains all of my elements and all of the elements in
a specified HashSet.
HashSet
public HashSet()
- Construct myself to be an empty HashSet that compares objects using equals() and
does not allow duplicates.
HashSet
public HashSet(boolean allowDuplicates)
- Construct myself to be an empty HashSet that compares objects using equals() and
that conditionally allows duplicates.
- Parameters:
- allowDuplicates - true if duplicates are allowed.
HashSet
public HashSet(BinaryPredicate comparator)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and does not allow duplicates.
- Parameters:
- comparator - The predicate for comparing objects.
HashSet
public HashSet(BinaryPredicate comparator,
boolean allowDuplicates)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and conditionally allows duplicates.
- Parameters:
- comparator - The predicate for comparing objects.
- allowDuplicates - true if duplicates are allowed.
HashSet
public HashSet(BinaryPredicate comparator,
boolean allowDuplicates,
int capacity,
float loadRatio)
- Construct myself to be an empty HashSet that compares objects using the specified
binary predicate and conditionally allows duplicates. The initial capacity and
load ratio must also be specified.
- Parameters:
- comparator - The predicate for comparing objects.
- allowDuplicates - true if duplicates are allowed.
- capacity - The initial number of hash buckets to reserve.
- loadRatio - The maximum load ratio.
HashSet
public HashSet(HashSet set)
- Construct myself to be a shallow copy of an existing HashSet.
- Parameters:
- set - The HashSet to copy.
allowsDuplicates
public boolean allowsDuplicates()
- Return true if I allow duplicate objects.
getComparator
public BinaryPredicate getComparator()
- Return my comparator.
getLoadRatio
public float getLoadRatio()
- Return my load ratio.
clone
public synchronized Object clone()
- Return a shallow copy of myself.
- Overrides:
- clone in class Object
copy
public synchronized void copy(HashSet set)
- Become a shallow copy of an existing HashSet.
- Parameters:
- map - The HashSet that I shall become a shallow copy of.
toString
public synchronized String toString()
- Return a string that describes me.
- Overrides:
- toString in class Object
elements
public synchronized Enumeration elements()
- Return an Enumeration of my objects.
start
public synchronized ForwardIterator start()
- Return an iterator positioned at my first item.
finish
public synchronized ForwardIterator finish()
- Return an iterator positioned immediately afer my last item.
begin
public synchronized HashSetIterator begin()
- Return an iterator positioned at my first item.
end
public synchronized HashSetIterator end()
- Return an iterator positioned immediately after my last item.
isEmpty
public boolean isEmpty()
- Return true if I contain no entries.
size
public int size()
- Return the number of entries that I contain.
maxSize
public int maxSize()
- Return the maximum number of entries that I can contain.
equals
public boolean equals(Object object)
- Return true if I'm equal to another object.
- Parameters:
- object - The object to compare myself against.
- Overrides:
- equals in class Object
equals
public synchronized boolean equals(HashSet set)
- Return true if I contain exactly the same items as another HashSet.
Use equals() to compare the individual elements.
- Parameters:
- set - The HashSet to compare myself against.
hashCode
public int hashCode()
- Return my hash code for support of hashing containers
- Overrides:
- hashCode in class Object
swap
public synchronized void swap(HashSet set)
- Swap my contents with another HashSet.
- Parameters:
- set - The HashSet that I will swap my contents with.
clear
public synchronized void clear()
- Remove all of my elements.
remove
public synchronized Object remove(Object object)
- Remove all objects that match the given object.
- Parameters:
- object - The object to match for removals
- Returns:
- Return the value associated with the first object removed or null if not found.
remove
public synchronized void remove(Enumeration e)
- Remove the element at a particular position.
- Parameters:
- e - An Enumeration positioned at the element to remove.
- Throws: IllegalArgumentException
- is the Enumeration isn't a
HashSetIterator for this HashSet object.
remove
public synchronized void remove(Enumeration first,
Enumeration last)
- Remove the elements within a specified range.
- Parameters:
- first - An Enumeration positioned at the first element to remove.
- last - An Enumeration positioned immediately after the last element to remove.
- Throws: IllegalArgumentException
- is the Enumeration isn't a
HashSetIterator for this HashSet object.
find
public synchronized HashSetIterator find(Object object)
- Find an object and return its position. If the object
is not found, return end().
- Parameters:
- object - The object to locate.
count
public synchronized int count(Object object)
- Return the number of items that match a particular object.
Since a HashSet cannot contain duplicates, this function always
returns either 0 or 1.
- Parameters:
- object - The object to match against.
add
public Object add(Object object)
- If the object doesn't exist or duplicates are allowed, add the object and return null,
otherwise don't modify the set and return the matching object.
- Parameters:
- object - The object to be added.
- Throws: NullPointerException
- If the value of the object is equal to null.
get
public synchronized Object get(Object object)
- Return the first object that matches the given object, or null if no match exists.
- Parameters:
- object - The object to match against.
put
public synchronized Object put(Object object)
- If the object doesn't exist, add the object and return null, otherwise replace the
first object that matches and return the old object.
- Parameters:
- object - The object to add.
- Throws: NullPointerException
- If the value of the object is equal to null.
union
public synchronized HashSet union(HashSet set)
- Return a new HashSet that contains all of my elements and all of the elements in
a specified HashSet.
- Parameters:
- set - The HashSet to union myself with.
intersection
public synchronized HashSet intersection(HashSet set)
- Return a new HashSet that contains the elements that are both in me and in
a specified set.
- Parameters:
- set - The HashSet to intersect myself with.
difference
public synchronized HashSet difference(HashSet set)
- Return a new HashSet that contains the elements that are in me but not in a
specified set.
- Parameters:
- set - The HashSet to difference myself with.
symmetricDifference
public synchronized HashSet symmetricDifference(HashSet set)
- Return a new HashSet that contains the elements that are either in me or in
a specified HashSet, but not both.
- Parameters:
- set - The HashSet to symmetric difference myself with.
subsetOf
public synchronized boolean subsetOf(HashSet set)
- Return true if every element in me is also in a specified HashSet.
- Parameters:
- set - The HashSet to test against.
properSubsetOf
public synchronized boolean properSubsetOf(HashSet set)
- Return true if every element in me is also in a specified HashSet and I'm smaller
than the specified HashSet.
- Parameters:
- set - The HashSet to test against.
equalRange
public synchronized Range equalRange(Object object)
- Return a range whose first element is an iterator positioned
at the first occurence of a specific object and whose second element is an
iterator positioned immediately after the last occurence of that object.
Note that all objects inbetween these iterators will also match the specified
object. If no matching object is found, return null.
- Parameters:
- object - The object whose bounds are to be found.
All Packages Class Hierarchy This Package Previous Next Index