home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / util / TaskQueue.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.1 KB  |  83 lines

  1. package java.util;
  2.  
  3. class TaskQueue {
  4.    private TimerTask[] queue = new TimerTask[128];
  5.    private int size = 0;
  6.  
  7.    void add(TimerTask var1) {
  8.       if (++this.size == this.queue.length) {
  9.          TimerTask[] var2 = new TimerTask[2 * this.queue.length];
  10.          System.arraycopy(this.queue, 0, var2, 0, this.size);
  11.          this.queue = var2;
  12.       }
  13.  
  14.       this.queue[this.size] = var1;
  15.       this.fixUp(this.size);
  16.    }
  17.  
  18.    TimerTask getMin() {
  19.       return this.queue[1];
  20.    }
  21.  
  22.    void removeMin() {
  23.       this.queue[1] = this.queue[this.size];
  24.       this.queue[this.size--] = null;
  25.       this.fixDown(1);
  26.    }
  27.  
  28.    void rescheduleMin(long var1) {
  29.       this.queue[1].nextExecutionTime = var1;
  30.       this.fixDown(1);
  31.    }
  32.  
  33.    boolean isEmpty() {
  34.       return this.size == 0;
  35.    }
  36.  
  37.    void clear() {
  38.       for(int var1 = 1; var1 <= this.size; ++var1) {
  39.          this.queue[var1] = null;
  40.       }
  41.  
  42.       this.size = 0;
  43.    }
  44.  
  45.    private void fixUp(int var1) {
  46.       while(true) {
  47.          if (var1 > 1) {
  48.             int var2 = var1 >> 1;
  49.             if (this.queue[var2].nextExecutionTime > this.queue[var1].nextExecutionTime) {
  50.                TimerTask var3 = this.queue[var2];
  51.                this.queue[var2] = this.queue[var1];
  52.                this.queue[var1] = var3;
  53.                var1 = var2;
  54.                continue;
  55.             }
  56.          }
  57.  
  58.          return;
  59.       }
  60.    }
  61.  
  62.    private void fixDown(int var1) {
  63.       while(true) {
  64.          int var2;
  65.          if ((var2 = var1 << 1) <= this.size) {
  66.             if (var2 < this.size && this.queue[var2].nextExecutionTime > this.queue[var2 + 1].nextExecutionTime) {
  67.                ++var2;
  68.             }
  69.  
  70.             if (this.queue[var1].nextExecutionTime > this.queue[var2].nextExecutionTime) {
  71.                TimerTask var3 = this.queue[var2];
  72.                this.queue[var2] = this.queue[var1];
  73.                this.queue[var1] = var3;
  74.                var1 = var2;
  75.                continue;
  76.             }
  77.          }
  78.  
  79.          return;
  80.       }
  81.    }
  82. }
  83.