01: package org.osbl;
02:
03: import java.util.*;
04:
05: public class ItemRegistry {
06: List<String> cache;
07: List<String> items = new ArrayList<String>();
08: List<ItemCollector> itemCollectors = new ArrayList<ItemCollector>();
09:
10: public void addItems(ItemCollector itemCollector) {
11: int index = itemCollectors.indexOf(itemCollector);
12: if (index == -1)
13: itemCollectors.add(itemCollector);
14: else
15: itemCollectors.set(index, itemCollector);
16: }
17:
18: public void addItem(String item) {
19: items.add(item);
20: }
21:
22: public void refresh() {
23: cache = null;
24: for (ItemCollector itemCollector : itemCollectors) {
25: itemCollector.refresh();
26: }
27: }
28:
29: public List<String> getItems() {
30: if (cache == null) {
31: cache = new ArrayList<String>();
32: cache.addAll(items);
33: for (ItemCollector itemCollector : itemCollectors) {
34: cache.addAll(itemCollector.getItems());
35: }
36: }
37: return cache;
38: }
39: }
|