]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/template/OutputableArrayIterable.java
498954074de111f942da3cf97b9b8a7bf5f0d8cd
[gigi.git] / src / org / cacert / gigi / output / template / OutputableArrayIterable.java
1 package org.cacert.gigi.output.template;
2
3 import java.util.Map;
4
5 import org.cacert.gigi.localisation.Language;
6
7 /**
8  * Generic implementation of {@link IterableDataset} that is fed by an array.
9  */
10 public class OutputableArrayIterable implements IterableDataset {
11
12     private Object[] content;
13
14     private String targetName;
15
16     private int index = 0;
17
18     /**
19      * Creates a new {@link OutputableArrayIterable}.
20      * 
21      * @param content
22      *            the objects to be iterated over.
23      * @param targetName
24      *            the variable where the contents of the array to be put in the
25      *            loop.
26      */
27     public OutputableArrayIterable(Object[] content, String targetName) {
28         this.content = content;
29         this.targetName = targetName;
30     }
31
32     @Override
33     public boolean next(Language l, Map<String, Object> vars) {
34         if (index >= content.length) {
35             return false;
36         }
37         vars.put(targetName, content[index]);
38         vars.put("i", index);
39         index++;
40         return true;
41     }
42
43 }