summaryrefslogtreecommitdiff
path: root/src/main/CommandQueue.java
blob: b3fde3e9cb4d80496b174d5a18e3d47a64426c7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main;

import java.util.LinkedList;
import java.util.Queue;

/**
 * The queue of commands to be executed every step.
 *
 * @author Maurice Laveaux
 */
public class CommandQueue {

    // the list of commands executed in this order.
    private final Queue<ICommand> m_commands;

    public CommandQueue() {
        m_commands = new LinkedList();
    }

    /**
     * Add another command to the last position in the queue.
     *
     * @param command Any command that can be executed.
     */
    public void add(ICommand command) {
        m_commands.offer(command);
    }

    /**
     * Execute every command that is in the queue.
     */
    public void executeAll() {
        while (!m_commands.isEmpty()) {
            ICommand command = m_commands.poll();

            command.execute();
        }
    }
}