home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / COM / objectspace / jgl / PriorityQueue.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-03-12  |  3.2 KB  |  151 lines

  1. package COM.objectspace.jgl;
  2.  
  3. import java.util.Enumeration;
  4.  
  5. public class PriorityQueue implements Container {
  6.    Array myArray;
  7.    BinaryPredicate myComparator;
  8.  
  9.    public PriorityQueue() {
  10.       this((BinaryPredicate)(new HashComparator()));
  11.    }
  12.  
  13.    public PriorityQueue(BinaryPredicate var1) {
  14.       this.myArray = new Array();
  15.       this.myComparator = var1;
  16.    }
  17.  
  18.    public PriorityQueue(PriorityQueue var1) {
  19.       synchronized(var1){}
  20.  
  21.       try {
  22.          this.myArray = (Array)var1.myArray.clone();
  23.          this.myComparator = var1.myComparator;
  24.       } catch (Throwable var4) {
  25.          throw var4;
  26.       }
  27.  
  28.    }
  29.  
  30.    public synchronized String toString() {
  31.       return "PriorityQueue( " + this.myArray.toString() + " )";
  32.    }
  33.  
  34.    public synchronized Object clone() {
  35.       return new PriorityQueue(this);
  36.    }
  37.  
  38.    public synchronized void copy(PriorityQueue var1) {
  39.       synchronized(var1){}
  40.  
  41.       try {
  42.          if (this != var1) {
  43.             this.myArray = (Array)var1.myArray.clone();
  44.             this.myComparator = var1.myComparator;
  45.          }
  46.       } catch (Throwable var4) {
  47.          throw var4;
  48.       }
  49.  
  50.    }
  51.  
  52.    public boolean equals(Object var1) {
  53.       return var1 instanceof PriorityQueue && this.equals((PriorityQueue)var1);
  54.    }
  55.  
  56.    public synchronized boolean equals(PriorityQueue var1) {
  57.       synchronized(var1){}
  58.  
  59.       boolean var2;
  60.       try {
  61.          var2 = this.myArray.equals(var1.myArray);
  62.       } catch (Throwable var6) {
  63.          throw var6;
  64.       }
  65.  
  66.       return var2;
  67.    }
  68.  
  69.    public synchronized int hashCode() {
  70.       return this.myArray.hashCode();
  71.    }
  72.  
  73.    public boolean isEmpty() {
  74.       return this.myArray.isEmpty();
  75.    }
  76.  
  77.    public int size() {
  78.       return this.myArray.size();
  79.    }
  80.  
  81.    public int maxSize() {
  82.       return this.myArray.maxSize();
  83.    }
  84.  
  85.    public synchronized void clear() {
  86.       this.myArray.clear();
  87.    }
  88.  
  89.    public synchronized Enumeration elements() {
  90.       return this.myArray.elements();
  91.    }
  92.  
  93.    public synchronized ForwardIterator start() {
  94.       return this.myArray.start();
  95.    }
  96.  
  97.    public synchronized ForwardIterator finish() {
  98.       return this.myArray.finish();
  99.    }
  100.  
  101.    public synchronized Object top() {
  102.       return this.myArray.front();
  103.    }
  104.  
  105.    public Object add(Object var1) {
  106.       this.push(var1);
  107.       return null;
  108.    }
  109.  
  110.    public synchronized void push(Object var1) {
  111.       this.myArray.pushBack(var1);
  112.       ArrayIterator var2 = this.myArray.begin();
  113.       ArrayIterator var3 = this.myArray.end();
  114.       BinaryPredicate var4 = this.myComparator;
  115.       Heap.pushHeap(var2, var2.distance(var3) - 1, 0, var3.get(-1), var4);
  116.    }
  117.  
  118.    public synchronized Object pop() {
  119.       if (this.myArray.isEmpty()) {
  120.          throw new InvalidOperationException("PriorityQueue is empty");
  121.       } else {
  122.          Heap.popHeap(this.myArray.begin(), this.myArray.end(), this.myComparator);
  123.          return this.myArray.popBack();
  124.       }
  125.    }
  126.  
  127.    public synchronized void swap(PriorityQueue var1) {
  128.       synchronized(var1){}
  129.  
  130.       try {
  131.          Array var4 = this.myArray;
  132.          this.myArray = var1.myArray;
  133.          var1.myArray = var4;
  134.          BinaryPredicate var5 = this.myComparator;
  135.          this.myComparator = var1.myComparator;
  136.          var1.myComparator = var5;
  137.       } catch (Throwable var7) {
  138.          throw var7;
  139.       }
  140.  
  141.    }
  142.  
  143.    public Object remove(Enumeration var1) {
  144.       throw new InvalidOperationException("cannot execute remove() on a priority queue");
  145.    }
  146.  
  147.    public int remove(Enumeration var1, Enumeration var2) {
  148.       throw new InvalidOperationException("cannot execute remove() on a priority queue");
  149.    }
  150. }
  151.