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 / OrderedSet.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-03-12  |  8.4 KB  |  370 lines

  1. package COM.objectspace.jgl;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.util.Enumeration;
  7.  
  8. public class OrderedSet implements Set {
  9.    transient Tree myTree;
  10.  
  11.    public OrderedSet() {
  12.       this.myTree = new Tree(false, false, this);
  13.    }
  14.  
  15.    public OrderedSet(boolean var1) {
  16.       this.myTree = new Tree(false, var1, this);
  17.    }
  18.  
  19.    public OrderedSet(BinaryPredicate var1) {
  20.       this.myTree = new Tree(false, false, var1, this);
  21.    }
  22.  
  23.    public OrderedSet(BinaryPredicate var1, boolean var2) {
  24.       this.myTree = new Tree(false, var2, var1, this);
  25.    }
  26.  
  27.    public OrderedSet(OrderedSet var1) {
  28.       synchronized(var1){}
  29.  
  30.       try {
  31.          this.myTree = new Tree(var1.myTree);
  32.       } catch (Throwable var4) {
  33.          throw var4;
  34.       }
  35.  
  36.    }
  37.  
  38.    public boolean allowsDuplicates() {
  39.       return this.myTree.myInsertAlways;
  40.    }
  41.  
  42.    public synchronized Object clone() {
  43.       return new OrderedSet(this);
  44.    }
  45.  
  46.    public synchronized void copy(OrderedSet var1) {
  47.       synchronized(var1){}
  48.  
  49.       try {
  50.          Tree var4 = this.myTree;
  51.          Tree var5 = var1.myTree;
  52.          if (var4 != var5) {
  53.             var4.clear();
  54.             var4.copyTree(var5);
  55.          }
  56.       } catch (Throwable var7) {
  57.          throw var7;
  58.       }
  59.  
  60.    }
  61.  
  62.    public synchronized String toString() {
  63.       return "OrderedSet" + Printing.toString(this.start(), this.finish());
  64.    }
  65.  
  66.    public synchronized Enumeration elements() {
  67.       Tree var1 = this.myTree;
  68.       return new OrderedSetIterator(var1, var1.myHeader.left, (OrderedSet)var1.myContainer);
  69.    }
  70.  
  71.    public ForwardIterator start() {
  72.       return this.begin();
  73.    }
  74.  
  75.    public ForwardIterator finish() {
  76.       return this.end();
  77.    }
  78.  
  79.    public synchronized OrderedSetIterator begin() {
  80.       Tree var1 = this.myTree;
  81.       return new OrderedSetIterator(var1, var1.myHeader.left, (OrderedSet)var1.myContainer);
  82.    }
  83.  
  84.    public synchronized OrderedSetIterator end() {
  85.       Tree var1 = this.myTree;
  86.       return new OrderedSetIterator(var1, var1.myHeader, (OrderedSet)var1.myContainer);
  87.    }
  88.  
  89.    public boolean isEmpty() {
  90.       return this.myTree.size == 0;
  91.    }
  92.  
  93.    public int size() {
  94.       return this.myTree.size;
  95.    }
  96.  
  97.    public int maxSize() {
  98.       Tree var1 = this.myTree;
  99.       return Integer.MAX_VALUE;
  100.    }
  101.  
  102.    public boolean equals(Object var1) {
  103.       return var1 instanceof OrderedSet && this.equals((OrderedSet)var1);
  104.    }
  105.  
  106.    public synchronized boolean equals(OrderedSet var1) {
  107.       synchronized(var1){}
  108.  
  109.       boolean var2;
  110.       try {
  111.          var2 = this.size() == var1.size() && Comparing.equal(this.start(), this.finish(), var1.start());
  112.       } catch (Throwable var8) {
  113.          throw var8;
  114.       }
  115.  
  116.       return var2;
  117.    }
  118.  
  119.    public synchronized int hashCode() {
  120.       return Hashing.orderedHash(this.start(), this.finish());
  121.    }
  122.  
  123.    public synchronized void swap(OrderedSet var1) {
  124.       synchronized(var1){}
  125.  
  126.       try {
  127.          Tree var4 = this.myTree;
  128.          this.myTree = var1.myTree;
  129.          var1.myTree = var4;
  130.       } catch (Throwable var6) {
  131.          throw var6;
  132.       }
  133.  
  134.    }
  135.  
  136.    public synchronized void clear() {
  137.       this.myTree.clear();
  138.    }
  139.  
  140.    public synchronized int remove(Object var1) {
  141.       Pair var2 = this.myTree.remove(var1);
  142.       return ((Number)var2.second).intValue();
  143.    }
  144.  
  145.    public synchronized int remove(Object var1, int var2) {
  146.       Pair var3 = this.myTree.remove(var1, var2);
  147.       return ((Number)var3.second).intValue();
  148.    }
  149.  
  150.    public synchronized Object remove(Enumeration var1) {
  151.       if (!(var1 instanceof OrderedSetIterator)) {
  152.          throw new IllegalArgumentException("Enumeration not a OrderedSetIterator");
  153.       } else if (((OrderedSetIterator)var1).myOrderedSet != this) {
  154.          throw new IllegalArgumentException("Enumeration not for this OrderedSet");
  155.       } else {
  156.          Tree.TreeNode var2 = this.myTree.remove(((OrderedSetIterator)var1).myNode);
  157.          return var2 == null ? null : var2.object;
  158.       }
  159.    }
  160.  
  161.    public synchronized int remove(Enumeration var1, Enumeration var2) {
  162.       if (var1 instanceof OrderedSetIterator && var2 instanceof OrderedSetIterator) {
  163.          if (((OrderedSetIterator)var1).myOrderedSet == this && ((OrderedSetIterator)var2).myOrderedSet == this) {
  164.             Tree var3 = this.myTree;
  165.             Tree.TreeNode var4 = ((OrderedSetIterator)var1).myNode;
  166.             Tree.TreeNode var5 = ((OrderedSetIterator)var2).myNode;
  167.             Pair var6 = var3.remove(var4, var5, var3.size);
  168.             return ((Number)var6.second).intValue();
  169.          } else {
  170.             throw new IllegalArgumentException("Enumeration not for this OrderedSet");
  171.          }
  172.       } else {
  173.          throw new IllegalArgumentException("Enumeration not a OrderedSetIterator");
  174.       }
  175.    }
  176.  
  177.    public synchronized OrderedSetIterator find(Object var1) {
  178.       return new OrderedSetIterator(this.myTree, this.myTree.find(var1), this);
  179.    }
  180.  
  181.    public synchronized int count(Object var1) {
  182.       return this.myTree.count(var1);
  183.    }
  184.  
  185.    public synchronized OrderedSetIterator lowerBound(Object var1) {
  186.       Tree var2;
  187.       return new OrderedSetIterator(var2 = this.myTree, (Tree.TreeNode)var2.equalRange(var1).first, this);
  188.    }
  189.  
  190.    public synchronized OrderedSetIterator upperBound(Object var1) {
  191.       Tree var2;
  192.       return new OrderedSetIterator(var2 = this.myTree, (Tree.TreeNode)var2.equalRange(var1).second, this);
  193.    }
  194.  
  195.    public synchronized Range equalRange(Object var1) {
  196.       Pair var2 = this.myTree.equalRange(var1);
  197.       return new Range(new OrderedSetIterator(this.myTree, (Tree.TreeNode)var2.first, this), new OrderedSetIterator(this.myTree, (Tree.TreeNode)var2.second, this));
  198.    }
  199.  
  200.    public BinaryPredicate getComparator() {
  201.       return this.myTree.myComparator;
  202.    }
  203.  
  204.    public synchronized Object add(Object var1) {
  205.       if (var1 == null) {
  206.          throw new NullPointerException();
  207.       } else {
  208.          Tree var2 = this.myTree;
  209.          Tree.InsertResult var3 = var2.insertAux(var1, true);
  210.          return var3.ok ? null : var3.node.object;
  211.       }
  212.    }
  213.  
  214.    public synchronized Object get(Object var1) {
  215.       Tree.TreeNode var2 = this.myTree.find(var1);
  216.       if (var2.object == null) {
  217.          return null;
  218.       } else {
  219.          return var2.object.equals(var1) ? var2.object : null;
  220.       }
  221.    }
  222.  
  223.    public synchronized Object put(Object var1) {
  224.       if (var1 == null) {
  225.          throw new NullPointerException();
  226.       } else {
  227.          Tree var2 = this.myTree;
  228.          Tree.InsertResult var4 = var2.insertAux(var1, false);
  229.          if (var4.ok) {
  230.             return null;
  231.          } else {
  232.             Object var3 = var4.node.object;
  233.             var4.node.object = var1;
  234.             return var3;
  235.          }
  236.       }
  237.    }
  238.  
  239.    public synchronized OrderedSet union(OrderedSet var1) {
  240.       if (!this.myTree.myInsertAlways && !var1.myTree.myInsertAlways) {
  241.          OrderedSet var2 = new OrderedSet(this.getComparator(), this.allowsDuplicates());
  242.          InsertIterator var5 = new InsertIterator(var2);
  243.          BinaryPredicate var6 = this.getComparator();
  244.          SetOperations.setUnion(this.start(), this.finish(), var1.start(), var1.finish(), var5, var6);
  245.          return var2;
  246.       } else {
  247.          throw new InvalidOperationException("union operation invalid on multisets");
  248.       }
  249.    }
  250.  
  251.    public synchronized OrderedSet intersection(OrderedSet var1) {
  252.       synchronized(var1){}
  253.  
  254.       OrderedSet var2;
  255.       try {
  256.          if (this.myTree.myInsertAlways || var1.myTree.myInsertAlways) {
  257.             throw new InvalidOperationException("intersection operation invalid on multisets");
  258.          }
  259.  
  260.          OrderedSet var5 = new OrderedSet(this.getComparator(), this.allowsDuplicates());
  261.          InsertIterator var8 = new InsertIterator(var5);
  262.          BinaryPredicate var9 = this.getComparator();
  263.          SetOperations.setIntersection(this.start(), this.finish(), var1.start(), var1.finish(), var8, var9);
  264.          var2 = var5;
  265.       } catch (Throwable var11) {
  266.          throw var11;
  267.       }
  268.  
  269.       return var2;
  270.    }
  271.  
  272.    public synchronized OrderedSet difference(OrderedSet var1) {
  273.       synchronized(var1){}
  274.  
  275.       OrderedSet var2;
  276.       try {
  277.          if (this.myTree.myInsertAlways || var1.myTree.myInsertAlways) {
  278.             throw new InvalidOperationException("difference operation invalid on multisets");
  279.          }
  280.  
  281.          OrderedSet var5 = new OrderedSet(this.getComparator(), this.allowsDuplicates());
  282.          InsertIterator var8 = new InsertIterator(var5);
  283.          BinaryPredicate var9 = this.getComparator();
  284.          SetOperations.setDifference(this.start(), this.finish(), var1.start(), var1.finish(), var8, var9);
  285.          var2 = var5;
  286.       } catch (Throwable var11) {
  287.          throw var11;
  288.       }
  289.  
  290.       return var2;
  291.    }
  292.  
  293.    public synchronized OrderedSet symmetricDifference(OrderedSet var1) {
  294.       synchronized(var1){}
  295.  
  296.       OrderedSet var2;
  297.       try {
  298.          if (this.myTree.myInsertAlways || var1.myTree.myInsertAlways) {
  299.             throw new InvalidOperationException("symmetricDifference operation invalid on multisets");
  300.          }
  301.  
  302.          OrderedSet var5 = new OrderedSet(this.getComparator(), this.allowsDuplicates());
  303.          InsertIterator var8 = new InsertIterator(var5);
  304.          BinaryPredicate var9 = this.getComparator();
  305.          SetOperations.setSymmetricDifference(this.start(), this.finish(), var1.start(), var1.finish(), var8, var9);
  306.          var2 = var5;
  307.       } catch (Throwable var11) {
  308.          throw var11;
  309.       }
  310.  
  311.       return var2;
  312.    }
  313.  
  314.    public synchronized boolean subsetOf(OrderedSet var1) {
  315.       synchronized(var1){}
  316.  
  317.       boolean var2;
  318.       try {
  319.          if (this.myTree.myInsertAlways || var1.myTree.myInsertAlways) {
  320.             throw new InvalidOperationException("subsetOf operation invalid on multisets");
  321.          }
  322.  
  323.          BinaryPredicate var7 = this.getComparator();
  324.          var2 = SetOperations.includes(var1.start(), var1.finish(), this.start(), this.finish(), var7);
  325.       } catch (Throwable var9) {
  326.          throw var9;
  327.       }
  328.  
  329.       return var2;
  330.    }
  331.  
  332.    public synchronized boolean properSubsetOf(OrderedSet var1) {
  333.       synchronized(var1){}
  334.  
  335.       boolean var2;
  336.       try {
  337.          if (this.myTree.myInsertAlways || var1.myTree.myInsertAlways) {
  338.             throw new InvalidOperationException("properSubsetOf operation invalid on multisets");
  339.          }
  340.  
  341.          var2 = this.size() < var1.size() && this.subsetOf(var1);
  342.       } catch (Throwable var6) {
  343.          throw var6;
  344.       }
  345.  
  346.       return var2;
  347.    }
  348.  
  349.    private synchronized void writeObject(ObjectOutputStream var1) throws IOException {
  350.       var1.defaultWriteObject();
  351.       var1.writeBoolean(this.allowsDuplicates());
  352.       var1.writeObject(this.getComparator());
  353.       var1.writeInt(this.size());
  354.       Copying.copy(this.begin(), this.end(), new ObjectOutputStreamIterator(var1));
  355.    }
  356.  
  357.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  358.       var1.defaultReadObject();
  359.       boolean var2 = var1.readBoolean();
  360.       BinaryPredicate var3 = (BinaryPredicate)var1.readObject();
  361.       this.myTree = new Tree(false, var2, var3, this);
  362.       int var4 = var1.readInt();
  363.  
  364.       while(var4-- > 0) {
  365.          this.add(var1.readObject());
  366.       }
  367.  
  368.    }
  369. }
  370.