X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2Foutput%2Ftemplate%2FOutputableArrayIterable.java;fp=src%2Fclub%2Fwpia%2Fgigi%2Foutput%2Ftemplate%2FOutputableArrayIterable.java;h=ff7886d4d12949f1edef58eb88066e9fa691a225;hb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e;hp=0000000000000000000000000000000000000000;hpb=c9ed09f0007fc2c813815be927a5a24b23dab83c;p=gigi.git diff --git a/src/club/wpia/gigi/output/template/OutputableArrayIterable.java b/src/club/wpia/gigi/output/template/OutputableArrayIterable.java new file mode 100644 index 00000000..ff7886d4 --- /dev/null +++ b/src/club/wpia/gigi/output/template/OutputableArrayIterable.java @@ -0,0 +1,43 @@ +package club.wpia.gigi.output.template; + +import java.util.Map; + +import club.wpia.gigi.localisation.Language; + +/** + * Generic implementation of {@link IterableDataset} that is fed by an array. + */ +public class OutputableArrayIterable implements IterableDataset { + + private Object[] content; + + private String targetName; + + private int index = 0; + + /** + * Creates a new {@link OutputableArrayIterable}. + * + * @param content + * the objects to be iterated over. + * @param targetName + * the variable where the contents of the array to be put in the + * loop. + */ + public OutputableArrayIterable(Object[] content, String targetName) { + this.content = content; + this.targetName = targetName; + } + + @Override + public boolean next(Language l, Map vars) { + if (index >= content.length) { + return false; + } + vars.put(targetName, content[index]); + vars.put("i", index); + index++; + return true; + } + +}