1 /* $Id: Box.java 1102402 2011-05-12 18:03:26Z simonetripodi $ 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one or more 4 * contributor license agreements. See the NOTICE file distributed with 5 * this work for additional information regarding copyright ownership. 6 * The ASF licenses this file to You under the Apache License, Version 2.0 7 * (the "License"); you may not use this file except in compliance with 8 * the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.commons.digester3; 20 21 import java.util.LinkedList; 22 import java.util.List; 23 24 /** 25 * Simple class for use in unit tests. A box has an ID, and can have multiple boxes within it. 26 */ 27 public class Box 28 { 29 private String id; 30 31 private List<Box> children = new LinkedList<Box>(); 32 33 public Box() 34 { 35 } 36 37 public String getId() 38 { 39 return id; 40 } 41 42 public void setId( String id ) 43 { 44 this.id = id; 45 } 46 47 public void addChild( Box child ) 48 { 49 this.children.add( child ); 50 } 51 52 public List<Box> getChildren() 53 { 54 return children; 55 } 56 57 @Override 58 public String toString() 59 { 60 StringBuilder buf = new StringBuilder(); 61 buf.append( "[Box] id=" ); 62 buf.append( id ); 63 buf.append( " nchildren=" ); 64 buf.append( children.size() ); 65 66 for ( Box child : children ) 67 { 68 buf.append( " " ); 69 buf.append( child.toString() ); 70 } 71 return buf.toString(); 72 } 73 74 /** 75 * Return a string containing this object's name value, followed by the names of all child objects (and their 76 * children etc) in pre-order sequence. Each name is separated by a space from the preceding one. 77 */ 78 public String getIds() 79 { 80 StringBuilder buf = new StringBuilder(); 81 buf.append( this.id ); 82 for ( Box child : children ) 83 { 84 buf.append( " " ); 85 buf.append( child.getIds() ); 86 } 87 return buf.toString(); 88 } 89 }