home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-30 | 1011 b | 38 lines |
- package borland.samples.intl.beans;
-
- import borland.jbcl.model.*;
- import borland.jbcl.util.*;
-
- /**
- * Extends BasicTreeContainer with a method for adding child nodes
- * to the tree in collated order.
- */
- public class BasicOrderedTreeContainer extends BasicTreeContainer {
-
- public BasicOrderedTreeContainer() {
- }
-
- public BasicOrderedTreeContainer(Object root) {
- super(root);
- }
-
- public GraphLocation addOrderedChild(GraphLocation gl, Object data, BinaryComparator binaryComparator) {
- int compareResult;
-
- LinkedTreeNode compareTreeNode = ((LinkedTreeNode) gl).getFirstChild();
- while (compareTreeNode != null) {
- compareResult = binaryComparator.compare(data, get(compareTreeNode));
- if (compareResult < 0) {
- return super.addChild(gl, compareTreeNode, data);
- }
- if (compareResult == 0) {
- return compareTreeNode;
- }
- compareTreeNode = compareTreeNode.getNextSibling();
- }
- return super.addChild(gl, data);
- }
-
- }
-
-