Command Pattern Exercise: Using addFirst() method fixes wrong undo order


In the Command Pattern, Mosh uses a Deque instead of a List. For adding new objects he uses the add() method, which is available for both the Deque and the List.

I did it the same way in the Command Pattern exercise. As I added several Command objects to my History object one after the other and then tried to undo them in the correct order with an UndoCommand object, I noticed that the order was not correct.

Finally, when I used the addFirst() method to add objects to my History, everything worked as expected.

Code: See gist.

Question: Has anyone else noticed this and/or have I done something wrong?