Take the Jzombie model for example, if I want to query all humans with energy equal to 5 and put them in a list I would be have the following codes:
List<Human> human_list = ArrayList<Human>();
Query<Object> query = new PropertyEquals<Object>(context, "energy", 5);
for (Object o : query.query()) {
Human h = (Human)o;
human_list.add(h);
}
However, the order of human in human_list is random and different between different simulation runs. This cause a problem of inconsistent result like below:
run-1:
[human_2, human_4, human_3, human_5, human_1]
run-2:
[human_1, human_3, human_4, human_2, human_1]
run-3:
[human_5, human_1, human_3, human_5, human_2]
I actually want to query the human with engergy == 5 and sort them by their id like:
[human_1, human_2, human_3, human_4, human_5]
so that when I perform some further actions and I can always get the consistent result.