home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / windowsxp / ftgateoffice / ftgateoffice.exe / Main / webhelp.jar / treeview / SiblingChildTree.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-11-07  |  1.9 KB  |  194 lines

  1. package treeview;
  2.  
  3. public class SiblingChildTree {
  4.    protected SiblingChildTree parent = null;
  5.    protected SiblingChildTree sibling_left = null;
  6.    protected SiblingChildTree sibling_right = null;
  7.    protected SiblingChildTree child = null;
  8.  
  9.    public SiblingChildTree getChild() {
  10.       return this.child;
  11.    }
  12.  
  13.    public SiblingChildTree pruneThisSubtree() {
  14.       if (this.sibling_left != null) {
  15.          this.sibling_left.sibling_right = this.sibling_right;
  16.          if (this.sibling_right != null) {
  17.             this.sibling_right.sibling_left = this.sibling_left;
  18.          }
  19.       } else {
  20.          if (this.sibling_right != null) {
  21.             this.sibling_right.sibling_left = null;
  22.          }
  23.  
  24.          if (this.parent != null) {
  25.             this.parent.child = this.sibling_right;
  26.          }
  27.       }
  28.  
  29.       SiblingChildTree var1;
  30.       for(var1 = this; var1.parent != null; var1 = var1.parent) {
  31.       }
  32.  
  33.       while(var1.sibling_left != null) {
  34.          var1 = var1.sibling_left;
  35.       }
  36.  
  37.       if (var1 == this) {
  38.          var1 = this.sibling_right;
  39.       }
  40.  
  41.       this.parent = null;
  42.       this.sibling_left = null;
  43.       this.sibling_right = null;
  44.       return var1;
  45.    }
  46.  
  47.    protected void setParent(SiblingChildTree var1) {
  48.       this.parent = var1;
  49.       if (this.sibling_right != null) {
  50.          this.sibling_right.setParent(var1);
  51.       }
  52.  
  53.    }
  54.  
  55.    public SiblingChildTree getParent() {
  56.       return this.parent;
  57.    }
  58.  
  59.    public SiblingChildTree nextNode() {
  60.       if (this.child != null) {
  61.          return this.child;
  62.       } else if (this.sibling_right != null) {
  63.          return this.sibling_right;
  64.       } else {
  65.          for(SiblingChildTree var1 = this.parent; var1 != null; var1 = var1.parent) {
  66.             if (var1.sibling_right != null) {
  67.                return var1.sibling_right;
  68.             }
  69.          }
  70.  
  71.          return null;
  72.       }
  73.    }
  74.  
  75.    public SiblingChildTree getSibling() {
  76.       return this.sibling_right;
  77.    }
  78.  
  79.    public SiblingChildTree prevNode() {
  80.       if (this.sibling_left == null) {
  81.          return this.parent != null ? this.lastBeforeMatch(this.parent) : null;
  82.       } else {
  83.          SiblingChildTree var1 = this.sibling_left.child;
  84.          if (var1 == null) {
  85.             return this.sibling_left;
  86.          } else {
  87.             while(var1.sibling_right != null) {
  88.                var1 = var1.sibling_right;
  89.             }
  90.  
  91.             return this.lastBeforeMatch(var1);
  92.          }
  93.       }
  94.    }
  95.  
  96.    private SiblingChildTree lastBeforeMatch(SiblingChildTree var1) {
  97.       SiblingChildTree var2 = null;
  98.  
  99.       do {
  100.          if (var2 != null) {
  101.             var1 = var2;
  102.          }
  103.  
  104.          var2 = var1.nextNode();
  105.       } while(var2 != this);
  106.  
  107.       return var1;
  108.    }
  109.  
  110.    public SiblingChildTree[] getChildren() {
  111.       SiblingChildTree[] var1 = new SiblingChildTree[this.numberOfChildren()];
  112.       SiblingChildTree var2 = this.child;
  113.  
  114.       for(int var3 = 0; var3 < var1.length; ++var3) {
  115.          var1[var3] = var2;
  116.          var2 = var2.sibling_right;
  117.       }
  118.  
  119.       return var1;
  120.    }
  121.  
  122.    public int numberOfChildren() {
  123.       int var1 = 0;
  124.  
  125.       for(SiblingChildTree var2 = this.child; var2 != null; var2 = var2.sibling_right) {
  126.          ++var1;
  127.       }
  128.  
  129.       return var1;
  130.    }
  131.  
  132.    public SiblingChildTree pruneChildren() {
  133.       if (this.child == null) {
  134.          return null;
  135.       } else {
  136.          this.child.setParent((SiblingChildTree)null);
  137.          SiblingChildTree var1 = this.child;
  138.          this.child = null;
  139.          return var1;
  140.       }
  141.    }
  142.  
  143.    public boolean isSibling(SiblingChildTree var1) {
  144.       if (this == var1) {
  145.          return false;
  146.       } else {
  147.          SiblingChildTree var2;
  148.          for(var2 = this; var2.sibling_left != null; var2 = var2.sibling_left) {
  149.          }
  150.  
  151.          while(var2 != null) {
  152.             if (var2 == var1) {
  153.                return true;
  154.             }
  155.  
  156.             var2 = var2.sibling_right;
  157.          }
  158.  
  159.          return false;
  160.       }
  161.    }
  162.  
  163.    public void addChild(SiblingChildTree var1) {
  164.       if (var1 == null) {
  165.          throw new IllegalArgumentException("SiblingChildTree.addChild(): child is a null reference");
  166.       } else if (this.child == null) {
  167.          this.child = var1;
  168.          var1.setParent(this);
  169.       } else {
  170.          this.child.addSibling(var1);
  171.       }
  172.    }
  173.  
  174.    public SiblingChildTree getSiblingLeft() {
  175.       return this.sibling_left;
  176.    }
  177.  
  178.    public void addSibling(SiblingChildTree var1) {
  179.       if (var1 == null) {
  180.          throw new IllegalArgumentException("SiblingChildTree.addSibling(): sibling is a null reference");
  181.       } else if (this.sibling_right == null) {
  182.          this.sibling_right = var1;
  183.          var1.sibling_left = this;
  184.          var1.setParent(this.parent);
  185.       } else {
  186.          SiblingChildTree var2;
  187.          for(var2 = this.sibling_right; var2.getSibling() != null; var2 = var2.getSibling()) {
  188.          }
  189.  
  190.          var2.addSibling(var1);
  191.       }
  192.    }
  193. }
  194.