Skip to content

Commit

Permalink
[se-edu#534] HistoryCommand: Returns previous commands in reverse chr…
Browse files Browse the repository at this point in the history
…onological order (se-edu#537)

The HistoryCommand returns the previous commands in chronological
order.

This goes against the intuition that history ought to be viewed in
reverse chronological order. We are expecting that the user will want
to see what he has typed most recently, just like how Google Chrome
History works.

Let’s update HistoryCommand to return previous commands in reverse
chronological order.
  • Loading branch information
Zhiyuan-Amos authored and yamgent committed Jul 5, 2017
1 parent 152302e commit a817b56
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Selects the 1st person in the results of the `find` command.

=== Listing entered commands : `history`

Lists all the commands that you have entered in chronological order. +
Lists all the commands that you have entered in reverse chronological order. +
Format: `history`

=== Clearing all entries : `clear`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;

import java.util.Collections;
import java.util.List;

import seedu.address.logic.CommandHistory;
Expand All @@ -13,7 +14,7 @@
public class HistoryCommand extends Command {

public static final String COMMAND_WORD = "history";
public static final String MESSAGE_SUCCESS = "Entered commands (from earliest to most recent):\n%1$s";
public static final String MESSAGE_SUCCESS = "Entered commands (from most recent to earliest):\n%1$s";
public static final String MESSAGE_NO_HISTORY = "You have not yet entered any commands.";

@Override
Expand All @@ -24,6 +25,7 @@ public CommandResult execute() {
return new CommandResult(MESSAGE_NO_HISTORY);
}

Collections.reverse(previousCommands);
return new CommandResult(String.format(MESSAGE_SUCCESS, String.join("\n", previousCommands)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void execute() {
history.add(command3);

String expectedMessage = String.format(HistoryCommand.MESSAGE_SUCCESS,
String.join("\n", command1, command2, command3));
String.join("\n", command3, command2, command1));

assertCommandResult(historyCommand, expectedMessage);
}
Expand Down

0 comments on commit a817b56

Please sign in to comment.