home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Technology Demos and Tools.iso / java / demo / SortDemo / SortAlgorithm.java < prev    next >
Encoding:
Text File  |  1996-04-29  |  2.9 KB  |  109 lines

  1. /*
  2.  * @(#)SortAlgorithm.java    1.6f 95/01/31 James Gosling
  3.  *
  4.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
  8.  * without fee is hereby granted. 
  9.  * Please refer to the file http://java.sun.com/copy_trademarks.html
  10.  * for further important copyright and trademark information and to
  11.  * http://java.sun.com/licensing.html for further important licensing
  12.  * information for the Java (tm) Technology.
  13.  * 
  14.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  15.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  18.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  19.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  20.  * 
  21.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  22.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  23.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  24.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  25.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  26.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  27.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  28.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  29.  * HIGH RISK ACTIVITIES.
  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.