Skip to content

Commit

Permalink
Update DG with the find feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyyyming committed Nov 8, 2023
1 parent 2bbe328 commit 6eac6c5
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
33 changes: 31 additions & 2 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,37 @@ Then, when the user inputs an instrument in the command, the `Instrument::isVali
* Cons: The user can store invalid instruments and genres (due to typos) for a musician. This way, the user will encounter difficulties when finding musicians by instruments or genres.


### Filtering Musicians by Name and Tags Feature
To be Added.
### Find Musician Feature

The find musician feature allows the user to search for musicians by their name, general tags, instruments, and genres. The following activity diagram illustrates the logic flow of the feature.

![FindMusicianActivityDiagram.png](images%2FFindMusicianActivityDiagram.png)

As shown by the diagram, the find feature finds musicians who satisfy the matching criteria (matching at least one keyword) for _all_ specified categories. For example, if the user inputs `find n/John i/piano i/guitar g/jazz`, the find feature will return all musicians whose name contains `John` **and** plays the instrument `guitar` **or** `piano` **and** specialises in the genre `jazz`.

#### Implementation

The following sequence diagram explains in detail how the find feature works with an example scenario.

![FindMusicianSequenceDiagram.png](images%2FFindMusicianSequenceDiagram.png)

<div markdown="block" class="alert alert-info">

:information_source: **Meanings of the abbreviations used in the diagram:**

* `NCKP`: `NameContainsKeywordsPredicate`
* `IMP`: `InstrumentMatchesPredicate`
* `GMP`: `GenreMatchesPredicate`

Abbreviations are used to reduce the clutter in the diagram.

</div>

Step 1. A `FindCommandParser` parses the command and creates a predicate for each category (`NCKP`, `IMP`, `GMP`) based on the keywords specified by the user. Since the user specifies nothing for the `tag` category, the `TagMatchesKeywordPredicate` is not created.

Step 2. Then, the `FindCommndParser` creates a `FindCommand` object with the set of predicates created in the previous step.

Step 3. When the `FindCommand` object is executed, it combines all the predicates into a single `combinedPrediacte`. This predicate is then used to filter the musician list using the `Model::updateFilteredMusicianList(Predicate)` method.

### Add Band Feature
The user can add a new Band entity to the storage through the `addb` Command.
Expand Down
33 changes: 33 additions & 0 deletions docs/diagrams/FindMusicianActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@startuml
skin rose
skinparam ActivityFontSize 15
skinparam ArrowFontSize 12
skinparam defaultTextAlignment center

start
:User executes find command;
:Parse the input keywords;

'Since the beta syntax does not support placing the condition outside the
'diamond we place it as the true branch instead.

if () then ([input is invalid])
:Show corresponding error message;
else ([else])
:Separate the keywords into categories
(name, tag, instrument, and genre);
while () is ([else])
:Go to the next category;
if () then ([the category is empty])
:Skip this category;
else ([else])
:Filter the musicians who
match ANY of the keywords
in this category;
endif
endwhile ([all categories are checked])
:Return the musicians who pass ALL filters;
endif

stop
@enduml
91 changes: 91 additions & 0 deletions docs/diagrams/FindMusicianSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":FindCommandParser" as FindCommandParser LOGIC_COLOR
participant "f:FindCommand" as FindCommand LOGIC_COLOR
participant ":CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
participant ":NCKP" as NameContainsKeywordsPredicate MODEL_COLOR
participant ":IMP" as InstrumentMatchesPredicate MODEL_COLOR
participant ":GMP" as GenreMatchesPredicate MODEL_COLOR
end box

[-> AddressBookParser : parseCommand\n("find n/John i/piano i/guitar g/jazz")
activate AddressBookParser

create FindCommandParser
AddressBookParser -> FindCommandParser
activate FindCommandParser

FindCommandParser --> AddressBookParser
deactivate FindCommandParser

AddressBookParser -> FindCommandParser : parse\n("n/John i/piano i/guitar g/jazz")
activate FindCommandParser

create NameContainsKeywordsPredicate
FindCommandParser -> NameContainsKeywordsPredicate : NameContainsKeywordsPredicate(List.of("John"))
activate NameContainsKeywordsPredicate

NameContainsKeywordsPredicate --> FindCommandParser
deactivate NameContainsKeywordsPredicate

create InstrumentMatchesPredicate
FindCommandParser -> InstrumentMatchesPredicate : InstrumentMatchesPredicate(List.of("piano", "guitar"))
activate InstrumentMatchesPredicate

InstrumentMatchesPredicate --> FindCommandParser
deactivate InstrumentMatchesPredicate

create GenreMatchesPredicate
FindCommandParser -> GenreMatchesPredicate : GenreMatchesPredicate(List.of("jazz"))
activate GenreMatchesPredicate

GenreMatchesPredicate --> FindCommandParser
deactivate GenreMatchesPredicate

create FindCommand
FindCommandParser -> FindCommand : pass the set of predicates
activate FindCommand

FindCommand --> FindCommandParser : f
deactivate FindCommand

FindCommandParser --> AddressBookParser : f
deactivate FindCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
FindCommandParser -[hidden]-> AddressBookParser
destroy FindCommandParser

[<-- AddressBookParser : f
deactivate AddressBookParser

[-> FindCommand : execute()
activate FindCommand

FindCommand -> Model : updateFilteredMusicianList\n(combinedPredicates)
activate Model

'Hidden arrow to increase the length of the activation bar.
Model -[hidden]-> Model

Model --> FindCommand
deactivate Model

create CommandResult
FindCommand -> CommandResult
activate CommandResult

CommandResult --> FindCommand
deactivate CommandResult

[<-- FindCommand : result
deactivate FindCommand

@enduml
Binary file added docs/images/FindMusicianActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/FindMusicianSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6eac6c5

Please sign in to comment.