[underscoregt] iP - #482
Open
underscoregt wants to merge 76 commits into
Open
Conversation
In build.gradle, the dependencies on distZip and/or distTar causes
the shadowJar task to generate a second JAR file for which the
mainClass.set("seedu.duke.Duke") does not take effect.
Hence, this additional JAR file cannot be run.
For this product, there is no need to generate a second JAR file
to begin with.
Let's remove this dependency from the build.gradle to prevent the
shadowJar task from generating the extra JAR file.
Add *.class to .gitignore
Create chatbot
Also update tests
Make Task abstract and add an abstract toFileString() method for file serialization. Implement toFileString() in ToDo, Deadline, and Event to produce pipe-separated representations (e.g. `T | 0 | description`, `D | 0 | description | by`, `E | 0 | description | from | to`).
* Introduce Storage.java to load/save tasks to ./data/amia.txt and persist task state. * Update Amia.java to load tasks on start and call Storage.save(...) after add/remove/mark/undone operations with basic AmiaException handling. * Update .gitignore to ignore the data/ directory.
Change Deadline and Event to store date/time as LocalDateTime and validate input.
Introduce a new Ui class to centralize input/output and replace direct Scanner/System.out usage in Amia.
Change Storage from a static utility to an instance-based class with a configurable file path.
Introduce a new Parser class to centralize command parsing logic.
Refactor Amia and TaskList to centralize index validation as validateIndex().
Persist task date/time fields using DateTimeFormatter.ISO_LOCAL_DATE_TIME.
Classes were relocated into amia, amia.exception, amia.parser, amia.storage, amia.task, and amia.ui packages.
Add a Command abstraction and concrete command implementations (Add, Delete, Mark, Unmark, List, Find, Exit, Unknown) to encapsulate command behavior and return response strings. Refactor Amia from a static CLI-style class into an instance-based class that parses input into Command objects (parseCommand), executes them, and exposes getResponse/shouldExit for GUI integration; main now instantiates Amia and runs start/loop/exit. Move task-limit logic into AddCommand, add Task.matches, and adjust Storage/Parser/CommandType with small API/doc updates (parseIndex, parseDeadline, parseEvent). Update tests to use JUnit Assertions and minor imports. Add JavaFX dependencies in build.gradle and change application mainClass to amia.Launcher to prepare for a GUI launcher.
Introduce a JavaFX-based UI for Amia: adds Main application and Launcher (classpath workaround), MainWindow controller, and DialogBox custom control. Includes FXML layouts (MainWindow.fxml, DialogBox.fxml) and avatar images (Amia.jpg, User.png). MainWindow wires Amia into the UI, binds scrolling, handles user input to display paired dialog boxes, and schedules app exit on Amia's exit command.
Remove hardcoded FILE_PATH from Amia and let Storage compute its default path when given null/empty. Amia now constructs Storage(null). Storage was updated to use getDefaultFilePath(), which determines a data/amia.txt path relative to the running JAR directory via the class ProtectionDomain (with a URISyntaxException fallback to ./data/amia.txt). Updated constructor docs and added necessary import.
Remove the private parseCommand method from Amia and delegate command creation to a new static Parser.parse(input) method. Amia now calls Parser.parse(...) in getResponse and the main loop and no longer imports individual command classes or CommandType. Parser now contains the switch that maps CommandType to concrete Command instances and imports the command classes. This centralizes parsing logic in Parser and keeps Amia focused on orchestration; no behavioral changes intended.
Consolidate constructor logic by making Amia() delegate to Amia(String). Extract task-loading logic into a new private loadTasks() method that returns a loaded TaskList or an empty one on failure, and add JavaDoc. Add assertions to verify storage, ui, and tasks are initialized. No change in behavior, just cleanup and clearer initialization flow.
Rename several variables and a parser method for clearer, consistent naming. Changes include: extractIndexArg -> extractIndexArgument and related call site updates in Delete/Mark/Unmark commands; various local variables in Parser (cmdType -> commandType, desc -> description, args -> arguments, byIdx/fromIdx/toIdx -> deadlineIndex/fromIndex/toIndex) and adjusted Deadline/Event parsing returns; AddCommand uses descriptive variable name for TODO description; TaskList method parameter names changed from idx to index and internal calls updated. No logic changes, only naming refactors to improve readability and maintainability.
Extract the first token of the input, normalize to lowercase, and compare with command values using equals instead of startsWith. This prevents false positives from prefix matches (e.g. "listall" matching "list") and ignores trailing arguments when resolving the CommandType.
Refactor add task handling by splitting the monolithic AddCommand into three focused commands: AddDeadlineCommand (renamed from AddCommand), AddEventCommand, and AddTodoCommand. Each new command encapsulates parsing and creation for its task type and preserves existing behavior (MAX_TASKS check, tasks.add, storage.save, and user message). Update Parser imports and switch to return the appropriate command class for TODO, DEADLINE, and EVENT inputs.
Wrap the BufferedWriter construction in a try-with-resources block so the writer is automatically closed (removed the explicit bw.close()). This prevents resource leaks when saving tasks and preserves the existing exception handling and behavior.
Add defensive checks when reading stored tasks to avoid ArrayIndex/parse errors on corrupted or truncated lines.
Introduce a new ErrorMessages class that centralizes user-facing error strings and a helper for index-format messages. Replace scattered hard-coded AmiaException messages with ErrorMessages constants across Parser, Storage, Task (Deadline/Event/TaskList) and Add* command classes, and add necessary imports. Purely a refactor to standardize and reuse error text; no behavior changes.
Reformat the INVALID_DEADLINE_FORMAT constant in src/main/java/amia/exception/ErrorMessages.java by breaking the assignment across two lines to improve code readability. No functional changes.
Avoid exposing internal mutable state by returning a new ArrayList containing the tasks instead of the backing list. The method implementation and Javadoc were updated so callers receive a defensive copy and cannot modify the TaskList's internal collection directly.
Extract command parsing/execution and CLI behavior into smaller methods to reduce duplication and improve readability. getResponse now delegates to executeCommand, and the main loop uses processOneCommand with unified displayResponse/displayError helpers. ui.close is moved to after the loop and command exit state is handled by isExit. Added Javadoc-style comments for the new helper methods.
Replace explicit welcome lines in Amia.start() with a single ui.showWelcome() call and add MainWindow.showWelcomeMessage() to display the same welcome dialog in the GUI. The MainWindow now triggers the welcome message from setAmia(), adding a single Amia dialog to the dialogContainer to keep CLI and GUI welcome behavior consistent.
Extracts the in-loop task parsing logic into a new private method parseTaskFromLine(String) and updates the file reading loop to use it. The helper returns null for malformed or unrecognized lines and throws AmiaException for invalid date/time parsing; tasks are only added when a non-null Task is returned. This reduces duplication, clarifies control flow, and centralizes parsing/error handling for storage file lines.
Centralize the message shown after adding a task by moving the formatted string into Ui.formatAddTaskMessage(Task, int). Updated AddTodoCommand, AddDeadlineCommand, and AddEventCommand to call ui.formatAddTaskMessage(task, tasks.size()) instead of duplicating the message. Added Task import to Ui to support the new method. This reduces duplication and keeps UI formatting in one place.
Remove duplicated MAX_TASKS fields from AddTodoCommand, AddEventCommand, and AddDeadlineCommand and reference a single public constant TaskList.MAX_TASKS. Add public static final int MAX_TASKS = 100 to TaskList to provide a single source of truth for the maximum task limit and avoid inconsistent magic numbers across command classes.
Introduce an abstract AddCommand that centralizes the common logic for adding tasks (task list full check, adding task, saving storage, and formatting UI message) via a template method createTask(). Refactor AddDeadlineCommand, AddEventCommand, and AddTodoCommand to extend AddCommand and implement createTask() to perform parsing and task construction, removing duplicated execute implementations and cleaning up imports.
Extract repeated "You have X task(s)." formatting into a new Ui.formatTaskCountMessage(int) helper. Update DeleteCommand and Ui.formatAddTaskMessage to use the new method and add JavaDoc for it. This removes duplication and improves readability/maintainability.
Code Quality Improvements
Introduce an assertion in AddCommand to ensure createTask() does not return null before adding the task to the list. This helps catch programming errors early by failing fast during development (when JVM assertions are enabled). (This is for practicing merging PRs.)
Enable Java assertions in the Gradle run configuration and add defensive assert checks throughout the codebase. Assertions were added to Amia (storage/tasks/ui initialization and command handling), Parser (command type resolution and non-null inputs for parsing utilities), Storage (non-null lines and task lists), TaskList (non-null constructor argument), and Ui (non-null messages and added task). These changes document invariants and will surface programming errors early by throwing AssertionError if assumptions are violated.
Add null-check assertions across codebase
Add multi-index support for task operations. Introduce Parser.parseIndices to parse space-separated indices into zero-based ints (sorted in descending order for safe deletions) and throw AmiaException on invalid input. Update DeleteCommand, MarkCommand, and UnmarkCommand to handle single or multiple indices. Also update ErrorMessages.invalidIndexFormat to document the new multi-number usage.
This reverts commit 8c512f4.
Add a new AI.md that documents how GitHub Copilot was used in the project (JavaDoc, commit message generation, assertions, code merging and quality checks). Includes observations about strengths and limitations of Copilot and guidance on providing examples and scope when using the tool. This file tracks AI-assisted work and rationale for edits.
Gives the main stage a proper title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Amia
Amia frees your mind of having to remember things you need to do. It's,
kinda slowreally fast!!All you can do is
And it is FREE! 👍
Features:
[x] Managing tasks
[] Managing deadlines (coming soon)
[] Reminders (coming soon)
Sample: