Skip to content

Commit

Permalink
Merge pull request #157 from JerryWang0000/branch-Find-DG
Browse files Browse the repository at this point in the history
Add implementation details for `Find` feature in DeveloperGuide
  • Loading branch information
Pluiexo authored Mar 29, 2024
2 parents 90da065 + b2148a1 commit f54fb76
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,41 @@ This is to prevent `FilterCommand` from taking on more responsibilities (Separat
`FilterCommand` having `setPersonPredicate()` method:
This is so that `FilterCommand` has the required argument of type `Predicate<Person>` to be used in the `updateFilteredPersonList()` method. Since the `Predicate<Person>` object is created by chaining the multiple predicates, no parsing is involved to create this `Predicate`.

### Find feature

#### How the feature is implemented

The sequence diagram below explains how the find command `find Alex` goes through the `Logic` component.

![Interactions Inside the Logic Component for the `find Alex` Command](images/FindSequenceDiagram.png)

<div markdown="span" class="alert alert-info">:information_source: **Note:** The lifeline for `FindCommandParser` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline continues till the end of diagram.
</div>

1. When user types in `find Alex`, it is passed to `StaffConnectParser`.
2. `StaffconnectParser` then creates a `FindCommandParser` that will parse `Alex` to create a `FindCommand` which utilizes a predicate judge whether `Alex` is contained in the person's name.
3. In `FindCommand`, `Model` executes `updateFilteredPersonList()` method using the predicate mentioned above.
4. The result of the command execution is encapsulated as a `CommandResult` object which is returned back from `Logic`, to show in the `UI` component the number of persons listed with `Alex` in the name.

The below sequence diagram goes into more detail on how the command is parsed in `EditCommandParser`.

![Interactions Inside FindCommandParser for the `parse("f/Computing")` Command](images/FindSequenceDiagram-Parser.png)

1. Within `FindCommandParser`, the command string is first trimmed and checked whether it is empty, then splitted into an string array by space characters.
2. `FindCommandParser` then constructs a predicate to test whether the names of `Person` contain any one of the strings in the array mentioned above. This predicate is passed as an argument for the constructor of `FindCommand`.

The below activity diagram illustrates the process when a user executes a find command.

<img src="images/FindActivityDiagram.png" width="250" />

#### Why find is implemented this way

The main operation for the find feature is the `updateFilteredPersonList(Predicate<Person> predicate)` method in the `Model` component.
Below are some explanations for the special considerations in the implementation.

`FindCommmandParser` parsing the `Predicate` objects:
This is to prevent `FindCommand` from taking on more responsibilities (Separation of Concerns).

### \[Proposed\] Undo/redo feature

#### Proposed Implementation
Expand Down
21 changes: 21 additions & 0 deletions docs/diagrams/FindActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@startuml
skin rose
skinparam ActivityFontSize 15
skinparam ArrowFontSize 12
start
:User executes find command;

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

if () then ([command is non-empty])
if () then ([Person fulfils criteria])
:Show in list;
else ([else])
:Not shown in list;
endif
else ([else])
:Show error message to User;
endif
stop
@enduml
30 changes: 30 additions & 0 deletions docs/diagrams/FindSequenceDiagram-Parser.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain
skinparam ParticipantPadding 0

Participant ":FindCommandParser" as FindCommandParser LOGIC_COLOR
Participant ":FindCommand" as FindCommand LOGIC_COLOR
Participant "p:NameContainsKeywordsPredicate" as p LOGIC_COLOR


[-> FindCommandParser : parse("Alex")
create FindCommandParser
activate FindCommandParser

create p
FindCommandParser -> p: new("Alex")
activate p
p --> FindCommandParser
deactivate p

create FindCommand
FindCommandParser -> FindCommand: new(p)
activate FindCommand

FindCommand --> FindCommandParser
deactivate FindCommand

[<-- FindCommandParser
deactivate FindCommandParser
@enduml
73 changes: 73 additions & 0 deletions docs/diagrams/FindSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":StaffConnectParser" as StaffConnectParser LOGIC_COLOR
participant ":FindCommandParser" as FindCommandParser LOGIC_COLOR
participant "f:FindCommand" as FindCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant "m:Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("find Alex")
activate LogicManager

LogicManager -> StaffConnectParser : parseCommand("find Alex")
activate StaffConnectParser

create FindCommandParser
StaffConnectParser -> FindCommandParser
activate FindCommandParser

FindCommandParser --> StaffConnectParser
deactivate FindCommandParser

StaffConnectParser -> FindCommandParser : parse("Alex")
activate FindCommandParser

create FindCommand
FindCommandParser -> FindCommand: new(NameContainsKeywordsPredicate)
activate FindCommand

FindCommand --> FindCommand
deactivate FindCommand

FindCommand --> FindCommandParser :
deactivate FindCommand

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

StaffConnectParser --> LogicManager : f
deactivate StaffConnectParser

LogicManager -> FindCommand : execute(m)
activate FindCommand

FindCommand -> Model : updateFilteredPersonList(NameContainsKeywordsPredicate)
activate Model

Model --> FindCommand
deactivate Model

create CommandResult
FindCommand -> CommandResult
activate CommandResult

CommandResult --> FindCommand
deactivate CommandResult

FindCommand --> LogicManager : r
deactivate FindCommand

[<-- LogicManager
deactivate LogicManager
@enduml
Binary file added docs/images/FindActivityDiagram.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/FindSequenceDiagram-Parser.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/FindSequenceDiagram.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 f54fb76

Please sign in to comment.