Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f306814
level0:
Jan 24, 2025
cf970a8
Rename, add greet, exit
zavsky Jan 24, 2025
2bbab8c
Add greeting, exit
zavsky Feb 7, 2025
6c70db6
Add echo user input
zavsky Feb 7, 2025
c4c4faf
Add tasks, list tasks
zavsky Feb 7, 2025
77839ab
mark and unmark tasks
zavsky Feb 9, 2025
6c39cff
Add todo, events, deadlines
zavsky Feb 9, 2025
eda5180
code standards compliance
zavsky Feb 9, 2025
b7a4a53
refactor and error handling
zavsky Feb 12, 2025
5ad547a
Merge branch 'branch-Level-5' into HEAD
zavsky Feb 12, 2025
e35e895
add basic undo last functionality
zavsky Feb 19, 2025
cc18725
add save and load functionality
zavsky Feb 20, 2025
4eef65c
Merge branch 'branch-Level-6'
zavsky Feb 20, 2025
351be6f
merge branch-Level-7 to branch-Level-6
zavsky Feb 20, 2025
9d41e65
refactor and better undo implementation
zavsky Feb 21, 2025
0f90bf2
improved delete logic
zavsky Feb 21, 2025
409731a
reduced magic strings
zavsky Feb 22, 2025
6402578
add ability to batch (un)mark/delete, transitive to undo
zavsky Feb 22, 2025
4442464
fixed variable spaces bug
zavsky Feb 22, 2025
9913a79
avoid duplicate indices, rewrite in lambda exp, prepare lvl8
zavsky Feb 24, 2025
27dc91e
update TaskManager to lambda expressions for scalability
zavsky Feb 26, 2025
5be9c7e
update MessageType to use lambda expressions
zavsky Feb 26, 2025
e16fc55
Removed duplicates, cleaned UI presentation
zavsky Feb 27, 2025
5fbe970
Add basic search-by-keyword functionality
zavsky Feb 27, 2025
7a3dbfa
Add JavaDoc
zavsky Feb 28, 2025
61a0382
Merge branch 'branch-A-JavaDoc'
zavsky Feb 28, 2025
dc65ce7
Merge branch-Level-9 with Master
zavsky Feb 28, 2025
1a92be7
Changed length of line separator
zavsky Feb 28, 2025
22f2a2f
Merge pull request #1 from zavsky/testing
zavsky Feb 28, 2025
ad398f7
Add product logo
zavsky Mar 14, 2025
9f85920
Update README.md
zavsky Mar 18, 2025
99947ed
Update README.md
zavsky Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT

*.class
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/java/bluebird/Bluebird.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bluebird;
public class Bluebird {

public Bluebird() {

}

public void greetHello() {
clearScreen();
System.out.println("Hello, I am Bluebird");
System.out.println("What can I do for you?");
System.out.println("");
}

public void greetGoodbye() {
clearScreen();
System.out.println("CAWWW");
System.out.println("");
}

public static void clearScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
}
}
144 changes: 144 additions & 0 deletions src/main/java/bluebird/CommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package bluebird;

import java.security.SecureRandom;

import bluebird.commands.*;
import bluebird.exceptions.IndexOutOfBoundsException;

public class CommandParser {
private final TaskManager taskManager;
private final UIHandler ui;

private static final SecureRandom random = new SecureRandom();

public CommandParser(TaskManager taskManager, UIHandler ui) {
this.taskManager = taskManager;
this.ui = ui;
}

public Command parseInput(String input) {
String[] parts = input.split(" ", 2);
String command = parts[0].toLowerCase();
String arguments = parts.length > 1 ? parts[1] : "";

switch (command) {
case "list":
case "l":
return new ListCommand(taskManager, ui);
case "add":
case "a":
return parseAddCommand(arguments);
case "mark":
case "m":
return parseMarkCommand(arguments, true);
case "unmark":
case "u":
return parseMarkCommand(arguments, false);
case "delete":
case "d":
return parseDeleteCommand(arguments);
//case "undo":
//case "x":
// implement undo last functionality
case "help":
case "h":
return new HelpCommand(ui);
case "exit":
case "e":
//bb.greetGoodbye();
return new ExitCommand();
default:
System.out.println("Unknown command.");
return new HelpCommand(ui);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the initiative to do short form commands for each command. However, these are considered magic strings. Perhaps you could put them in a constant EXIT_COMMAND/EXIT_COMMAND_SHORT or use a enum to represent the commands.


private Command parseAddCommand(String arguments) {
String trimmedArgs = arguments.trim();
String[] parts = trimmedArgs.split(" ", 2);
String taskType = parts[0].toLowerCase();

if (!isValidTaskType(taskType)) {
String input = ui.getUserInput("Add event, deadline or todo? ").trim();
parts = input.split(" ", 2);
taskType = parts[0].toLowerCase();

if (!isValidTaskType(taskType)) {
return new Command();
}
}

String details = (parts.length > 1) ? parts[1] : ui.getUserInput("Enter details: ");

if (details.trim().isEmpty()) {
return new Command();
}

return new AddCommand(taskManager, ui, taskType, details);

// System.out.println(randomEnum(TaskType.class).name());
// return new Command();
}

/**
* Taken from stackoverflow.com/questions/1972392/pick-a-random-value-from-an-enum
* from users Eldelshell and zuddduz.
* @return
*/
public static <T extends Enum<?>> T randomEnum(Class<T> clazz) {
int x = random.nextInt(clazz.getEnumConstants().length);
return clazz.getEnumConstants()[x];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, this function does not seem to serve any functionality. Consider removing it in your final version of IP.


enum TaskType {
DEADLINE, D,
EVENT, E,
TODO, T
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this in its own file. Enums, like classes, should have a dedicated file. You could then even share it across multiple classes for consistency.


private boolean isValidTaskType(String args) {
try {
TaskType.valueOf(args.toUpperCase());
return true;
} catch (IllegalArgumentException e) {
return false;
}
}

private Command parseMarkCommand(String arguments, boolean markAsDone) {
try {
String trimmedArgs = arguments.trim();
if (trimmedArgs.isEmpty()) {
ui.displayTasks(taskManager.getTasks());
trimmedArgs = ui.getUserInput("Enter task number: ");
}
return new MarkCommand(taskManager, ui, parseTaskIndex(trimmedArgs), markAsDone);
} catch (IndexOutOfBoundsException e) {
ui.showError("Index provided is out of bounds");
return new Command();
}
}

private Command parseDeleteCommand(String arguments) {
try {
String trimmedArgs = arguments.trim();
if (trimmedArgs.isEmpty()) {
ui.displayTasks(taskManager.getTasks());
trimmedArgs = ui.getUserInput("Enter task number to delete: ");
}
return new DeleteCommand(taskManager, ui, parseTaskIndex(trimmedArgs));
} catch (IndexOutOfBoundsException e) {
ui.showError("Index provided is out of bounds");
return new Command();
}
}

private int parseTaskIndex(String input) throws IndexOutOfBoundsException {
int index = Integer.parseInt(input.trim()) - 1;
// check index out-of-bounds
if (index < 0 || index >= taskManager.getTasks().size()) {
throw new IndexOutOfBoundsException();
}
return index;
}
}
Loading