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

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package jgl;
  5.  
  6. /**
  7.  * The Filling class contains generic filling algorithms.
  8.  * <p>
  9.  * @see jgl.examples.FillingExamples
  10.  * @version 1.1
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public final class Filling
  15.   {
  16.   private Filling()
  17.     {
  18.     }
  19.  
  20.   /**
  21.    * Fill a specified range with a particular value.
  22.    * @param first An iterator positioned at the first element of the sequence.
  23.    * @param last An iterator positioned immediately after the last element of the sequence.
  24.    * @param object The object to fill the sequence with.
  25.    */
  26.   public static void fill( ForwardIterator first, ForwardIterator last, Object object )
  27.     {
  28.     ForwardIterator firstx = (ForwardIterator) first.clone();
  29.  
  30.     while( !firstx.equals( last ) )
  31.       {
  32.       firstx.put( object );
  33.       firstx.advance();
  34.       }
  35.     }
  36.  
  37.   /**
  38.    * Fill a container with a particular value.
  39.    * @param container The container.
  40.    * @param object The object to fill the container with.
  41.    */
  42.   public static void fill( Container container, Object object )
  43.     {
  44.     fill( container.start(), container.finish(), object );
  45.     }
  46.  
  47.   /**
  48.    * Assign an object to a number of elements starting at a specified location.
  49.    * @param output An iterator positioned at the first element of the sequence.
  50.    * @param n The number of objects to assign.
  51.    * @param object The object to fill the sequence with.
  52.    */
  53.   public static void fillN( OutputIterator output, int n, Object object )
  54.     {
  55.     OutputIterator outputx = (OutputIterator) output.clone();
  56.  
  57.     while( n-- > 0 )
  58.       {
  59.       outputx.put( object );
  60.       outputx.advance();
  61.       }  
  62.     }
  63.   }
  64.  
  65.