home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / xml4j.jar / com / ibm / xml / parser / CM2op.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-30  |  2.7 KB  |  130 lines

  1. package com.ibm.xml.parser;
  2.  
  3. import java.util.BitSet;
  4.  
  5. public class CM2op extends CMNode {
  6.    static final long serialVersionUID = 3303486725862458161L;
  7.    int type;
  8.    CMNode leftNode;
  9.    CMNode rightNode;
  10.  
  11.    public CM2op(int var1, CMNode var2, CMNode var3) {
  12.       this.type = var1;
  13.       this.leftNode = var2;
  14.       this.rightNode = var3;
  15.    }
  16.  
  17.    public int getType() {
  18.       return this.type;
  19.    }
  20.  
  21.    public CMNode getLeft() {
  22.       return this.leftNode;
  23.    }
  24.  
  25.    public void setLeft(CMNode var1) {
  26.       this.leftNode = var1;
  27.    }
  28.  
  29.    public CMNode getRight() {
  30.       return this.rightNode;
  31.    }
  32.  
  33.    public void setRight(CMNode var1) {
  34.       this.rightNode = var1;
  35.    }
  36.  
  37.    public String toString() {
  38.       return this.leftNode instanceof CM2op && ((CM2op)this.leftNode).type == this.type ? "(" + ((CM2op)this.leftNode).toStringWithoutParen() + (char)this.type + this.rightNode.toString() + ")" : "(" + this.leftNode.toString() + (char)this.type + this.rightNode.toString() + ")";
  39.    }
  40.  
  41.    String toStringWithoutParen() {
  42.       return this.leftNode instanceof CM2op && ((CM2op)this.leftNode).type == this.type ? ((CM2op)this.leftNode).toStringWithoutParen() + (char)this.type + this.rightNode.toString() : this.leftNode.toString() + (char)this.type + this.rightNode.toString();
  43.    }
  44.  
  45.    CMNode cloneNode() {
  46.       return new CM2op(this.type, this.leftNode.cloneNode(), this.rightNode.cloneNode());
  47.    }
  48.  
  49.    boolean nullable() {
  50.       if (super.nullable == null) {
  51.          switch (this.type) {
  52.             case 44:
  53.                super.nullable = new Boolean(this.leftNode.nullable() && this.rightNode.nullable());
  54.                break;
  55.             case 124:
  56.                super.nullable = new Boolean(this.leftNode.nullable() || this.rightNode.nullable());
  57.          }
  58.       }
  59.  
  60.       return super.nullable;
  61.    }
  62.  
  63.    BitSet firstpos() {
  64.       if (super.firstPos == null) {
  65.          if (this.type == 124) {
  66.             super.firstPos = (BitSet)this.leftNode.firstpos().clone();
  67.             super.firstPos.or(this.rightNode.firstpos());
  68.          } else if (this.leftNode.nullable()) {
  69.             super.firstPos = (BitSet)this.leftNode.firstpos().clone();
  70.             super.firstPos.or(this.rightNode.firstpos());
  71.          } else {
  72.             super.firstPos = this.leftNode.firstpos();
  73.          }
  74.       }
  75.  
  76.       return super.firstPos;
  77.    }
  78.  
  79.    BitSet lastpos() {
  80.       if (super.lastPos == null) {
  81.          if (this.type == 124) {
  82.             super.lastPos = (BitSet)this.leftNode.lastpos().clone();
  83.             super.lastPos.or(this.rightNode.lastpos());
  84.          } else if (this.rightNode.nullable()) {
  85.             super.lastPos = (BitSet)this.leftNode.lastpos().clone();
  86.             super.lastPos.or(this.rightNode.lastpos());
  87.          } else {
  88.             super.lastPos = this.rightNode.lastpos();
  89.          }
  90.       }
  91.  
  92.       return super.lastPos;
  93.    }
  94.  
  95.    void prepare(int var1) {
  96.       this.leftNode.prepare(var1);
  97.       this.rightNode.prepare(var1);
  98.    }
  99.  
  100.    void setFollowpos(BitSet[] var1) {
  101.       this.leftNode.setFollowpos(var1);
  102.       this.rightNode.setFollowpos(var1);
  103.       if (this.type != 124 && this.type == 44) {
  104.          for(int var2 = 0; var2 < var1.length; ++var2) {
  105.             if (this.leftNode.lastpos().get(var2)) {
  106.                var1[var2].or(this.rightNode.firstpos());
  107.             }
  108.          }
  109.       }
  110.  
  111.    }
  112.  
  113.    public boolean equals(Object var1) {
  114.       if (!(var1 instanceof CM2op)) {
  115.          return false;
  116.       } else {
  117.          CM2op var2 = (CM2op)var1;
  118.          if (var2.getType() != this.getType()) {
  119.             return false;
  120.          } else {
  121.             return var2.getLeft().equals(this.getLeft()) && var2.getRight().equals(this.getRight());
  122.          }
  123.       }
  124.    }
  125.  
  126.    public int hashCode() {
  127.       return this.getLeft().hashCode() + this.getRight().hashCode();
  128.    }
  129. }
  130.