view code/composite-composite.java @ 37:debbd3bf76ce default tip

Added tag Ausarbeitung final for changeset f03413250b39d73ca44b22ea1e4022fd3c9e825d
author meillo@marmaro.de
date Sat, 11 Aug 2007 22:43:34 +0200
parents c9e5dcd79aae
children
line wrap: on
line source

    class Composite implements IComponent {
            private String id;
            private List<IComponent> list = new ArrayList<IComponent> ();

            public Composite(String id) {
                    this.id = id;
            }

            public String toString() {
                    StringBuilder buf = new StringBuilder();
                    buf.append(String.format("(%s:", id));

                    for (IComponent child : list) {
                          buf.append(" " + child.toString());
                    }
                    buf.append(")");

                    return buf.toString();
            }

            //public List<IComponent> getChildren()

            public Collection getChildren(){
                    return list;
            }

            public boolean addComponent(IComponent c){
                    return list.add(c);
            }

            public boolean removeComponent(IComponent c){
                    return list.remove(c);
            }
    }