docs/DesignPatterns
annotate code/composite-composite.java @ 29:f3b4061ec3b4
added new content
author | meillo@marmaro.de |
---|---|
date | Sun, 08 Jul 2007 20:49:06 +0200 |
parents | 20c0116dcb97 |
children |
rev | line source |
---|---|
meillo@7 | 1 class Composite implements IComponent { |
meillo@7 | 2 private String id; |
meillo@7 | 3 private List<IComponent> list = new ArrayList<IComponent> (); |
meillo@7 | 4 |
meillo@7 | 5 public Composite(String id) { |
meillo@7 | 6 this.id = id; |
meillo@7 | 7 } |
meillo@7 | 8 |
meillo@7 | 9 public String toString() { |
meillo@7 | 10 StringBuilder buf = new StringBuilder(); |
meillo@7 | 11 buf.append(String.format("(%s:", id)); |
meillo@7 | 12 |
meillo@7 | 13 for (IComponent child : list) { |
meillo@7 | 14 buf.append(" " + child.toString()); |
meillo@7 | 15 } |
meillo@7 | 16 buf.append(")"); |
meillo@7 | 17 |
meillo@7 | 18 return buf.toString(); |
meillo@7 | 19 } |
meillo@7 | 20 |
meillo@7 | 21 //public List<IComponent> getChildren() |
meillo@7 | 22 |
meillo@7 | 23 public Collection getChildren(){ |
meillo@7 | 24 return list; |
meillo@7 | 25 } |
meillo@7 | 26 |
meillo@7 | 27 public boolean addComponent(IComponent c){ |
meillo@7 | 28 return list.add(c); |
meillo@7 | 29 } |
meillo@7 | 30 |
meillo@7 | 31 public boolean removeComponent(IComponent c){ |
meillo@7 | 32 return list.remove(c); |
meillo@7 | 33 } |
meillo@7 | 34 } |