Mercurial > docs > DesignPatterns
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:20c0116dcb97 | 8:c9e5dcd79aae |
---|---|
1 class Composite implements IComponent { | |
2 private String id; | |
3 private List<IComponent> list = new ArrayList<IComponent> (); | |
4 | |
5 public Composite(String id) { | |
6 this.id = id; | |
7 } | |
8 | |
9 public String toString() { | |
10 StringBuilder buf = new StringBuilder(); | |
11 buf.append(String.format("(%s:", id)); | |
12 | |
13 for (IComponent child : list) { | |
14 buf.append(" " + child.toString()); | |
15 } | |
16 buf.append(")"); | |
17 | |
18 return buf.toString(); | |
19 } | |
20 | |
21 //public List<IComponent> getChildren() | |
22 | |
23 public Collection getChildren(){ | |
24 return list; | |
25 } | |
26 | |
27 public boolean addComponent(IComponent c){ | |
28 return list.add(c); | |
29 } | |
30 | |
31 public boolean removeComponent(IComponent c){ | |
32 return list.remove(c); | |
33 } | |
34 } |