Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Hailinx authored Oct 19, 2017
2 parents e7813d0 + b979f92 commit 703228b
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 39 deletions.
74 changes: 64 additions & 10 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ public class FindOptionByName extends CommandOption<FindCommand> {
}
----

==== Design Consideration

**Aspect:** Implementation of Command Options +
**Alternative 1 (current choice):** Extend abstract class `CommandOption`. +
**Pros:** It is easier to understand the architecture of parsing chain. +
**Cons:** Using inheritance makes it more troublesome than implementing directly. +
**Alternative 2:** Just override `execute()` +
**Pros:** Does not involve inheritance. Only needs to change one file.
**Cons:** This structure is not clear.

---

// tag::undoredo[]
=== Undo/Redo mechanism

Expand Down Expand Up @@ -334,16 +346,6 @@ image::UndoRedoActivityDiagram.png[width="200"]

==== Design Considerations

**Aspect:** Implementation of Command Options +
**Alternative 1 (current choice):** Extend abstract class `CommandOption`. +
**Pros:** It is easier to understand the architecture of parsing chain. +
**Cons:** Using inheritance makes it more troublesome than implementing directly. +
**Alternative 2:** Just override `execute()` +
**Pros:** Does not involve inheritance. Only needs to change one file.
**Cons:** This structure is not clear.

---

**Aspect:** Implementation of `UndoableCommand` +
**Alternative 1 (current choice):** Add a new abstract method `executeUndoableCommand()` +
**Pros:** We will not lose any undone/redone functionality as it is now part of the default behaviour. Classes that deal with `Command` do not have to know that `executeUndoableCommand()` exist. +
Expand Down Expand Up @@ -384,6 +386,58 @@ image::UndoRedoActivityDiagram.png[width="200"]
**Cons:** Requires dealing with commands that have already been undone: We must remember to skip these commands. Violates Single Responsibility Principle and Separation of Concerns as `HistoryManager` now needs to do two different things. +
// end::undoredo[]

// tag::sort[]
=== Sort mechanism

The sort mechanism makes use of sort() method in Java 8, which takes in Comparator as parameter. It is written in Lambda expression which makes the code more concise.

The advantage of Lambda expression can be illustrated by the following two code examples.

Example of codes written in pre Java 8 fashion:
[source,java]
----
Collection.sort(fruitList, new Comparator<Fruit>() {
@Override
public int compare(Fruit a, Fruit b) {
return a.getSize().compareTo(b.getSize());
}
});
----

With Lambda expression:
[source,java]
----
Collection.sort(fruitList, (Fruit a, Fruit b) -> a.getSize().compareTo(b.getSize()));
----

Both examples sort the fruits in the fruitList according to their size, where smallest on top and largest at the bottom. The amount of verbosity has been reduced by using the Lambda expression. In fact, it can be more concise by removing the variable type from the parameters as the type information is inferred from the context in which the Lambda expression is being used (adopted by sort command):
[source,java]
----
Collection.sort(fruitList, (a, b) -> a.getSize().compareTo(b.getSize()));
----

[NOTE]
Lambda expression is equivalent to overriding the 'compare(T o1, T o2)' method in 'Comparator' class.

==== Design Considerations

**Aspect:** Implementation of 'SortCommand' 'OPTION' +
**Alternative 1 (current choice):** Make use of `CommandOptionUtil` +
**Pros:** Standardised usage of command options format which can be implemented into other commands. +
**Cons:** Need to extend abstract class 'CommandOption' if a more complex parsing procedure is involved. e.g. 'find' command. +
**Alternative 2:** Declare new 'OPTION' format +
**Pros:** No inheritance required, minimise error. +
**Cons:** 'SortCommand' class specific, cannot be reused by other commands.

**Aspect:** Implementation of sort +
**Alternative 1 (current choice):** Lambda expression +
**Pros:** Short and concise. +
**Cons:** Increase bug occurrence as variable type can be omitted. +
**Alternative 2:** Pre Java 8 practice +
**Pros:** Widely practised, minimise error. +
**Cons:** Long and unclear, need to manually override 'compare' method.
// end::sort[]

=== Logging

We are using `java.util.logging` package for logging. The `LogsCenter` class is used to manage the logging levels and logging destinations.
Expand Down
68 changes: 39 additions & 29 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -298,29 +298,6 @@ The `redo` command fails as there are no `undo` commands executed previously.
`redo` (reapplies the `clear` command) +
// end::undoredo[]

=== Locking the address book : `lock`

Locks the address book by a password. +
Format: `lock PASSWORD`

****
* Password should be longer than 4 characters.
* After locking, user cannot input any commands except `unlock`.
* Data file will be encrypted after locking.
* Person contact list will be cleared.
****

=== Unlocking the address book: `unlock`

Unlocks the address book after entering correct password. +
Format: `unlock PASSWORD`

****
* Password should be longer than 4 characters.
* Encrypted data file will be decrypted after locking.
* Person contact list will reload.
****

=== Clearing all entries : `clear`

Clears all entries from the address book. +
Expand All @@ -338,6 +315,7 @@ There is no need to save manually.

== Since v1.2

// tag::sort[]
=== Sorting all persons : `sort`

Shows a sorted list of all persons in the address book. +
Expand All @@ -348,17 +326,41 @@ Format: `sort OPTION`
* The OPTION refers to a contact's field, e.g. 'name', 'phone', 'email', ...
* The OPTION *must be a hyphen followed by a single lower case alphabet* -n, -p, -e, ...
* Available options:
'-n': sort by name
'-p': sort by phone number
'-e': sort by email address
'-a': sort by address
'-t': sort by tag
**'-n': sort by name
**'-p': sort by phone number
**'-e': sort by email address
**'-a': sort by address
**'-t': sort by tag
****

Examples:

* `sort -n` +
Sorts the address book alphabetically by name.
// end::sort[]

=== Locking the address book : `lock`

Locks the address book by a password. +
Format: `lock PASSWORD`

****
* Password should be longer than 4 characters.
* After locking, user cannot input any commands except `unlock`.
* Data file will be encrypted after locking.
* Person contact list will be cleared.
****

=== Unlocking the address book: `unlock`

Unlocks the address book after entering correct password. +
Format: `unlock PASSWORD`

****
* Password should be longer than 4 characters.
* Encrypted data file will be decrypted after locking.
* Person contact list will reload.
****

== Coming in v2.0

Expand All @@ -378,6 +380,10 @@ Adds schedule with the 1st person: `dinner at 7`.
* `sch 2 s/` +
Clears all existing schedules with the 2nd person.

=== real time highlight

Real time highlight when input command is not correct.

== FAQ

*Q*: How do I transfer my data to another Computer? +
Expand All @@ -392,7 +398,9 @@ e.g. `add n/James Ho p/22224444 e/[email protected] a/123, Clementi Rd, 123466
e.g. `delete 3`, `del john`
* *Edit* : `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]...` +
e.g. `edit 2 n/James Lee e/[email protected]`
* *Find* : `find KEYWORD [MORE_KEYWORDS]` +
* *Find* : `find KEYWORD [MORE_KEYWORDS]` or +
`find -u KEYWORD` or +
`find -d [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]...` +
e.g. `find James Jake`
* *List* : `list`
* *Help* : `help`
Expand All @@ -403,3 +411,5 @@ e.g. 'sort -n'
* *History* : `history`
* *Undo* : `undo`
* *Redo* : `redo`
* *Lock* : `lock PASSWORD`
* *Unlock* : `unlock PASSWORD`

0 comments on commit 703228b

Please sign in to comment.