1 package club.wpia.gigi.output.template;
3 import java.io.PrintWriter;
4 import java.util.Collection;
5 import java.util.HashMap;
8 import club.wpia.gigi.localisation.Language;
11 * Outputs an {@link Outputable} multiple times based on a given
12 * {@link IterableDataset}.
14 public final class ForeachStatement implements Translatable {
16 private final String variable;
18 private final TemplateBlock body;
21 * Creates a new {@link ForeachStatement}.
24 * the variable to take the {@link IterableDataset} from.
26 * the body to output multiple times.
28 public ForeachStatement(String variable, TemplateBlock body) {
29 this.variable = variable;
34 public void output(PrintWriter out, Language l, Map<String, Object> vars) {
35 Object o = vars.get(variable);
36 if (o instanceof IterableDataset) {
37 IterableDataset id = (IterableDataset) o;
38 Map<String, Object> subcontext = new HashMap<String, Object>(vars);
39 while (id.next(l, subcontext)) {
40 body.output(out, l, subcontext);
46 public void addTranslations(Collection<String> s) {
47 body.addTranslations(s);