Wrote possible fix for issue #50 (Composite command tries to remove non-existent element)

This commit is contained in:
Connor Taylor-Brown
2017-09-12 11:46:57 +12:00
parent d90b161d01
commit b902b05e5e
2 changed files with 9 additions and 4 deletions
@@ -1,7 +1,7 @@
package mock.model.commandFactory;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
/**
* Wraps multiple commands into a composite to execute queued commands during a frame.
@@ -10,15 +10,15 @@ public class CompositeCommand implements Command {
private Queue<Command> commands;
public CompositeCommand() {
this.commands = new ArrayDeque<>();
this.commands = new ConcurrentLinkedDeque<>();
}
public void addCommand(Command command) {
commands.add(command);
commands.offer(command);
}
@Override
public void execute() {
while(!commands.isEmpty()) commands.remove().execute();
while(commands.peek() != null) commands.poll().execute();
}
}