You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/DeveloperGuide.md
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -599,6 +599,23 @@ The following UML sequence diagram shows how the `delete-note BOOK_TITLE` comman
599
599
600
600
`InputHandler` uses `Formatter` to print a message indicating that the note was successfully deleted
601
601
602
+
### Search Title
603
+
604
+
The `search-title` feature allows the user to search for books in the inventory by providing a keyword. The system returns a list of books whose titles contain the specified keyword.
605
+
606
+
`InputHandler` coordinates with `InputParser`, `BookList`, and `Formatter` classes to implement the feature.
607
+
608
+
1. User issues command:
609
+
The user inputs the command in the CLI with the required keyword, e.g., `search-title Gatsby`.
610
+
2.`InputHandler` first calls `InputParser.extractCommandArgs(...)` to split the user input into command arguments.
611
+
3.`InputHandler` checks if the keyword is valid (non-empty). If invalid, an error message is displayed.
612
+
4. InputHandler calls `BookList.findBooksByKeyword(keyword)` to retrieve a list of books whose titles contain the keyword.
613
+
5.`InputHandler` uses `Formatter` to print the list of matching books.
614
+
615
+
Design Considerations:
616
+
- Case Insensitivity: The search is case-insensitive to improve usability.
617
+
618
+
602
619
### Save Inventory
603
620
604
621
The save inventory feature automatically saves the inventory each time the user makes a change.
@@ -682,6 +699,53 @@ The following UML sequence diagram shows the relevant behaviour:
682
699
- A message is printed indicating the number of books loaded.
683
700
- The populated `bookList` is returned.
684
701
702
+
703
+
### Save Loans
704
+
705
+
The save loans feature ensures that all loans are saved to persistent storage whenever there is a change to the `LoanList`. If no existing persistent storage file is detected, it will be created in the default location `./data/bookKeeper_loanList.txt`. The file path can also be customized using the setLoanFilePath() method.
706
+
707
+
The method `saveLoans(loanList)` is invoked by `InputHandler` after any method call that makes changes to the current loan list.
708
+
709
+
The following UML sequence diagram shows the relevant behavior:
2. Directory Check: A `File` object is created for the directory. If the directory does not exist, it is created using `mkdirs()`.
715
+
3. FileWriter Creation: A new `FileWriter` is created for the file at the path specified by `loanListFilePath`.
716
+
4. Retrieving Loan List: `getLoanList()` is called on the `LoanList` instance passed into `saveLoans(loanList)` to obtain the list of Loan objects.
717
+
5. Writing Each Loan: For each `Loan` in the list, `toFileString()` is called to get a string representation. This string is then written to the file via `FileWriter`.
718
+
6. Closing: After writing all loans, `FileWriter` is closed to complete the writing process.
719
+
720
+
Error Handling: If an `IOException` occurs during any file operations, an error message is displayed via `Formatter.printBorderedMessage()`.
721
+
722
+
### Load Loans
723
+
724
+
The load loans feature loads the loan list from the existing persistent data storage file if it exists. If it does not exist, an empty loan list is used. The file path defaults to `./data/bookKeeper_loanList.txt` but can be customized using the `setLoanFilePath()` method.
725
+
726
+
The method `loadLoans(bookList)` is called once by `InputHandler` at the start of the program.
727
+
728
+
The following UML sequence diagram shows the relevant behavior:
729
+
730
+

731
+
732
+
1. Initialization:
733
+
734
+
`InputHandler` invokes `Storage.loadLoans(bookList)`, which initializes an empty `ArrayList<Loan>`.
735
+
736
+
2. File Existence Check: A `File` object is created for the loan file path.
737
+
- If the file does not exist:
738
+
A message is printed using `Formatter.printBorderedMessage()` indicating no saved loans were found. A new file is created, and an empty `ArrayList<Loan>` is returned.
739
+
740
+
3. File Reading: If the file exists, a `Scanner` reads the file line by line. Each line is passed to `parseLoanFromString(line, bookList)` to convert it into a Loan object.
741
+
742
+
4. Loan Validation: If the `Loan` is null, a message is printed indicating the entry was skipped.
743
+
- If valid, duplicates are checked using `loanList.stream().anyMatch(...)`.
744
+
- If a duplicate is found, a message is printed, and the loan is skipped.
745
+
- Otherwise, the loan is added to the loanList.
746
+
747
+
5. Completion: After processing all lines in the file, the `Scanner` is closed. A message is printed indicating the number of loans loaded. The populated `loanList` is returned.
0 commit comments