()
| 11 | private List<Event> eventList = new ArrayList<>(); |
| 12 | public void addEvent(Event c) { eventList.add(c); } |
| 13 | public void run() { |
| 14 | while(eventList.size() > 0) |
| 15 | // Make a copy so you're not modifying the list |
| 16 | // while you're selecting the elements in it: |
| 17 | for(Event e : new ArrayList<>(eventList)) |
| 18 | if(e.ready()) { |
| 19 | System.out.println(e); |
| 20 | e.action(); |
| 21 | eventList.remove(e); |
| 22 | } |
| 23 | } |
| 24 | } |