forked from nus-cs2103-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from galvinleow/branch-sort-revenue
Sort Revenue Feature
- Loading branch information
Showing
10 changed files
with
149 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/seedu/homerce/logic/commands/revenue/SortRevenueCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package seedu.homerce.logic.commands.revenue; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.homerce.logic.commands.Command; | ||
import seedu.homerce.logic.commands.CommandResult; | ||
import seedu.homerce.model.Model; | ||
import seedu.homerce.model.manager.HistoryManager; | ||
import seedu.homerce.ui.revenuepanel.RevenueListPanel; | ||
|
||
/** | ||
* Sorts all revenues in Homerce to the user. | ||
*/ | ||
public class SortRevenueCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sortrev"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Sorted all revenues"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Sorts the revenue based on value.\n" | ||
+ "Parameters: ORDER\n" | ||
+ "Example: " + COMMAND_WORD + " asc"; | ||
|
||
private final boolean isAscending; | ||
|
||
/** | ||
* Constructs a SortRevenueCommand. | ||
* | ||
* @param isAscending to indicate the order of the sort. | ||
*/ | ||
public SortRevenueCommand(boolean isAscending) { | ||
this.isAscending = isAscending; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, HistoryManager historyManager) { | ||
requireNonNull(model); | ||
model.getRevenueTracker().sortRevenueList(isAscending); | ||
return new CommandResult(MESSAGE_SUCCESS, RevenueListPanel.TAB_NAME); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/seedu/homerce/logic/parser/revenue/SortRevenueCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package seedu.homerce.logic.parser.revenue; | ||
|
||
import static seedu.homerce.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.homerce.logic.commands.revenue.SortRevenueCommand; | ||
import seedu.homerce.logic.parser.ParserUtil; | ||
import seedu.homerce.logic.parser.exceptions.ParseException; | ||
|
||
public class SortRevenueCommandParser { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the SortRevenueCommand | ||
* and returns a SortRevenueCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public SortRevenueCommand parse(String args) throws ParseException { | ||
try { | ||
boolean isAscending = ParserUtil.parseOrder(args); | ||
return new SortRevenueCommand(isAscending); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortRevenueCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/seedu/homerce/model/revenue/RevenueComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package seedu.homerce.model.revenue; | ||
|
||
import java.util.Comparator; | ||
|
||
public class RevenueComparator implements Comparator<Revenue> { | ||
|
||
@Override | ||
public int compare(Revenue revenue1, Revenue revenue2) { | ||
return revenue1.getValue().value.compareTo(revenue2.getValue().value); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/seedu/homerce/model/revenue/RevenueDefaultComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package seedu.homerce.model.revenue; | ||
|
||
import java.util.Comparator; | ||
|
||
public class RevenueDefaultComparator implements Comparator<Revenue> { | ||
|
||
@Override | ||
public int compare(Revenue revenue1, Revenue revenue2) { | ||
if (revenue1.getDate().getLocalDate().isBefore(revenue2.getDate().getLocalDate())) { | ||
return 1; | ||
} else if (revenue1.getDate().getLocalDate().isAfter(revenue2.getDate().getLocalDate())) { | ||
return -1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} |