diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index effa535e834..31e9149c8ea 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -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` to be used in the `updateFilteredPersonList()` method. Since the `Predicate` 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) + +
: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. +
+ +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. + + + +#### Why find is implemented this way + +The main operation for the find feature is the `updateFilteredPersonList(Predicate 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 diff --git a/docs/diagrams/FindActivityDiagram.puml b/docs/diagrams/FindActivityDiagram.puml new file mode 100644 index 00000000000..72dca8cd27e --- /dev/null +++ b/docs/diagrams/FindActivityDiagram.puml @@ -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 diff --git a/docs/diagrams/FindSequenceDiagram-Parser.puml b/docs/diagrams/FindSequenceDiagram-Parser.puml new file mode 100644 index 00000000000..ee8f3562104 --- /dev/null +++ b/docs/diagrams/FindSequenceDiagram-Parser.puml @@ -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 diff --git a/docs/diagrams/FindSequenceDiagram.puml b/docs/diagrams/FindSequenceDiagram.puml new file mode 100644 index 00000000000..53b9066518e --- /dev/null +++ b/docs/diagrams/FindSequenceDiagram.puml @@ -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 diff --git a/docs/images/FindActivityDiagram.png b/docs/images/FindActivityDiagram.png new file mode 100644 index 00000000000..a7d628c63dd Binary files /dev/null and b/docs/images/FindActivityDiagram.png differ diff --git a/docs/images/FindSequenceDiagram-Parser.png b/docs/images/FindSequenceDiagram-Parser.png new file mode 100644 index 00000000000..366dcaaf92f Binary files /dev/null and b/docs/images/FindSequenceDiagram-Parser.png differ diff --git a/docs/images/FindSequenceDiagram.png b/docs/images/FindSequenceDiagram.png new file mode 100644 index 00000000000..998c4da5808 Binary files /dev/null and b/docs/images/FindSequenceDiagram.png differ