Project: In-Credit-Ble


Overview

This portfolio describes my contributions to a software engineering project called In-Credit-Ble.

In-Credit-Ble is a finance tracker application, morphed from an address book application, and created by 4 other friends and me. With In-Credit-Ble, you can set budgets, allocate budgets to categories, record your expenses etc.

Abiding by the project constraints, In-Credit-Ble is designed for users who prefer typing over mouse/voice commands. All of In-Credit-Ble’s functions can be accomplished using the keyboard.

In this project, I mainly worked on implementing In-Credit-Ble’s sort and reverse features. The following sections explain these enhancements in more detail, and also show the relevant sections I have added to In-Credit-Ble’s user and developer guide on these features.

The figure below explains the symbols and formatting used in this document

-NAME

Words in UPPER_CASE are parameters to be supplied by the user (e.g. sort -NAME)

[ORDER]

Words in square brackets are optional

SortCommandParser#parse()

parse() method in SortCommandParser

Summary of contributions

This section contains a description of some enhancements I made, and a summary of my contributions.

Enhancement added

I added a sort command and a reverse command in In-Credit-Ble.

  • What they do:
    The reverse command allows users to reverse the list of entries displayed on the graphic user interface. The sort command allows users to sort the entries by name, amount, date and category, in both ascending order and descending order.

  • Justification:
    Without the sort command, entries will be displayed in an order where the most recently entered entry is at the bottom of the list. However, this may not be very helpful and user-friendly to the user. A user may want to sort the entries by amount, so that he/she can find out what he/she has been spending the most on. A user may also want to sort entries by name, date and category to make the list more organised.
    The reverse command will allow the user to reverse the list as a user may want to view the entries in the opposite order. For example, after sorting the entries by amount in descending order, a user may want the entries to be sorted by amount in ascending order next, and this can be achieved conveniently using the reverse command.

  • Highlights:
    These enhancements work with existing commands such as edit and delete. When a list is sorted, it may be easier to find an entry (In-Credit-Ble has a search function too!). These enhancements are also compatible with In-Credit-Ble’s undo and redo functions.

Code contributed

Click here to see the code I contributed to the In-Credit-Ble project!

Other contributions

  • Enhancements:

    • Added aliases for the earlier commands and allowed commands entered to be case-insensitive so that the software becomes more user-friendly and convenient to use.
      (Pull Requests: #15, #22, #71)

    • Imported DateTimeFormatter and LocalDate into the project to make management of dates easier.
      (Pull Requests: #90)

    • Worked on debugging the system tests and increased code coverage.
      (Pull Requests: #177)

  • Documentation:

    • Updated and formatted parts of User Guide and Developer Guide.
      (Pull Requests: #88, #106, #110, #229)



Contributions to the User Guide

These are additions I made to In-Credit-Ble's User Guide for the reverse and sort features.

Sorting the entries according to name/amount/date/category: sort

You can choose to sort the list of entries by name, amount, date or category.
Sort has effect on the entire list of entries (instead of a filtered list).

Format: sort FLAG [ORDER]

  • FLAG here refers to either -name, -amount, -date or -cat.

  • Only one flag should be provided.

  • [ORDER] refers to either -asc or -desc.

    • -asc for ascending order.

    • -desc for descending order.

  • [ORDER] is optional. If not supplied, default ordering is implied.

  • Order of parameters supplied matters. (FLAG must be before ORDER)

Examples (default ordering) (See Figure 17 below):

  • sort -name:
    Sorts the list of records by name in lexicographical order. (ascending order)

  • sort -amount:
    Sorts the list of records by amount from largest to smallest.(descending order)

  • sort -date:
    Sorts the list of records by date with the latest at the top. (descending order)

  • sort -cat:
    Sorts the list of records by category in lexicographical order. (ascending order)

sortExamples
Figure 1. Examples of sort command (sorted by name, amount, date and category respectively, default ordering)


More examples:

  • sort -name -desc:
    Sorts list of records by name in reverse lexicographical order.

sortNameDescExample
Figure 2. Name sorted in descending order


To sort any list conveniently in the reverse order, use the reverse command!
(eg. sort -name,
reverse,
List will be sorted by name in reverse lexicographical order.)

Reversing the entries: reverse

You can also reverse the order of the list of entries in the records.
See Figure 19 below for an example.
Reverse has effect on the entire list of entries (instead of a filtered list).

Alias: rev

Format: reverse

reverseExample
Figure 3. Name sorted in descending order


Contributions to the Developer Guide

These are additions I made to In-Credit-Ble's Developer Guide for the reverse and sort features.

Sort feature

By default, the list of entries is ordered according to the time the entry is entered into the application, where the entry entered first will be at the top of the list, and the entry entered last is at the bottom of the list. The sort mechanism allows users to view their expense records in a different way.


Current Implementation

The sort command uses comparators that implement java.util.Comparator interface to provide the comparison functions.

Table 1. Sort commands (default ordering)
Command Comparator used Effect

sort -name, sort -name -asc

RecordNameComparator

Lexicographical order

sort -amount, sort -amount -desc

RecordAmountComparator

Descending order

sort -date, sort -date -desc

RecordDateComparator

Reverse chronological order

sort -cat, sort -cat -asc

RecordCategoryComparator

Lexicographical order


Table 2. Sort commands (Specified order opposite to that of default)
Command Comparator used Effect

sort -name -desc

RecordNameComparator#reversed()

Reverse lexicographical order

sort -amount - asc

RecordAmountComparator#reversed()

Ascending order

sort -date - asc

RecordDateComparator#reversed()

Chronological order

sort -cat -desc

RecordCategoryComparator#reversed()

Reverse lexicographical order

Here is the list of operations involved in the execution of command, sort -name.
See Figure 10 for steps 1 to 4, and Figure 11 for steps 5 to 10.

SortSequenceDiagram1
Figure 4. Sequence Diagram of Sort Command I
  1. LogicManager#execute("sort -name") calls FinanceTrackerParser#parseCommand("sort -name").

  2. FinanceTracker#parseCommand("sort -name") creates a new SortCommandParser object and calls SortCommandParser#parse(" -name").

  3. SortCommandParser#parse() creates a new RecordNameComparator() object, comparator and passes it as a parameter into the SortCommand constructor.

  4. The SortCommand object, s, is then passed back to the SortCommandParser, FinanceTrackerParser, and finally back to the LogicManager.

    SortSequenceDiagram2
    Figure 5. Sequence Diagram of Sort Command II
  5. LogicManager#execute("sort -name") then continues to call SortCommand#execute().

  6. SortCommand#execute() calls Model#SortFilteredRecordList(comparator).

  7. Model#SortFilteredRecordList(comparator) calls FinanceTracker#sortRecordList(comparator).

  8. FinanceTracker#sortRecordList(comparator) calls UniqueRecordList#sortList(comparator).

  9. UniqueRecordList#sortList(comparator) then uses FXCollection’s static method sort() to sort the records.

  10. SortCommand#execute() then creates a CommandResult object and returns it back to the LogicManager.


Design Considerations

Aspect: How sort is executed
  • Alternative 1 (current choice): Use the Comparator interface.

    • Pros 1: Sorting can be done based on different attributes of the records (name, amount, date, category).

    • Pros 2: Allows an alternative ordering to be applied, does not have to be the natural ordering. Therefore, dates can be sorted in reverse chronological order, and amount in descending order.

    • Cons: A new class that implements the interface Comparator needs to be created.

  • Alternative 2: Use the Comparable interface.

    • Pros: Type-safe with compiler as Comparable#compareTo() only accepts object of type T, instead of java.lang.Object.

    • Cons 1: There can only be one form or way of sorting the records.

    • Cons 2: Uses the natural order for sorting. Therefore, dates will be sorted in chronological order, amount in ascending order, and names and categories in lexicographical order.

Aspect: How sort is executed when [ORDER] argument is supplied and specified order is opposite to that of default. (E.g. sort -name -desc)
  • Alternative 1 (current choice): A new comparator that imposes the reverse ordering of one of the four defined comparator classes is created.
    (E.g. To sort the list by name in reverse lexicographical order, a new comparator, RecordNameComparator#reversed() is created.)

    • Pros: Easy to implement.

    • Cons: List needs to be sorted again using the new comparator. Time will be needed to compare the records in the list.

  • Alternative 2: Reverse the list after sorting it using one of the four defined comparator classes.
    (E.g. Sort list using RecordNameComparator. Then use the reverse command to reverse the list.)

    • Pros: We can reuse what is already in the codebase (reverse command).

    • Cons: Harder to implement, need to execute two commands internally when one command is entered in the CommandBox.

Reverse feature

The reverse feature allows users to reverse the list of entries displayed on the graphic user interface. The sort features are implemented with a default ordering. The reverse command provides a convenient way for users to sort their entries in reverse order.

Current Implementation

This is how the reverse command is implemented:

ReverseSequenceDiagram
Figure 6. Sequence Diagram of Reverse Command
  1. LogicManager#execute("reverse") calls FinanceTrackerParser#parseCommand("reverse").

  2. FinanceTrackerParser#parseCommand("reverse") creates a ReverseCommand object, r.

  3. r is passed back to the FinanceTrackerParser, and then back to the LogicManager.

  4. LogicManager#execute("reverse") then moves on to call ReverseCommand#execute().

  5. ReverseCommand#execute() calls Model#reverseFilteredRecordList().

  6. Model#reverseFilteredRecordList() calls FinanceTracker#reverseRecordList().

  7. FinanceTracker#reverseRecordList() calls UniqueRecordList#reverseList().

  8. UniqueRecordList#reverseList() uses FXCollection’s static method reverse() to reverse the list of records.

  9. ReverseCommand#execute() then creates a CommandResult object and returns it back to the LogicManager.