home *** CD-ROM | disk | FTP | other *** search
- package treeview;
-
- public class SiblingChildTree {
- protected SiblingChildTree parent = null;
- protected SiblingChildTree sibling_left = null;
- protected SiblingChildTree sibling_right = null;
- protected SiblingChildTree child = null;
-
- public SiblingChildTree getChild() {
- return this.child;
- }
-
- public SiblingChildTree pruneThisSubtree() {
- if (this.sibling_left != null) {
- this.sibling_left.sibling_right = this.sibling_right;
- if (this.sibling_right != null) {
- this.sibling_right.sibling_left = this.sibling_left;
- }
- } else {
- if (this.sibling_right != null) {
- this.sibling_right.sibling_left = null;
- }
-
- if (this.parent != null) {
- this.parent.child = this.sibling_right;
- }
- }
-
- SiblingChildTree var1;
- for(var1 = this; var1.parent != null; var1 = var1.parent) {
- }
-
- while(var1.sibling_left != null) {
- var1 = var1.sibling_left;
- }
-
- if (var1 == this) {
- var1 = this.sibling_right;
- }
-
- this.parent = null;
- this.sibling_left = null;
- this.sibling_right = null;
- return var1;
- }
-
- protected void setParent(SiblingChildTree var1) {
- this.parent = var1;
- if (this.sibling_right != null) {
- this.sibling_right.setParent(var1);
- }
-
- }
-
- public SiblingChildTree getParent() {
- return this.parent;
- }
-
- public SiblingChildTree nextNode() {
- if (this.child != null) {
- return this.child;
- } else if (this.sibling_right != null) {
- return this.sibling_right;
- } else {
- for(SiblingChildTree var1 = this.parent; var1 != null; var1 = var1.parent) {
- if (var1.sibling_right != null) {
- return var1.sibling_right;
- }
- }
-
- return null;
- }
- }
-
- public SiblingChildTree getSibling() {
- return this.sibling_right;
- }
-
- public SiblingChildTree prevNode() {
- if (this.sibling_left == null) {
- return this.parent != null ? this.lastBeforeMatch(this.parent) : null;
- } else {
- SiblingChildTree var1 = this.sibling_left.child;
- if (var1 == null) {
- return this.sibling_left;
- } else {
- while(var1.sibling_right != null) {
- var1 = var1.sibling_right;
- }
-
- return this.lastBeforeMatch(var1);
- }
- }
- }
-
- private SiblingChildTree lastBeforeMatch(SiblingChildTree var1) {
- SiblingChildTree var2 = null;
-
- do {
- if (var2 != null) {
- var1 = var2;
- }
-
- var2 = var1.nextNode();
- } while(var2 != this);
-
- return var1;
- }
-
- public SiblingChildTree[] getChildren() {
- SiblingChildTree[] var1 = new SiblingChildTree[this.numberOfChildren()];
- SiblingChildTree var2 = this.child;
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- var1[var3] = var2;
- var2 = var2.sibling_right;
- }
-
- return var1;
- }
-
- public int numberOfChildren() {
- int var1 = 0;
-
- for(SiblingChildTree var2 = this.child; var2 != null; var2 = var2.sibling_right) {
- ++var1;
- }
-
- return var1;
- }
-
- public SiblingChildTree pruneChildren() {
- if (this.child == null) {
- return null;
- } else {
- this.child.setParent((SiblingChildTree)null);
- SiblingChildTree var1 = this.child;
- this.child = null;
- return var1;
- }
- }
-
- public boolean isSibling(SiblingChildTree var1) {
- if (this == var1) {
- return false;
- } else {
- SiblingChildTree var2;
- for(var2 = this; var2.sibling_left != null; var2 = var2.sibling_left) {
- }
-
- while(var2 != null) {
- if (var2 == var1) {
- return true;
- }
-
- var2 = var2.sibling_right;
- }
-
- return false;
- }
- }
-
- public void addChild(SiblingChildTree var1) {
- if (var1 == null) {
- throw new IllegalArgumentException("SiblingChildTree.addChild(): child is a null reference");
- } else if (this.child == null) {
- this.child = var1;
- var1.setParent(this);
- } else {
- this.child.addSibling(var1);
- }
- }
-
- public SiblingChildTree getSiblingLeft() {
- return this.sibling_left;
- }
-
- public void addSibling(SiblingChildTree var1) {
- if (var1 == null) {
- throw new IllegalArgumentException("SiblingChildTree.addSibling(): sibling is a null reference");
- } else if (this.sibling_right == null) {
- this.sibling_right = var1;
- var1.sibling_left = this;
- var1.setParent(this.parent);
- } else {
- SiblingChildTree var2;
- for(var2 = this.sibling_right; var2.getSibling() != null; var2 = var2.getSibling()) {
- }
-
- var2.addSibling(var1);
- }
- }
- }
-