summaryrefslogtreecommitdiff
path: root/src/main/CommandQueue.java
diff options
context:
space:
mode:
authorMaurice Laveaux <m.laveaux@student.tue.nl>2014-04-25 12:46:12 +0200
committerMaurice Laveaux <m.laveaux@student.tue.nl>2014-04-25 12:46:12 +0200
commitcc55914d61978b46ec8e3673c4b37fdc3b392e48 (patch)
treebcee0ff32af56afb4ed19ac2f07f87640fd6ea23 /src/main/CommandQueue.java
parent00c8957e2bbb43b167688a877a0f9a908db03c07 (diff)
downloadTwitterDataAnalytics-cc55914d61978b46ec8e3673c4b37fdc3b392e48.tar.gz
Added the functionality to execute and parse commands.
* CommandParser can parse input strings to RequestCommand. * CommandQueue will execute all ICommands in a queue. * TODO: StreamCommands, database implementation. * RequestCommand writes into database.txt
Diffstat (limited to 'src/main/CommandQueue.java')
-rw-r--r--src/main/CommandQueue.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/CommandQueue.java b/src/main/CommandQueue.java
new file mode 100644
index 0000000..b3fde3e
--- /dev/null
+++ b/src/main/CommandQueue.java
@@ -0,0 +1,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();
+ }
+ }
+}