I created a data structure of my own for a game Text Adventure, and in it each Action object has a Consumer. The next step would be to have someone type a word, scroll through the structure, and find an Action containing the String typed in a vector, run that Consumer (default value 1). But I can not create a code of type "Action.function (1)". to get around this, I had to use forEach, like this:
public static void exec(Consumer<Integer> c, int i) {
ArrayList<Integer> is = new ArrayList<>();
is.add(i);
is.forEach(c);
}
What I think is a gambiarra. Does anyone know a better way to use my Consumer within the code, without having to create a new ArrayList (or whatever) just for that? If necessary, here is part of my Action object code: public class Action implements Iterable {
String id;
String[] functionNames;
Consumer<Integer> function;
Action next;
public Action(String id, Consumer<Integer> function, String... names) {
this.id = id;
this.function = function;
this.functionNames = names;
this.next = null;
}
@Override
public Iterator iterator() {
return new ActionIterator(this);
}
Thank you in advance.