docs/DesignPatterns

diff code/composite-composite.java @ 8:c9e5dcd79aae

rename; cleanups
author meillo@marmaro.de
date Mon, 18 Jun 2007 12:38:48 +0200
parents code/composite-component.java@20c0116dcb97
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/code/composite-composite.java	Mon Jun 18 12:38:48 2007 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +    class Composite implements IComponent {
     1.5 +            private String id;
     1.6 +            private List<IComponent> list = new ArrayList<IComponent> ();
     1.7 +
     1.8 +            public Composite(String id) {
     1.9 +                    this.id = id;
    1.10 +            }
    1.11 +
    1.12 +            public String toString() {
    1.13 +                    StringBuilder buf = new StringBuilder();
    1.14 +                    buf.append(String.format("(%s:", id));
    1.15 +
    1.16 +                    for (IComponent child : list) {
    1.17 +                          buf.append(" " + child.toString());
    1.18 +                    }
    1.19 +                    buf.append(")");
    1.20 +
    1.21 +                    return buf.toString();
    1.22 +            }
    1.23 +
    1.24 +            //public List<IComponent> getChildren()
    1.25 +
    1.26 +            public Collection getChildren(){
    1.27 +                    return list;
    1.28 +            }
    1.29 +
    1.30 +            public boolean addComponent(IComponent c){
    1.31 +                    return list.add(c);
    1.32 +            }
    1.33 +
    1.34 +            public boolean removeComponent(IComponent c){
    1.35 +                    return list.remove(c);
    1.36 +            }
    1.37 +    }