home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / misc / Queue.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.1 KB  |  77 lines

  1. package sun.misc;
  2.  
  3. import java.util.Enumeration;
  4.  
  5. public class Queue {
  6.    int length;
  7.    QueueElement head;
  8.    QueueElement tail;
  9.  
  10.    public synchronized void enqueue(Object var1) {
  11.       QueueElement var2 = new QueueElement(var1);
  12.       if (this.head == null) {
  13.          this.head = var2;
  14.          this.tail = var2;
  15.          this.length = 1;
  16.       } else {
  17.          var2.next = this.head;
  18.          this.head.prev = var2;
  19.          this.head = var2;
  20.          ++this.length;
  21.       }
  22.  
  23.       this.notify();
  24.    }
  25.  
  26.    public Object dequeue() throws InterruptedException {
  27.       return this.dequeue(0L);
  28.    }
  29.  
  30.    public synchronized Object dequeue(long var1) throws InterruptedException {
  31.       while(this.tail == null) {
  32.          this.wait(var1);
  33.       }
  34.  
  35.       QueueElement var3 = this.tail;
  36.       this.tail = var3.prev;
  37.       if (this.tail == null) {
  38.          this.head = null;
  39.       } else {
  40.          this.tail.next = null;
  41.       }
  42.  
  43.       --this.length;
  44.       return var3.obj;
  45.    }
  46.  
  47.    public synchronized boolean isEmpty() {
  48.       return this.tail == null;
  49.    }
  50.  
  51.    public final synchronized Enumeration elements() {
  52.       return new LIFOQueueEnumerator(this);
  53.    }
  54.  
  55.    public final synchronized Enumeration reverseElements() {
  56.       return new FIFOQueueEnumerator(this);
  57.    }
  58.  
  59.    public synchronized void dump(String var1) {
  60.       System.err.println(">> " + var1);
  61.       System.err.println("[" + this.length + " elt(s); head = " + (this.head == null ? "null" : String.valueOf(this.head.obj)) + " tail = " + (this.tail == null ? "null" : String.valueOf(this.tail.obj)));
  62.       QueueElement var2 = this.head;
  63.  
  64.       QueueElement var3;
  65.       for(var3 = null; var2 != null; var2 = var2.next) {
  66.          System.err.println("  " + var2);
  67.          var3 = var2;
  68.       }
  69.  
  70.       if (var3 != this.tail) {
  71.          System.err.println("  tail != last: " + this.tail + ", " + var3);
  72.       }
  73.  
  74.       System.err.println("]");
  75.    }
  76. }
  77.