Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Javadocs and refactor code to improve readability #206

Merged
merged 8 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Example usage:
The project is built upon an ongoing software project for a desktop application (called _AddressBook_) used for managing contact details.
* It is **written in OOP fashion**. It provides a **reasonably well-written** code base **bigger** (around 6 KLoC) than what students usually write in beginner-level SE modules, without being overwhelmingly big.
* It comes with a **reasonable level of user and developer documentation**.
* It is named `AddressBook Level 3` (`AB3` for short) because it was initially created as a part of a series of `AddressBook` projects (`Level 1`, `Level 2`, `Level 3` ...).
* It is named `AddressBook Level 3` (`AB3` for short) because it was initially created as a part of a series of `AddressBook` projects (`Level 1`, `Level 2`, `Level 3` ....)
* For the detailed documentation of this project, see the **[Address Book Product Website](https://se-education.org/addressbook-level3)**.
* This project is a **part of the se-education.org** initiative. If you would like to contribute code to this project, see [se-education.org](https://se-education.org#https://se-education.org/#contributing) for more info.
18 changes: 9 additions & 9 deletions docs/team/atyhamos.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ Given below are my contributions to the project.
* Highlights: This enhancement did not affect existing commands and commands to be added in the future, but did affect code coverage which required the creation of a `TuteeCardTest` class. Most of the changes were applied to .fxml and .css files which were mostly independent from the logic of the application.
* Credits: *-*

* **Code contributed**: [RepoSense link](https://nus-cs2103-ay2122s1.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2021-09-17&tabOpen=true&tabType=authorship&tabAuthor=atyhamos&tabRepo=AY2122S1-CS2103T-F12-3%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false)
* **Code contributed**: [RepoSense link](https://nus-cs2103-ay2122s1.github.io/tp-dashboard/?search=&sort=groupTitle&sortWithin=title&timeframe=commit&mergegroup=&groupSelect=groupByRepos&breakdown=true&checkedFileTypes=docs~functional-code~test-code~other&since=2021-09-17&tabOpen=true&tabType=authorship&tabAuthor=atyhamos&tabRepo=AY2122S1-CS2103T-F12-3%2Ftp%5Bmaster%5D&authorshipIsMergeGroup=false&authorshipFileTypes=docs~functional-code~test-code~other&authorshipIsBinaryFileTypeChecked=false)

* **Project management**:
* Managed releases `v1.3` and `v1.3.1` (2 releases) on GitHub
* **Project management**:
* Managed releases `v1.3` and `v1.3.1` (2 releases) on GitHub

* **Enhancements to existing features**:
* Updated the GUI color scheme (Pull request [\#36](https://github.com/AY2122S1-CS2103T-F12-3/tp/pull/36))
* Added test cases for `TuteeCard` to improve code coverage.
* Created `TuteeCardTest` to improve code coverage and testing for the `TuteeCard` class. Difficulties arose as testing the `TuteeCard` class required JavaFX toolkit to be initialised, but a workaround was used after researching on the Internet.
* Credits: *https://stackoverflow.com/a/53760312*
* **Enhancements to existing features**:
* Updated the GUI color scheme (Pull request [\#36](https://github.com/AY2122S1-CS2103T-F12-3/tp/pull/36))
* Added test cases for `TuteeCard` to improve code coverage.
* Created `TuteeCardTest` to improve code coverage and testing for the `TuteeCard` class. Difficulties arose as testing the `TuteeCard` class required JavaFX toolkit to be initialised, but a workaround was used after researching on the Internet.
* Credits: *https://stackoverflow.com/a/53760312*

* **Documentation**:
* User Guide:
Expand All @@ -63,7 +63,7 @@ Given below are my contributions to the project.
[\#88](https://github.com/AY2122S1-CS2103T-F12-3/tp/pull/88),
[\#90](https://github.com/AY2122S1-CS2103T-F12-3/tp/pull/90),
[\#163](https://github.com/AY2122S1-CS2103T-F12-3/tp/pull/163).

* Designed team's application icon:
* For Application tray and window: <br> <img width="20%" alt="Application tray" src="../../src/main/resources/images/tracko_logo.png"/>
* For User Guide:<br><img width="20%" alt="For website" src="../images/tracko_logo_docs.png"/>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ public static String parsePaymentValue(String paymentValue) throws ParseExceptio
requireNonNull(paymentValue);
String trimmedPayment = paymentValue.trim();
if (!Payment.isNumberWithAnyDecimals(trimmedPayment)) {
throw new ParseException(Payment.MESSAGE_CONSTRAINTS);
throw new ParseException(Payment.FORMAT_CONSTRAINTS_MESSAGE);
} else if (!Payment.isValidPaymentFormat(trimmedPayment)) {
throw new ParseException(Payment.DECIMAL_CONSTRAINTS);
throw new ParseException(Payment.DECIMAL_CONSTRAINTS_MESSAGE);
} else if (!Payment.isValidPaymentAmount(trimmedPayment)) {
// Payment amount is greater than maximum allowed
throw new ParseException(Payment.AMOUNT_CONSTRAINTS);
throw new ParseException(Payment.AMOUNT_CONSTRAINTS_MESSAGE);
} else {
return trimmedPayment;
}
Expand Down Expand Up @@ -365,17 +365,17 @@ public static LocalDate parsePayByDate(String payByDate) throws ParseException {
}

if (!Payment.isValidPayByDate(trimmedPayByDate)) {
throw new ParseException(Payment.DATE_CONSTRAINTS);
throw new ParseException(Payment.DATE_CONSTRAINTS_MESSAGE);
}

try {
formattedPayByDate = LocalDate.parse(trimmedPayByDate, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
} catch (DateTimeParseException e) {
throw new ParseException(Payment.DATE_CONSTRAINTS);
throw new ParseException(Payment.DATE_CONSTRAINTS_MESSAGE);
}

if (!formattedPayByDate.isAfter(dateToday) && !formattedPayByDate.equals(dateToday)) {
throw new ParseException(Payment.DATE_CONSTRAINTS);
throw new ParseException(Payment.DATE_CONSTRAINTS_MESSAGE);
}
return formattedPayByDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public PaymentCommand parse(String args) throws ParseException {
String userInput = argMultimap.getValue(PREFIX_PAYMENT_DATE).get();
LocalDate paymentPayByDateToSet = ParserUtil.parsePayByDate(userInput);
if (paymentPayByDateToSet == null) {
throw new ParseException(Payment.DATE_CONSTRAINTS);
throw new ParseException(Payment.DATE_CONSTRAINTS_MESSAGE);
}
return new PaymentSetDateCommand(index, paymentPayByDateToSet);
}
Expand Down
59 changes: 45 additions & 14 deletions src/main/java/seedu/address/model/tutee/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,54 @@
*/
public class Payment {

public static final String MESSAGE_CONSTRAINTS =
/** Error message displayed when the payment is not a positive number. */
public static final String FORMAT_CONSTRAINTS_MESSAGE =
"Payment values should only contain non-negative numbers with at least 1 digit, allowing 0 or 2 decimals "
+ "i.e 0, 100 or 74.50";
public static final String DECIMAL_CONSTRAINTS =

/** Error message displayed when the payment does not have valid decimal places. */
public static final String DECIMAL_CONSTRAINTS_MESSAGE =
"Payment values must have either 0 or 2 decimal places. If it has 2 decimal places, it must "
+ "end with either a 0 or 5, i.e 40.50 or 40.55.";
public static final String AMOUNT_CONSTRAINTS = "Payment value should not exceed $100,000";
public static final String DATE_CONSTRAINTS =

/** Error message displayed when the payment exceeds the maximum amount. */
public static final String AMOUNT_CONSTRAINTS_MESSAGE = "Payment value should not exceed $100,000";

/** Error message displayed when the payment due date is in the incorrect format. */
public static final String DATE_CONSTRAINTS_MESSAGE =
"Payment due dates should be a valid date in the format of dd-MM-yyyy, i.e 20-10-2021 and"
+ " must equal to or after today's date.";
public static final String PAYMENT_HISTORY_CONSTRAINTS =

/** Error message displayed when the payment history is in the incorrect format. */
public static final String PAYMENT_HISTORY_CONSTRAINTS_MESSAGE =
"Payment history should only contain dates in the format of dd-MM-yyyy, i.e 20-10-2021, and 'Never'.";

/** The formatter used to format dates in the dd-MM-YYY pattern. */
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy");
public static final String TODAY_DATE_AS_STRING = LocalDate.now().format(FORMATTER);

/** The regex used to determine if a string is a valid non-negative number*/
public static final String VALIDATION_REGEX_NUMERICAL_FRONT_ANY_DECIMALS = "^[0-9][\\d]*([.][0-9]+)?$"
.replaceFirst("^0+", "");

/** The regex used to determine if a string is a valid non_negative number with strictly zero or two decimals. */
public static final String VALIDATION_REGEX_PAYMENT_NO_OR_TWO_DECIMAL_PLACES = "^[0-9][\\d]*([.][0-9][0|5])?$"
.replaceFirst("^0+", "");

/** The maximum amount that a tutee can owe. */
public static final Double MAXIMUM_AMOUNT = 100000.00;

/** The payment amount due by the tutee. */
public final String value;

/** The payment due date set for the tutee. */
public final LocalDate payByDate;
public final String payByDateAsString;

/** Whether the current date has exceeded the payment due date. */
public final boolean isOverdue;

/** The previous payment dates of the tutee. */
public final List<String> paymentHistory = new ArrayList<String>();


Expand All @@ -50,7 +75,7 @@ public class Payment {
*/
public Payment(String payment, LocalDate payByDate) {
requireNonNull(payment);
checkArgument(isValidPaymentFormat(payment), MESSAGE_CONSTRAINTS);
checkArgument(isValidPaymentFormat(payment), FORMAT_CONSTRAINTS_MESSAGE);
value = payment;
this.payByDate = payByDate;
this.paymentHistory.add("Never");
Expand All @@ -59,15 +84,15 @@ public Payment(String payment, LocalDate payByDate) {
}

/**
* Initializes a standard payment sum starting from $0
* Initializes a standard payment sum starting from $0.
* @return A payment of 0 without a last payment date.
*/
public static Payment initializePayment() {
return new Payment("0", null);
}

/**
* Returns true if a given string is a valid payment amount.
* Returns true if a given string has a valid payment format of a non-negative number with zero or two decimals.
* @param test The string to test on
* @return Whether the string matches the regex
*/
Expand Down Expand Up @@ -120,12 +145,15 @@ public static boolean isValidPayByDate(String payByDateAsString) {
* @return Whether the given List follows the correct format for payment histories
*/
public static boolean isValidPaymentHistory(List<String> paymentHistory) {
if (!paymentHistory.get(0).equals("Never")) {
String firstPaymentDate = paymentHistory.get(0);
if (!firstPaymentDate.equals("Never")) {
return false;
}
for (int i = 1; i < paymentHistory.size(); i++) {
if (!isValidPayByDate(paymentHistory.get(i))) {
return false;
} else {
// Checks if all the entries are valid payment due dates
for (int i = 1; i < paymentHistory.size(); i++) {
if (!isValidPayByDate(paymentHistory.get(i))) {
return false;
}
}
}
return true;
Expand All @@ -139,6 +167,7 @@ public void copyPaymentHistory(List<String> historyToCopy) {
if (!isValidPaymentHistory(historyToCopy)) {
return;
} else {
// Ensure current payment history is empty before copying over
paymentHistory.clear();
assert paymentHistory.isEmpty() : "paymentHistory should be empty";
for (String payment : historyToCopy) {
Expand All @@ -149,8 +178,9 @@ public void copyPaymentHistory(List<String> historyToCopy) {

@Override
public String toString() {
String lastPaidDate = paymentHistory.get(paymentHistory.size() - 1);
return String.format("$%s (Last paid on: %s)\nOverdue: %s",
value, paymentHistory.get(paymentHistory.size() - 1), getOverdueStatus());
getValue(), lastPaidDate, getOverdueStatus());
}

/**
Expand All @@ -163,6 +193,7 @@ public String getOverdueStatus() {
} else if (payByDateAsString.equals("-")) {
return "No (Pay-by date not set)";
} else {
// Payment is not overdue
return "No (Next payment date by: " + payByDateAsString + ")";
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/storage/JsonAdaptedTutee.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ public Tutee toModelType() throws IllegalValueException, IOException {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Payment.class.getSimpleName()));
}
if (!Payment.isValidPaymentFormat(payment)) {
throw new IllegalValueException(Payment.MESSAGE_CONSTRAINTS);
throw new IllegalValueException(Payment.FORMAT_CONSTRAINTS_MESSAGE);
}

if (payByDateAsString == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "payment pay-by date"));
}
if (!Payment.isValidPayByDate(payByDateAsString)) {
throw new IllegalValueException(Payment.DATE_CONSTRAINTS);
throw new IllegalValueException(Payment.DATE_CONSTRAINTS_MESSAGE);
}

if (paymentHistory == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "payment history"));
}
if (!Payment.isValidPaymentHistory(paymentHistory)) {
throw new IllegalValueException(Payment.PAYMENT_HISTORY_CONSTRAINTS);
throw new IllegalValueException(Payment.PAYMENT_HISTORY_CONSTRAINTS_MESSAGE);
}

final Address modelAddress = new Address(address);
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/seedu/address/ui/TuteeCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ public class TuteeCard extends UiPart<Region> {
@FXML
private FlowPane tags;

// A List of hexadecimal values of colors to choose from (Green, Pink, Orange, Purple, Cyan)
/** A List of five hexadecimal values of colors for subject labels (Green, Pink, Orange, Purple, Cyan). */
private List<String> subjectColors = Arrays.asList("#35893b", "#d2729d", "#ae950c", "#5912b0",
"#48ac9a");
// The index of the color to choose from

/** The index of the color to choose from. */
private int colorIndex = 0;

/**
* Creates a {@code TuteeCode} with the given {@code Tutee} and index to display.
* Creates a {@code TuteeCard} with the given {@code Tutee} and index to display.
* @param tutee The Tutee whose information is to be displayed
* @param displayedIndex The index to be displayed alongside the tutee's information
*/
public TuteeCard(Tutee tutee, int displayedIndex) {
super(FXML);
Expand All @@ -73,7 +76,7 @@ public TuteeCard(Tutee tutee, int displayedIndex) {
school.setText(tutee.getSchool().value);
level.setText(tutee.getLevel().stringRepresentation);

//Adds subject names as tags
// Adds subject names as tags
tutee.getLessons().stream()
.sorted(Comparator.comparing(lesson -> lesson.getSubject().toString()))
.forEach(lesson -> addSubjectToTag(lesson.getSubject()));
Expand All @@ -84,19 +87,24 @@ public TuteeCard(Tutee tutee, int displayedIndex) {
}

/**
* Adds colored subject tags to Tutee Card
* @param subject The Lesson with the subject to be added
* Adds colored subject tags to a TuteeCard.
* @param subject The Subject to be added and displayed
*/
public void addSubjectToTag(Subject subject) {
Label subjectLabel = new Label(subject.toString());

// This sets the subject to be displayed as a tag with white font colour and a coloured background
subjectLabel.setStyle(" -fx-text-fill: white;\n"
+ " -fx-background-color: " + this.subjectColors.get(colorIndex)
+ ";\n"
+ " -fx-padding: 1 3 1 3;\n"
+ " -fx-border-radius: 2;\n"
+ " -fx-background-radius: 2;\n"
+ " -fx-font-size: 11;\n");

// Wrap-around if student has more than 5 subjects
colorIndex = colorIndex == 4 ? 0 : colorIndex + 1;

tags.getChildren().add(subjectLabel);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void showAlertDialogAndWait(Alert.AlertType type, String title, String headerTex
private static void showAlertDialogAndWait(Stage owner, AlertType type, String title, String headerText,
String contentText) {
final Alert alert = new Alert(type);
alert.getDialogPane().getStylesheets().add("view/NewTheme.css");
alert.getDialogPane().getStylesheets().add("view/Theme.css");
alert.initOwner(owner);
alert.setTitle(title);
alert.setHeaderText(headerText);
Expand Down
Loading