home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / src / insertiterator.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  1.5 KB  |  71 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package jgl;
  5.  
  6. /**
  7.  * An InsertIterator is an output iterator that adds any object that is written to it
  8.  * into a specified Container.
  9.  * <p>
  10.  * @version 1.1
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class InsertIterator implements OutputIterator
  15.   {
  16.   Container my_container;
  17.  
  18.   /**
  19.    * Construct myself so that current( object ) inserts the object into a container
  20.    * using add().
  21.    * @param container The container to add to.
  22.    */
  23.   public InsertIterator( Container container )
  24.     {
  25.     my_container = container;
  26.     }
  27.  
  28.   /** 
  29.    * Construct myself to be a copy of the specified iterator.
  30.    * @param iterator The iterator to copy.
  31.    */
  32.   public InsertIterator( InsertIterator iterator )
  33.     {
  34.     my_container = iterator.my_container;
  35.     }
  36.  
  37.   /**
  38.    * Insert the object to my associated container using add().
  39.    * @param object The object to be added.
  40.    */
  41.   public void put( Object object )
  42.     {
  43.     my_container.add( object );
  44.     }
  45.  
  46.   /**
  47.    * Advance by one. This has no effect for an InsertIterator.
  48.    */
  49.   public void advance()
  50.     {
  51.     // Do nothing.
  52.     }
  53.  
  54.   /**
  55.    * Advance by a specified amount. This has no effect for an InsertIterator.
  56.    * @param n The amount to advance.
  57.    */
  58.   public void advance( int n )
  59.     {
  60.     // Do nothing.
  61.     }
  62.  
  63.   /**
  64.    * Return a clone of myself.
  65.    */
  66.   public Object clone()
  67.     {
  68.     return new InsertIterator( this );
  69.     }
  70.   }
  71.