home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / SortAlgorithm.java < prev    next >
Encoding:
Text File  |  1997-07-30  |  3.2 KB  |  109 lines

  1. // $Header: z:/admin/metro_examples/java/demo/SortDemo/rcs/SortAlgorithm.java 1.1 1997/02/06 00:30:30 IPGIntel-2 Exp $ 
  2. /*
  3.  * @(#)SortAlgorithm.java    1.4 96/12/06
  4.  *
  5.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  6.  *
  7.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  8.  * modify and redistribute this software in source and binary code form,
  9.  * provided that i) this copyright notice and license appear on all copies of
  10.  * the software; and ii) Licensee does not utilize the software in a manner
  11.  * which is disparaging to Sun.
  12.  *
  13.  * This software is provided "AS IS," without a warranty of any kind. ALL
  14.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  15.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  16.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  17.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  18.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  19.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  20.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  21.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  22.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  23.  * POSSIBILITY OF SUCH DAMAGES.
  24.  *
  25.  * This software is not designed or intended for use in on-line control of
  26.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  27.  * the design, construction, operation or maintenance of any nuclear
  28.  * facility. Licensee represents and warrants that it will not use or
  29.  * redistribute the Software for such purposes.
  30.  */
  31.  
  32. /**
  33.  * A generic sort demonstration algorithm
  34.  * SortAlgorithm.java, Thu Oct 27 10:32:35 1994
  35.  *
  36.  * @author James Gosling
  37.  * @version     1.6f, 31 Jan 1995
  38.  */
  39.  
  40. class SortAlgorithm {
  41.     /**
  42.      * The sort item.
  43.      */
  44.     private SortItem parent;
  45.  
  46.     /**
  47.      * When true stop sorting.
  48.      */
  49.     protected boolean stopRequested = false;
  50.  
  51.     /**
  52.      * Set the parent.
  53.      */
  54.     public void setParent(SortItem p) {
  55.     parent = p;
  56.     }
  57.  
  58.     /**
  59.      * Pause for a while.
  60.      */
  61.     protected void pause() throws Exception {
  62.     if (stopRequested) {
  63.         throw new Exception("Sort Algorithm");
  64.     }
  65.     parent.pause(parent.h1, parent.h2);
  66.     }
  67.  
  68.     /**
  69.      * Pause for a while and mark item 1.
  70.      */
  71.     protected void pause(int H1) throws Exception {
  72.     if (stopRequested) {
  73.         throw new Exception("Sort Algorithm");
  74.     }
  75.     parent.pause(H1, parent.h2);
  76.     }
  77.  
  78.     /**
  79.      * Pause for a while and mark item 1 & 2.
  80.      */
  81.     protected void pause(int H1, int H2) throws Exception {
  82.     if (stopRequested) {
  83.         throw new Exception("Sort Algorithm");
  84.     }
  85.     parent.pause(H1, H2);
  86.     }
  87.  
  88.     /**
  89.      * Stop sorting.
  90.      */
  91.     public void stop() {
  92.     stopRequested = true;
  93.     }
  94.  
  95.     /**
  96.      * Initialize
  97.      */
  98.     public void init() {
  99.     stopRequested = false;
  100.     }
  101.  
  102.     /**
  103.      * This method will be called to
  104.      * sort an array of integers.
  105.      */
  106.     void sort(int a[]) throws Exception {
  107.     }
  108. }
  109.