< prev index next >

src/com/sun/javatest/util/HelpTree.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 151         public Node getChild(int i) {
 152             if (i >= getChildCount())
 153                 throw new IllegalArgumentException();
 154             return children[i];
 155         }
 156 
 157         private String name;
 158         private String description;
 159         private Node[] children;
 160     }
 161 
 162     /**
 163      * A selection of nodes within a HelpTree.
 164      * @see HelpTree#find
 165      */
 166     public class Selection {
 167         private Selection(Node node) {
 168             this(node, null);
 169         }
 170 
 171         private Selection(Map map) {
 172             this(null, map);
 173         }
 174 
 175         private Selection(Node node, Map map) {
 176             this.node = node;
 177             this.map = map;
 178         }
 179 
 180         private Node node;
 181         private Map map;
 182     }
 183 
 184     /**
 185      * Create an empty HelpTree object.
 186      */
 187     public HelpTree() {
 188         nodes = new Node[0];
 189     }
 190 
 191     /**
 192      * Create a HelpTree object containing a given set of nodes.
 193      * @param nodes the contents of the HelpTree
 194      */
 195     public HelpTree(Node[] nodes) {
 196         this.nodes = nodes;
 197     }
 198 
 199     /**
 200      * Add a node to a help tree.
 201      * @param node the node to be added to the tree


 396     }
 397 
 398     /**
 399      * Sets the comparator which will be used in {@link #find(String[]) find} methods
 400      * method
 401      * @param comparator Comparator to set
 402      */
 403     public void setNodeComparator(Comparator<Node> comparator){
 404         nodeComparator = comparator;
 405     }
 406 
 407     /**
 408      * Returns current comparator used in {@link #find(String[]) find} methods
 409      * method
 410      * @return current node comparator
 411      */
 412     public Comparator<Node> getNodeComparator(){
 413         return nodeComparator;
 414     }
 415 
 416     private void write(WrapWriter out, Map m) throws IOException {
 417         int margin = out.getLeftMargin();
 418         for (Iterator iter = m.entrySet().iterator(); iter.hasNext(); ) {
 419             Map.Entry e = (Map.Entry) (iter.next());
 420             Node node = (Node) (e.getKey());
 421             Selection s = (Selection) (e.getValue());
 422             if (s.map == null)
 423                 write(out, node);
 424             else {
 425                 writeHead(out, node);
 426                 out.setLeftMargin(margin + nodeIndent);
 427                 write(out, s.map);
 428                 out.setLeftMargin(margin);
 429             }
 430             if (margin == 0)
 431                 out.write('\n');
 432         }
 433     }
 434 
 435     private void write(WrapWriter out, Node node) throws IOException {
 436         int baseMargin = out.getLeftMargin();
 437 
 438         writeHead(out, node);
 439 
 440         Node[] children = node.children;
 441         if (children != null && children.length > 0) {




 151         public Node getChild(int i) {
 152             if (i >= getChildCount())
 153                 throw new IllegalArgumentException();
 154             return children[i];
 155         }
 156 
 157         private String name;
 158         private String description;
 159         private Node[] children;
 160     }
 161 
 162     /**
 163      * A selection of nodes within a HelpTree.
 164      * @see HelpTree#find
 165      */
 166     public class Selection {
 167         private Selection(Node node) {
 168             this(node, null);
 169         }
 170 
 171         private Selection(Map<Node, Selection> map) {
 172             this(null, map);
 173         }
 174 
 175         private Selection(Node node, Map<Node, Selection> map) {
 176             this.node = node;
 177             this.map = map;
 178         }
 179 
 180         private Node node;
 181         private Map<Node, Selection> map;
 182     }
 183 
 184     /**
 185      * Create an empty HelpTree object.
 186      */
 187     public HelpTree() {
 188         nodes = new Node[0];
 189     }
 190 
 191     /**
 192      * Create a HelpTree object containing a given set of nodes.
 193      * @param nodes the contents of the HelpTree
 194      */
 195     public HelpTree(Node[] nodes) {
 196         this.nodes = nodes;
 197     }
 198 
 199     /**
 200      * Add a node to a help tree.
 201      * @param node the node to be added to the tree


 396     }
 397 
 398     /**
 399      * Sets the comparator which will be used in {@link #find(String[]) find} methods
 400      * method
 401      * @param comparator Comparator to set
 402      */
 403     public void setNodeComparator(Comparator<Node> comparator){
 404         nodeComparator = comparator;
 405     }
 406 
 407     /**
 408      * Returns current comparator used in {@link #find(String[]) find} methods
 409      * method
 410      * @return current node comparator
 411      */
 412     public Comparator<Node> getNodeComparator(){
 413         return nodeComparator;
 414     }
 415 
 416     private void write(WrapWriter out, Map<Node, Selection> m) throws IOException {
 417         int margin = out.getLeftMargin();
 418         for (Iterator<Map.Entry<Node, Selection>> iter = m.entrySet().iterator(); iter.hasNext(); ) {
 419             Map.Entry<Node, Selection> e = iter.next();
 420             Node node = (e.getKey());
 421             Selection s = (e.getValue());
 422             if (s.map == null)
 423                 write(out, node);
 424             else {
 425                 writeHead(out, node);
 426                 out.setLeftMargin(margin + nodeIndent);
 427                 write(out, s.map);
 428                 out.setLeftMargin(margin);
 429             }
 430             if (margin == 0)
 431                 out.write('\n');
 432         }
 433     }
 434 
 435     private void write(WrapWriter out, Node node) throws IOException {
 436         int baseMargin = out.getLeftMargin();
 437 
 438         writeHead(out, node);
 439 
 440         Node[] children = node.children;
 441         if (children != null && children.length > 0) {


< prev index next >