All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.objectspace.jgl.HashSet

java.lang.Object
   |
   +----COM.objectspace.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:
Set, BinaryPredicate, SetOperations, HashSetExamples

Constructor Index

 o HashSet()
Construct myself to be an empty HashSet that compares objects using equals() and does not allow duplicates.
 o HashSet(BinaryPredicate)
Construct myself to be an empty HashSet that compares objects using the specified binary predicate and does not allow duplicates.
 o HashSet(BinaryPredicate, boolean)
Construct myself to be an empty HashSet that compares objects using the specified binary predicate and conditionally allows duplicates.
 o HashSet(BinaryPredicate, boolean, int, float)
Construct myself to be an empty HashSet that compares objects using the specified binary predicate and conditionally allows duplicates.
 o HashSet(BinaryPredicate, int, float)
Construct myself to be an empty HashSet that compares objects using the specified binary predicate and conditionally allows duplicates.
 o HashSet(boolean)
Construct myself to be an empty HashSet that compares objects using equals() and that conditionally allows duplicates.
 o HashSet(HashSet)
Construct myself to be a shallow copy of an existing HashSet.

Method Index

 o 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.
 o allowExpansion(boolean)
Enable or disable the current expansion mode.
 o allowsDuplicates()
Return true if I allow duplicate objects.
 o begin()
Return an iterator positioned at my first item.
 o clear()
Remove all of my elements.
 o clone()
Return a shallow copy of myself.
 o copy(HashSet)
Become a shallow copy of an existing HashSet.
 o count(Object)
Return the number of items that match a particular object.
 o difference(HashSet)
Return a new HashSet that contains the elements that are in me but not in a specified set.
 o elements()
Return an Enumeration of my objects.
 o end()
Return an iterator positioned immediately after my last item.
 o 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.
 o equals(HashSet)
Return true if I contain exactly the same items as another HashSet.
 o equals(Object)
Return true if I'm equal to another object.
 o expansionAllowed()
Return true if adding an object to myself could result in an expansion of the number of hash buckets I currently use.
 o find(Object)
Find an object and return its position.
 o finish()
Return an iterator positioned immediately afer my last item.
 o get(Object)
Return the first object that matches the given object, or null if no match exists.
 o getComparator()
Return my comparator.
 o getLoadRatio()
Return my load ratio.
 o hashCode()
Return my hash code for support of hashing containers
 o intersection(HashSet)
Return a new HashSet that contains the elements that are both in me and in a specified set.
 o isEmpty()
Return true if I contain no entries.
 o lowerBound(Object)
Return an iterator positioned at the first location that a particular object could be inserted without violating the ordering criteria.
 o maxSize()
Return the maximum number of entries that I can contain.
 o properSubsetOf(HashSet)
Return true if every element in me is also in a specified HashSet and I'm smaller than the specified HashSet.
 o 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.
 o remove(Enumeration)
Remove the element at a particular position.
 o remove(Enumeration, Enumeration)
Remove the elements within a specified range.
 o remove(Object)
Remove all objects that match the given object.
 o remove(Object, int)
Remove at most a given number of objects that match the given object.
 o size()
Return the number of entries that I contain.
 o start()
Return an iterator positioned at my first item.
 o subsetOf(HashSet)
Return true if every element in me is also in a specified HashSet.
 o swap(HashSet)
Swap my contents with another HashSet.
 o symmetricDifference(HashSet)
Return a new HashSet that contains the elements that are either in me or in a specified HashSet, but not both.
 o toString()
Return a string that describes me.
 o union(HashSet)
Return a new HashSet that contains all of my elements and all of the elements in a specified HashSet.
 o upperBound(Object)
Return an iterator positioned at the last location that a particular object could be inserted without violating the ordering criteria.

Constructors

 o HashSet
  public HashSet()
Construct myself to be an empty HashSet that compares objects using equals() and does not allow duplicates.

 o 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.
 o 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.
 o 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.
 o HashSet
  public HashSet(BinaryPredicate comparator,
                 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.
capacity - The initial number of hash buckets to reserve.
loadRatio - The maximum load ratio.
 o 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.
 o HashSet
  public HashSet(HashSet set)
Construct myself to be a shallow copy of an existing HashSet.

Parameters:
set - The HashSet to copy.

Methods

 o allowsDuplicates
  public boolean allowsDuplicates()
Return true if I allow duplicate objects.

 o getComparator
  public BinaryPredicate getComparator()
Return my comparator.

 o getLoadRatio
  public float getLoadRatio()
Return my load ratio.

 o clone
  public synchronized Object clone()
Return a shallow copy of myself.

Overrides:
clone in class Object
 o copy
  public synchronized void copy(HashSet set)
Become a shallow copy of an existing HashSet.

Parameters:
set - The HashSet that I shall become a shallow copy of.
 o toString
  public synchronized String toString()
Return a string that describes me.

Overrides:
toString in class Object
 o elements
  public synchronized Enumeration elements()
Return an Enumeration of my objects.

 o start
  public ForwardIterator start()
Return an iterator positioned at my first item.

 o finish
  public ForwardIterator finish()
Return an iterator positioned immediately afer my last item.

 o begin
  public synchronized HashSetIterator begin()
Return an iterator positioned at my first item.

 o end
  public synchronized HashSetIterator end()
Return an iterator positioned immediately after my last item.

 o isEmpty
  public boolean isEmpty()
Return true if I contain no entries.

 o size
  public int size()
Return the number of entries that I contain.

 o maxSize
  public int maxSize()
Return the maximum number of entries that I can contain.

 o 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
 o 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.
 o hashCode
  public synchronized int hashCode()
Return my hash code for support of hashing containers

Overrides:
hashCode in class Object
 o swap
  public synchronized void swap(HashSet set)
Swap my contents with another HashSet.

Parameters:
set - The HashSet that I will swap my contents with.
 o clear
  public synchronized void clear()
Remove all of my elements.

 o remove
  public int remove(Object object)
Remove all objects that match the given object.

Parameters:
object - The object to match for removals
Returns:
Return the number of values removed.
 o remove
  public int remove(Object key,
                    int count)
Remove at most a given number of objects that match the given object.

Parameters:
object - The object to match for removals
count - The maximum number of the pair(s) to remove.
Returns:
Return the number of values removed.
 o remove
  public synchronized Object remove(Enumeration e)
Remove the element at a particular position.

Parameters:
e - An Enumeration positioned at the element to remove.
Returns:
Return the pair associated with the enumeration or null if none.
Throws: IllegalArgumentException
is the Enumeration isn't a HashSetIterator for this HashSet object.
 o remove
  public synchronized int 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.
Returns:
Return the number of values removed.
Throws: IllegalArgumentException
is the Enumeration isn't a HashSetIterator for this HashSet object.
 o 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.
 o count
  public synchronized int count(Object object)
Return the number of items that match a particular object.

Parameters:
object - The object to match against.
 o add
  public synchronized 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o lowerBound
  public synchronized HashSetIterator lowerBound(Object object)
Return an iterator positioned at the first location that a particular object could be inserted without violating the ordering criteria. If no such location is found, return an iterator positioned at end().

Parameters:
object - The object in question.
 o upperBound
  public synchronized HashSetIterator upperBound(Object object)
Return an iterator positioned at the last location that a particular object could be inserted without violating the ordering criteria. If no such location is found, return an iterator positioned at end().

Parameters:
object - The object in question.
 o 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, both ends of the range will be the same.

Parameters:
object - The object whose bounds are to be found.
 o expansionAllowed
  public boolean expansionAllowed()
Return true if adding an object to myself could result in an expansion of the number of hash buckets I currently use.

 o allowExpansion
  public synchronized void allowExpansion(boolean allow)
Enable or disable the current expansion mode. If disabled, no new hash buckets will ever be created regardless of my size.

Parameters:
allow - The new expansion mode.

All Packages  Class Hierarchy  This Package  Previous  Next  Index