home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / src / COM / objectspace / jgl / HashMultiSet.java < prev    next >
Encoding:
Java Source  |  1997-03-14  |  3.7 KB  |  126 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package COM.objectspace.jgl;
  5.  
  6. import java.util.Enumeration;
  7.  
  8. /**
  9.  * A HashMultiSet is a container that is optimized for fast associative lookup. Items are
  10.  * matched using a BinaryPredicate which is EqualTo() by default. When an item is
  11.  * inserted into a HashMultiSet, it is stored in a data structure that allows the item
  12.  * to be found very quickly. Items are stored in buckets based on their hash value,
  13.  * computed using the standard function hashCode().
  14.  * A HashMultiSet may contain items that match.
  15.  * <p>
  16.  * HashMultiSets are useful when fast associate lookup is important, and when index-based lookup is
  17.  * unnecessary.
  18.  * <p>
  19.  * Insertion can invalidate iterators.
  20.  * <p>
  21.  * Removal can invalidate iterators.
  22.  * <p>
  23.  * @see COM.objectspace.jgl.SetOperations
  24.  * @see COM.objectspace.jgl.HashSet
  25.  * @see COM.objectspace.jgl.examples.HashSetExamples
  26.  * @version 2.0.2
  27.  * @author ObjectSpace, Inc.
  28.  * @deprecated
  29.  * @see COM.objectspace.jgl.HashSet
  30.  */
  31.  
  32. public class HashMultiSet extends HashSet
  33.   {
  34.   /**
  35.    * Construct myself to be an empty HashMultiSet that compares objects using equals().
  36.    */
  37.   public HashMultiSet()
  38.     {
  39.     super( new EqualTo(), true, DEFAULT_SIZE, DEFAULT_RATIO );
  40.     }
  41.  
  42.   /**
  43.    * Construct myself to be an empty HashMultiSet that compares objects using the specified
  44.    * binary predicate.
  45.    * @param comparator The predicate for comparing objects.
  46.    */
  47.   public HashMultiSet( BinaryPredicate comparator )
  48.     {
  49.     super( comparator, true, DEFAULT_SIZE, DEFAULT_RATIO );
  50.     }
  51.  
  52.   /**
  53.    * Construct myself to be an empty HashMultiSet that compares objects using the specified
  54.    * binary predicate. The initial capacity and load ratio must also be specified.
  55.    * @param comparator The predicate for comparing objects.
  56.    * @param capacity The initial number of hash buckets to reserve.
  57.    * @param loadRatio The maximum load ratio.
  58.    */
  59.   public HashMultiSet( BinaryPredicate comparator, int capacity, float loadRatio  )
  60.     {
  61.     super( comparator, true, capacity, loadRatio );
  62.     }
  63.  
  64.   /**
  65.    * Construct myself to be a shallow copy of an existing HashMultiSet.
  66.    * @param set The HashMultiSet to copy.
  67.    */
  68.   public HashMultiSet( HashMultiSet set )
  69.     {
  70.     copy( set );
  71.     }
  72.  
  73.   /**
  74.    * Return a shallow copy of myself.
  75.    */
  76.   public synchronized Object clone()
  77.     {
  78.     return new HashMultiSet( this );
  79.     }
  80.  
  81.   /**
  82.    * Become a shallow copy of an existing HashMultiSet.
  83.    * @param set The HashMultiSet that I shall become a shallow copy of.
  84.    */
  85.   public synchronized void copy( HashMultiSet set )
  86.     {
  87.     super.copy( set );
  88.     }
  89.  
  90.   /**
  91.    * Return a string that describes me.
  92.    */
  93.   public synchronized String toString()
  94.     {
  95.     return Printing.toString( this, "HashMultiSet" );
  96.     }
  97.  
  98.   /**
  99.    * Return true if I'm equal to another object.
  100.    * @param object The object to compare myself against.
  101.    */
  102.   public boolean equals( Object object )
  103.     {
  104.     return object instanceof HashMultiSet && equals( (HashMultiSet)object );
  105.     }
  106.  
  107.   /**
  108.    * Return true if I contain exactly the same items as another HashMultiSet.
  109.    * Use equals() to compare the individual elements.
  110.    * @param set The HashMultiSet to compare myself against.
  111.    */
  112.   public synchronized boolean equals( HashMultiSet set )
  113.     {
  114.     return super.equals( set );
  115.     }
  116.  
  117.   /**
  118.    * Swap my contents with another HashMultiSet.
  119.    * @param set The HashMultiSet that I will swap my contents with.
  120.    */
  121.   public synchronized void swap( HashMultiSet set )
  122.     {
  123.     super.swap( set );
  124.     }
  125.   }
  126.