KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > Box


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.digester;
18
19 import java.util.List JavaDoc;
20 import java.util.LinkedList JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 /**
24  * Simple class for use in unit tests. A box has an ID, and can have
25  * multiple boxes within it.
26  */

27 public class Box {
28     private String JavaDoc id;
29     
30     private List JavaDoc children = new LinkedList JavaDoc();
31
32     public Box() {}
33     
34     public String JavaDoc getId() {
35         return id;
36     }
37     
38     public void setId(String JavaDoc id) {
39         this.id = id;
40     }
41     
42     public void addChild(Box child) {
43         this.children.add(child);
44     }
45     
46     public List JavaDoc getChildren() {
47         return children;
48     }
49     
50     public String JavaDoc toString()
51     {
52         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
53         buf.append("[Box] id=");
54         buf.append(id);
55         buf.append(" nchildren=");
56         buf.append(children.size());
57         
58         for(Iterator JavaDoc i = children.iterator(); i.hasNext(); ) {
59             Box child = (Box) i.next();
60             buf.append(" ");
61             buf.append(child.toString());
62         }
63         return buf.toString();
64     }
65     
66     /**
67      * Return a string containing this object's name value, followed by the
68      * names of all child objects (and their children etc) in pre-order
69      * sequence. Each name is separated by a space from the preceding one.
70      */

71     public String JavaDoc getIds() {
72         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
73         buf.append(this.id);
74         for(Iterator JavaDoc i = children.iterator(); i.hasNext(); ) {
75             Box child = (Box) i.next();
76             buf.append(" ");
77             buf.append(child.getIds());
78         }
79         return buf.toString();
80     }
81 }
82
Popular Tags