From fb372916bf48cc1fe7000229d97423e2275f24b5 Mon Sep 17 00:00:00 2001 From: holmesjj Date: Thu, 4 Nov 2021 14:07:15 +0800 Subject: [PATCH 1/2] Fix billing bug and inconsistent format of the help boxes --- .../address/logic/commands/AddCommand.java | 7 ++-- .../logic/commands/AddMemberCommand.java | 23 ++++++------- .../logic/commands/AddReservationCommand.java | 19 +++++------ .../logic/commands/AddTransactionCommand.java | 15 +++++---- .../address/logic/commands/DeleteCommand.java | 7 ++-- .../logic/commands/DeleteMemberCommand.java | 8 ++--- .../commands/DeleteReservationCommand.java | 6 ++-- .../commands/DeleteTransactionCommand.java | 4 +-- .../address/logic/commands/EditCommand.java | 7 ++-- .../logic/commands/EditMemberCommand.java | 32 +++++++++---------- .../commands/EditReservationCommand.java | 12 +++---- .../commands/EditTransactionCommand.java | 8 ++--- .../address/logic/commands/FindCommand.java | 20 ++++++------ .../logic/commands/SetAccountCommand.java | 6 ++-- .../address/logic/commands/ViewCommand.java | 4 +-- .../address/logic/parser/ParserUtil.java | 4 +++ .../seedu/address/model/member/Credit.java | 12 +++++-- .../seedu/address/model/member/Point.java | 14 +++++--- .../address/model/transaction/Billing.java | 11 +++++-- 19 files changed, 126 insertions(+), 93 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 2e6485429e3..4d67cbc23d6 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_RESERVATION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TRANSACTION; import seedu.address.logic.commands.exceptions.CommandException; @@ -12,10 +13,12 @@ public abstract class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a member or a transaction to the ezFoodie.\n" + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Adds a member or a transaction or a reservation to the ezFoodie.\n" + "With " + PREFIX_MEMBER + " (member details) or " - + PREFIX_TRANSACTION + " (transaction details)"; + + PREFIX_TRANSACTION + " (transaction details) or " + + PREFIX_RESERVATION + " (reservation details)"; @Override public abstract CommandResult execute(Model model) throws CommandException; diff --git a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java index cc2a59ca0c0..30835dd4732 100644 --- a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java @@ -16,19 +16,20 @@ */ public class AddMemberCommand extends AddCommand { - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a member to the ezFoodie. " - + "Parameters: " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a member to the ezFoodie.\n" + + "Parameters:\n" + PREFIX_MEMBER + " " - + PREFIX_NAME + " " + "NAME " - + PREFIX_PHONE + " " + "PHONE " - + PREFIX_EMAIL + " " + "EMAIL " - + PREFIX_ADDRESS + " " + "ADDRESS\n" - + "Example: " + COMMAND_WORD + " " + + PREFIX_NAME + "NAME " + + PREFIX_PHONE + "PHONE " + + PREFIX_EMAIL + "EMAIL " + + PREFIX_ADDRESS + "ADDRESS\n" + + "Example:\n" + + COMMAND_WORD + " " + PREFIX_MEMBER + " " - + PREFIX_NAME + " " + "John Doe " - + PREFIX_PHONE + " " + "98765432 " - + PREFIX_EMAIL + " " + "johnd@example.com " - + PREFIX_ADDRESS + " " + "311, Clementi Ave 2, #02-25"; + + PREFIX_NAME + "John Doe " + + PREFIX_PHONE + "98765432 " + + PREFIX_EMAIL + "johnd@example.com " + + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25"; public static final String MESSAGE_SUCCESS = "New member added: %1$s"; public static final String MESSAGE_DUPLICATE_MEMBER = "This member already exists in the ezFoodie"; diff --git a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java index b5ed36035ee..01ea1acef27 100644 --- a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java @@ -35,17 +35,18 @@ public class AddReservationCommand extends AddCommand { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds reservation to member " - + "by member ID in the ezFoodie. " - + "Parameters: " + + "by member ID in the ezFoodie.\n" + + "Parameters:\n" + PREFIX_RESERVATION + " " - + PREFIX_DATE_TIME + " " + "DATE_TIME (" + DateTimeUtil.DATE_TIME_PATTERN + ") " - + PREFIX_REMARK + " " + "REMARK " - + PREFIX_ID + " " + "ID\n" - + "Example: " + COMMAND_WORD + " " + + PREFIX_DATE_TIME + "DATE_TIME (" + DateTimeUtil.DATE_TIME_PATTERN + ") " + + PREFIX_REMARK + "REMARK " + + PREFIX_ID + "ID\n" + + "Example:\n" + + COMMAND_WORD + " " + PREFIX_RESERVATION + " " - + PREFIX_DATE_TIME + " " + "2021-12-01 13:00 " - + PREFIX_REMARK + " " + "2 people " - + PREFIX_ID + " " + "10001"; + + PREFIX_DATE_TIME + "2021-12-01 13:00 " + + PREFIX_REMARK + "2 people " + + PREFIX_ID + "10001"; public static final String MESSAGE_SUCCESS = "New reservation added: %1$s"; diff --git a/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java b/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java index 25606bb3a01..608e3234b13 100644 --- a/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java @@ -32,15 +32,16 @@ */ public class AddTransactionCommand extends AddCommand { - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a transaction to each member in the ezFoodie. " - + "Parameters: " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a transaction to each member in the ezFoodie.\n" + + "Parameters:\n" + PREFIX_TRANSACTION + " " - + PREFIX_BILLING + " " + "BILLING (STRICTLY 2 DECIMAL PLACES) " - + PREFIX_ID + " " + "ID\n" - + "Example: " + COMMAND_WORD + " " + + PREFIX_BILLING + "BILLING (STRICTLY 2 DECIMAL PLACES) " + + PREFIX_ID + "ID\n" + + "Example:\n" + + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " - + PREFIX_BILLING + " " + "23.00 " - + PREFIX_ID + " " + "10001"; + + PREFIX_BILLING + "23.00 " + + PREFIX_ID + "10001"; public static final String MESSAGE_SUCCESS = "New transaction added: %1$s"; diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 8e719db5898..b172b0c1bd1 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_RESERVATION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TRANSACTION; import seedu.address.logic.commands.exceptions.CommandException; @@ -12,10 +13,12 @@ public abstract class DeleteCommand extends Command { public static final String COMMAND_WORD = "del"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes a member or a transaction from the ezFoodie.\n" + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Deletes a member or a transaction or a reservation from the ezFoodie.\n" + "With " + PREFIX_MEMBER + " (member details) or " - + PREFIX_TRANSACTION + " (transaction details)"; + + PREFIX_TRANSACTION + " (transaction details) or " + + PREFIX_RESERVATION + " (reservation details)"; @Override public abstract CommandResult execute(Model model) throws CommandException; diff --git a/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java b/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java index ac2ba8fcd2c..386eca1ebf3 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteMemberCommand.java @@ -22,12 +22,12 @@ public class DeleteMemberCommand extends DeleteCommand { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the member identified by the index number used in the displayed member list or member ID.\n" + "Parameters:\n" - + "Delete by index number: " + PREFIX_MEMBER + " [" + PREFIX_INDEX + " INDEX]" + + "Delete by index number: " + PREFIX_MEMBER + " " + PREFIX_INDEX + "INDEX" + " (INDEX must be a positive integer)\n" - + "Delete by member ID: " + PREFIX_MEMBER + " [" + PREFIX_ID + " ID]\n" + + "Delete by member ID: " + PREFIX_MEMBER + " " + PREFIX_ID + "ID\n" + "Example:\n" - + "Delete by index number: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_INDEX + " 1\n" - + "Delete by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + " 10001"; + + "Delete by index number: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_INDEX + "1\n" + + "Delete by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + "10001"; public static final String MESSAGE_SUCCESS = "Deleted Member: %1$s"; diff --git a/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java b/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java index d9688bc447f..1dd3ea96b73 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteReservationCommand.java @@ -34,10 +34,10 @@ public class DeleteReservationCommand extends DeleteCommand { + ": Deletes the reservation identified by the member ID and reservation ID.\n" + "Parameters:\n" + "Delete by member ID and reservation ID: " - + PREFIX_RESERVATION + " " + PREFIX_ID + " member ID + reservation ID\n" + + PREFIX_RESERVATION + " " + PREFIX_ID + "member ID + reservation ID\n" + "Example:\n" + "Delete by member ID and reservation ID: " - + COMMAND_WORD + " " + PREFIX_RESERVATION + " " + PREFIX_ID + " 10001100001"; + + COMMAND_WORD + " " + PREFIX_RESERVATION + " " + PREFIX_ID + "10001100001"; public static final String MESSAGE_SUCCESS = "Deleted reservation: %1$s"; @@ -76,7 +76,7 @@ private static Member createUpdatedReservation(Member memberToEdit, Reservation updatedReservations.remove(reservation); return new Member(id, updatedName, updatedPhone, updatedEmail, updatedAddress, timestamp, credit, point, - transactions, reservations, updatedTags); + transactions, updatedReservations, updatedTags); } @Override diff --git a/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java index 7c92348a66a..dd80a5b5891 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTransactionCommand.java @@ -35,10 +35,10 @@ public class DeleteTransactionCommand extends DeleteCommand { + ": Deletes the transaction identified by the member ID and transaction ID.\n" + "Parameters:\n" + "Delete by member ID and transaction ID: " - + PREFIX_TRANSACTION + " " + PREFIX_ID + " member ID + transaction ID\n" + + PREFIX_TRANSACTION + " " + PREFIX_ID + "member ID + transaction ID\n" + "Example:\n" + "Delete by member ID and transaction ID: " - + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " + PREFIX_ID + " 10001100001"; + + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " + PREFIX_ID + "10001100001"; public static final String MESSAGE_SUCCESS = "Deleted Transaction: %1$s"; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 94bdb188ea9..9bb5e066de6 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,7 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.parser.CliSyntax.PREFIX_MEMBER; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PASS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_RESERVATION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TRANSACTION; import seedu.address.logic.commands.exceptions.CommandException; @@ -13,11 +13,12 @@ public abstract class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits a member or a transaction in the ezFoodie.\n" + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Edits a member or a transaction or a reservation in the ezFoodie.\n" + "With " + PREFIX_MEMBER + " (member details) or " + PREFIX_TRANSACTION + " (transaction details) or " - + PREFIX_PASS + " (password details)"; + + PREFIX_RESERVATION + " (reservation details)"; @Override public abstract CommandResult execute(Model model) throws CommandException; diff --git a/src/main/java/seedu/address/logic/commands/EditMemberCommand.java b/src/main/java/seedu/address/logic/commands/EditMemberCommand.java index d3353be1738..47ec942c80d 100644 --- a/src/main/java/seedu/address/logic/commands/EditMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditMemberCommand.java @@ -44,24 +44,24 @@ public class EditMemberCommand extends EditCommand { + "by the index number used in the displayed member list or the member ID. " + "Existing values will be overwritten by the input values.\n" + "Parameters:\n" - + "Edit by index number: " + PREFIX_MEMBER + " [" + PREFIX_INDEX + " INDEX] " + + "Edit by index number: " + PREFIX_MEMBER + " " + PREFIX_INDEX + "INDEX " + "(INDEX must be a positive integer) " - + "[" + PREFIX_NAME + " NAME] " - + "[" + PREFIX_PHONE + " PHONE] " - + "[" + PREFIX_EMAIL + " EMAIL] " - + "[" + PREFIX_ADDRESS + " ADDRESS]\n" - + "Edit by member ID: " + PREFIX_MEMBER + " [" + PREFIX_ID + " ID] " - + "[" + PREFIX_NAME + " NAME] " - + "[" + PREFIX_PHONE + " PHONE] " - + "[" + PREFIX_EMAIL + " EMAIL] " - + "[" + PREFIX_ADDRESS + " ADDRESS]\n" + + "[" + PREFIX_NAME + "NAME] " + + "[" + PREFIX_PHONE + "PHONE] " + + "[" + PREFIX_EMAIL + "EMAIL] " + + "[" + PREFIX_ADDRESS + "ADDRESS]\n" + + "Edit by member ID: " + PREFIX_MEMBER + " " + PREFIX_ID + "ID " + + "[" + PREFIX_NAME + "NAME] " + + "[" + PREFIX_PHONE + "PHONE] " + + "[" + PREFIX_EMAIL + "EMAIL] " + + "[" + PREFIX_ADDRESS + "ADDRESS]\n" + "Example:\n" - + "Edit by index number: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_INDEX + " 1 " - + PREFIX_PHONE + " 91234567 " - + PREFIX_EMAIL + " johndoe@example.com\n" - + "Edit by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + " 10001 " - + PREFIX_PHONE + " 91234567 " - + PREFIX_EMAIL + " johndoe@example.com"; + + "Edit by index number: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_INDEX + "1 " + + PREFIX_PHONE + "91234567 " + + PREFIX_EMAIL + "johndoe@example.com\n" + + "Edit by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + "10001 " + + PREFIX_PHONE + "91234567 " + + PREFIX_EMAIL + "johndoe@example.com"; public static final String MESSAGE_SUCCESS = "Edited Member: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; diff --git a/src/main/java/seedu/address/logic/commands/EditReservationCommand.java b/src/main/java/seedu/address/logic/commands/EditReservationCommand.java index e256dc05f18..f257c443a45 100644 --- a/src/main/java/seedu/address/logic/commands/EditReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditReservationCommand.java @@ -41,14 +41,14 @@ public class EditReservationCommand extends EditCommand { + "Existing values will be overwritten by the input values.\n" + "Parameters:\n" + "Edit by member ID and reservation ID: " - + PREFIX_RESERVATION + " " + PREFIX_ID + " member ID + reservation ID " - + "[" + PREFIX_DATE_TIME + " DATE_TIME]" - + "[" + PREFIX_REMARK + " REMARK]\n" + + PREFIX_RESERVATION + " " + PREFIX_ID + "member ID + reservation ID " + + "[" + PREFIX_DATE_TIME + "DATE_TIME] " + + "[" + PREFIX_REMARK + "REMARK]\n" + "Example:\n" + "Edit by member ID and reservation ID: " - + COMMAND_WORD + " " + PREFIX_RESERVATION + " " + PREFIX_ID + " 10001100001 " - + PREFIX_DATE_TIME + " 2021-12-01 13:00" - + PREFIX_REMARK + " 3 people"; + + COMMAND_WORD + " " + PREFIX_RESERVATION + " " + PREFIX_ID + "10001100001 " + + PREFIX_DATE_TIME + "2021-12-01 13:00 " + + PREFIX_REMARK + "3 people"; public static final String MESSAGE_SUCCESS = "Edited Member: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; diff --git a/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java b/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java index 4d303f03775..dce6fec29d3 100644 --- a/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditTransactionCommand.java @@ -39,12 +39,12 @@ public class EditTransactionCommand extends EditCommand { + "Existing values will be overwritten by the input values.\n" + "Parameters:\n" + "Edit by member ID and transaction ID: " - + PREFIX_TRANSACTION + " " + PREFIX_ID + " member ID + transaction ID " - + "[" + PREFIX_BILLING + " BILLING]\n" + + PREFIX_TRANSACTION + " " + PREFIX_ID + "member ID + transaction ID " + + "[" + PREFIX_BILLING + "BILLING]\n" + "Example:\n" + "Edit by member ID and transaction ID: " - + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " + PREFIX_ID + " 10001100001 " - + PREFIX_BILLING + " 123.45"; + + COMMAND_WORD + " " + PREFIX_TRANSACTION + " " + PREFIX_ID + "10001100001 " + + PREFIX_BILLING + "123.45"; public static final String MESSAGE_SUCCESS = "Edited Member: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; diff --git a/src/main/java/seedu/address/logic/commands/FindCommand.java b/src/main/java/seedu/address/logic/commands/FindCommand.java index 9854e87cbed..9b337a8e2d4 100644 --- a/src/main/java/seedu/address/logic/commands/FindCommand.java +++ b/src/main/java/seedu/address/logic/commands/FindCommand.java @@ -32,18 +32,18 @@ public class FindCommand extends Command { + "the specified keywords (case-insensitive) or within a specific of registration dates " + "and displays them as a list with index numbers.\n" + "Parameters:\n" - + "Find by member ID: " + PREFIX_MEMBER + " [" + PREFIX_ID + " ID]\n" - + "Find by name: " + PREFIX_MEMBER + " [" + PREFIX_NAME + " NAME]\n" - + "Find by phone: " + PREFIX_MEMBER + " [" + PREFIX_PHONE + " PHONE]\n" - + "Find by email: " + PREFIX_MEMBER + " [" + PREFIX_EMAIL + " EMAIL]\n" - + "Find by registration date: " + PREFIX_MEMBER + " [" + PREFIX_DATE + " REGISTRATION_DATE]\n" + + "Find by member ID: " + PREFIX_MEMBER + " [" + PREFIX_ID + "ID]\n" + + "Find by name: " + PREFIX_MEMBER + " [" + PREFIX_NAME + "NAME]\n" + + "Find by phone: " + PREFIX_MEMBER + " [" + PREFIX_PHONE + "PHONE]\n" + + "Find by email: " + PREFIX_MEMBER + " [" + PREFIX_EMAIL + "EMAIL]\n" + + "Find by registration date: " + PREFIX_MEMBER + " [" + PREFIX_DATE + "REGISTRATION_DATE]\n" + "Example:\n" - + "Find by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " [" + PREFIX_ID + " 10001]\n" - + "Find by name: " + COMMAND_WORD + " " + PREFIX_MEMBER + " [" + PREFIX_NAME + " Alex]\n" - + "Find by phone: " + COMMAND_WORD + " " + PREFIX_MEMBER + " [" + PREFIX_PHONE + " 87438807]\n" - + "Find by email: " + COMMAND_WORD + " " + PREFIX_MEMBER + " [" + PREFIX_EMAIL + " alexyeoh@example.com]\n" + + "Find by member ID: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + "10001\n" + + "Find by name: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_NAME + "Alex\n" + + "Find by phone: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_PHONE + "87438807\n" + + "Find by email: " + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_EMAIL + "alexyeoh@example.com\n" + "Find by registration date: " + COMMAND_WORD + " " + PREFIX_MEMBER - + " [" + PREFIX_DATE + " 2021-01-02]"; + + " " + PREFIX_DATE + " 2021-01-02"; private final Predicate predicate; diff --git a/src/main/java/seedu/address/logic/commands/SetAccountCommand.java b/src/main/java/seedu/address/logic/commands/SetAccountCommand.java index b0b63b087c1..4e1d870e2f4 100644 --- a/src/main/java/seedu/address/logic/commands/SetAccountCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetAccountCommand.java @@ -16,12 +16,12 @@ public class SetAccountCommand extends Command { public static final String COMMAND_WORD = "set"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits login password. " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Sets login password. " + "Existing password will be overwritten by the new password.\n" + "Parameters: " - + PREFIX_PASS + " PASSWORD\n" + + PREFIX_PASS + "PASSWORD\n" + "Example: " - + COMMAND_WORD + " " + PREFIX_PASS + " 123456"; + + COMMAND_WORD + " " + PREFIX_PASS + "123456"; public static final String MESSAGE_SUCCESS = "Password updated"; diff --git a/src/main/java/seedu/address/logic/commands/ViewCommand.java b/src/main/java/seedu/address/logic/commands/ViewCommand.java index e277af2fa67..23f50e4a37e 100644 --- a/src/main/java/seedu/address/logic/commands/ViewCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewCommand.java @@ -20,9 +20,9 @@ public class ViewCommand extends Command { + ": View a specific member's details, " + "accessed by member ID.\n" + "Parameters:\n" - + PREFIX_MEMBER + " " + PREFIX_ID + " ID\n" + + PREFIX_MEMBER + " " + PREFIX_ID + "ID\n" + "Example:\n" - + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + " 10001"; + + COMMAND_WORD + " " + PREFIX_MEMBER + " " + PREFIX_ID + "10001"; private final IdContainsKeywordsPredicate predicate; diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index ad9512de7b2..21eddcfc42b 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -2,6 +2,8 @@ import static java.util.Objects.requireNonNull; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collection; @@ -175,6 +177,8 @@ public static Billing parseBilling(String billing) throws ParseException { if (!Billing.isValidBilling(trimmedBilling)) { throw new ParseException(Billing.MESSAGE_CONSTRAINTS); } + trimmedBilling = BigDecimal.valueOf(Double.parseDouble(trimmedBilling)).stripTrailingZeros() + .setScale(2, RoundingMode.HALF_EVEN).toPlainString(); return new Billing(trimmedBilling); } diff --git a/src/main/java/seedu/address/model/member/Credit.java b/src/main/java/seedu/address/model/member/Credit.java index 0a6680d88dc..6cc9ec5d8f6 100644 --- a/src/main/java/seedu/address/model/member/Credit.java +++ b/src/main/java/seedu/address/model/member/Credit.java @@ -9,10 +9,11 @@ */ public class Credit { + public static final int MAX = 99999999; public static final String MESSAGE_CONSTRAINTS = - "Credits should only contain no more than 8 digits, and it should not be blank"; + "Credits should only contain no more than 8 digits and it should not be blank, and max amount is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; - public static final int MAX = 99999999; public static final int LENGTH = 8; // Max credit is 99999999 public final String value; @@ -32,7 +33,12 @@ public Credit(String credit) { * Returns true if a given string is a valid credit. */ public static boolean isValidCredit(String test) { - return test.matches(VALIDATION_REGEX) && test.length() <= LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Integer.parseInt(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } } /** diff --git a/src/main/java/seedu/address/model/member/Point.java b/src/main/java/seedu/address/model/member/Point.java index 2c048c5088e..f6ea27dffbe 100644 --- a/src/main/java/seedu/address/model/member/Point.java +++ b/src/main/java/seedu/address/model/member/Point.java @@ -8,11 +8,12 @@ * and it can be redeem from a redemption process */ public class Point { - public static final String MESSAGE_CONSTRAINTS = - "Points should only contain no more than 8 digits, and it should not be blank"; - public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int MAX = 99999999; + public static final String MESSAGE_CONSTRAINTS = + "Points should only contain no more than 8 digits and it should not be blank, and max amount is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; + public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int LENGTH = 8; // Max point is 99999999 public final String value; @@ -32,7 +33,12 @@ public Point(String point) { * Returns true if a given string is a valid point. */ public static boolean isValidPoint(String test) { - return test.matches(VALIDATION_REGEX) && test.length() <= LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Integer.parseInt(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } } /** diff --git a/src/main/java/seedu/address/model/transaction/Billing.java b/src/main/java/seedu/address/model/transaction/Billing.java index 8ea00f450dd..6ca17f2c053 100644 --- a/src/main/java/seedu/address/model/transaction/Billing.java +++ b/src/main/java/seedu/address/model/transaction/Billing.java @@ -9,8 +9,10 @@ */ public class Billing { + public static final double MAX = 9999.99; public static final String MESSAGE_CONSTRAINTS = - "Billings should be numeric with 2 decimal places, and max amount is 9999.99"; + "Billings should be positive numeric with 2 decimal places, and max amount is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "\\d*\\.\\d{2}$"; public static final int LENGTH = 7; // Max amount is 9999.99 @@ -31,7 +33,12 @@ public Billing(String billing) { * Returns true if a given string is a valid billing amount. */ public static boolean isValidBilling(String test) { - return test.matches(VALIDATION_REGEX) && test.length() <= LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Double.parseDouble(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } } /** From 5fd10c368c2f5fa59592d8f93f06b9ce1c666b23 Mon Sep 17 00:00:00 2001 From: holmesjj Date: Thu, 4 Nov 2021 14:07:45 +0800 Subject: [PATCH 2/2] The member list will be initialized when logout, fix bugs of ID checking --- .../logic/commands/AddMemberCommand.java | 2 ++ .../logic/commands/AddReservationCommand.java | 8 +++--- .../logic/commands/AddTransactionCommand.java | 8 +++--- .../address/logic/commands/LogoutCommand.java | 2 ++ .../logic/parser/AddMemberCommandParser.java | 9 ++++--- .../parser/AddReservationCommandParser.java | 12 ++++++--- .../parser/AddTransactionCommandParser.java | 13 ++++++---- src/main/java/seedu/address/model/Model.java | 5 ++++ .../seedu/address/model/ModelManager.java | 1 + .../seedu/address/model/member/Credit.java | 2 +- .../model/member/CreditSortComparator.java | 2 +- .../java/seedu/address/model/member/Id.java | 22 +++++++++++++--- .../seedu/address/model/member/Member.java | 1 - .../seedu/address/model/member/Point.java | 2 +- .../seedu/address/model/reservation/Id.java | 25 +++++++++++++++---- .../seedu/address/model/transaction/Id.java | 22 +++++++++++++--- 16 files changed, 99 insertions(+), 37 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java index 30835dd4732..af832bbc084 100644 --- a/src/main/java/seedu/address/logic/commands/AddMemberCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddMemberCommand.java @@ -9,6 +9,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.member.Id; import seedu.address.model.member.Member; /** @@ -32,6 +33,7 @@ public class AddMemberCommand extends AddCommand { + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25"; public static final String MESSAGE_SUCCESS = "New member added: %1$s"; + public static final String MESSAGE_FULL = "Member ID has reached " + Id.MAX; public static final String MESSAGE_DUPLICATE_MEMBER = "This member already exists in the ezFoodie"; private final Member toAdd; diff --git a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java index 01ea1acef27..06654f85d22 100644 --- a/src/main/java/seedu/address/logic/commands/AddReservationCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddReservationCommand.java @@ -20,7 +20,6 @@ import seedu.address.model.member.Address; import seedu.address.model.member.Credit; import seedu.address.model.member.Email; -import seedu.address.model.member.Id; import seedu.address.model.member.Member; import seedu.address.model.member.Name; import seedu.address.model.member.Phone; @@ -49,14 +48,15 @@ public class AddReservationCommand extends AddCommand { + PREFIX_ID + "10001"; public static final String MESSAGE_SUCCESS = "New reservation added: %1$s"; + public static final String MESSAGE_FULL = "Reservation ID has reached " + seedu.address.model.reservation.Id.MAX; private final Reservation reservationToAdd; - private final Id idToAdd; + private final seedu.address.model.member.Id idToAdd; /** * Creates an AddReservationCommand to add the specified {@code Member} */ - public AddReservationCommand(Reservation reservation, Id id) { + public AddReservationCommand(Reservation reservation, seedu.address.model.member.Id id) { requireAllNonNull(reservation, id); reservationToAdd = reservation; idToAdd = id; @@ -84,7 +84,7 @@ public CommandResult execute(Model model) throws CommandException { private static Member createUpdatedReservations(Member memberToEdit, Reservation reservation) { assert memberToEdit != null; - Id id = memberToEdit.getId(); + seedu.address.model.member.Id id = memberToEdit.getId(); Name name = memberToEdit.getName(); Phone phone = memberToEdit.getPhone(); Email email = memberToEdit.getEmail(); diff --git a/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java b/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java index 608e3234b13..1032b025072 100644 --- a/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTransactionCommand.java @@ -18,7 +18,6 @@ import seedu.address.model.member.Address; import seedu.address.model.member.Credit; import seedu.address.model.member.Email; -import seedu.address.model.member.Id; import seedu.address.model.member.Member; import seedu.address.model.member.Name; import seedu.address.model.member.Phone; @@ -44,14 +43,15 @@ public class AddTransactionCommand extends AddCommand { + PREFIX_ID + "10001"; public static final String MESSAGE_SUCCESS = "New transaction added: %1$s"; + public static final String MESSAGE_FULL = "Transaction ID has reached " + seedu.address.model.transaction.Id.MAX; private final Transaction transactionToAdd; - private final Id idToAdd; + private final seedu.address.model.member.Id idToAdd; /** * Creates an AddTransactionCommand to add the specified {@code Member} */ - public AddTransactionCommand(Transaction transaction, Id id) { + public AddTransactionCommand(Transaction transaction, seedu.address.model.member.Id id) { requireAllNonNull(transaction, id); transactionToAdd = transaction; idToAdd = id; @@ -78,7 +78,7 @@ public CommandResult execute(Model model) throws CommandException { private static Member createUpdatedCreditAndPointsMember(Member memberToEdit, Transaction transaction) { assert memberToEdit != null; - Id id = memberToEdit.getId(); + seedu.address.model.member.Id id = memberToEdit.getId(); Name updatedName = memberToEdit.getName(); Phone updatedPhone = memberToEdit.getPhone(); Email updatedEmail = memberToEdit.getEmail(); diff --git a/src/main/java/seedu/address/logic/commands/LogoutCommand.java b/src/main/java/seedu/address/logic/commands/LogoutCommand.java index 52a464c08fd..4af0b530f6f 100644 --- a/src/main/java/seedu/address/logic/commands/LogoutCommand.java +++ b/src/main/java/seedu/address/logic/commands/LogoutCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.COMPARATOR_SORT_MEMBERS_BY_ID_ASC; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MEMBERS; import seedu.address.commons.status.LoginStatus; @@ -22,6 +23,7 @@ public CommandResult execute(Model model) { return new CommandResult(MESSAGE_ALREADY_IN_STATUS); } LoginStatus.setLoginStatus(LoginStatus.STAFF); + model.updateSortedMemberList(COMPARATOR_SORT_MEMBERS_BY_ID_ASC); model.updateFilteredMemberList(PREDICATE_SHOW_ALL_MEMBERS); return new CommandResult(MESSAGE_SUCCESS); } diff --git a/src/main/java/seedu/address/logic/parser/AddMemberCommandParser.java b/src/main/java/seedu/address/logic/parser/AddMemberCommandParser.java index c8fdb3fad13..fd486763dea 100644 --- a/src/main/java/seedu/address/logic/parser/AddMemberCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddMemberCommandParser.java @@ -49,13 +49,16 @@ public AddMemberCommandParser(Model model, ExecutionStatus executionStatus) { this.executionStatus = executionStatus; } - private String generateId() { + private String generateId() throws ParseException { List memberList = model.getEzFoodie().getMemberList(); long latestId = 0; if (memberList.size() > 0) { - latestId = Long.parseLong(memberList.get(memberList.size() - 1).getId().value); + latestId = memberList.get(memberList.size() - 1).getId().getLongValue(); } - return String.format(Id.PATTERN, latestId + 1); + if (latestId == Id.MAX) { + throw new ParseException(AddMemberCommand.MESSAGE_FULL); + } + return Long.toString(latestId + 1); } private String generateIdStub() { diff --git a/src/main/java/seedu/address/logic/parser/AddReservationCommandParser.java b/src/main/java/seedu/address/logic/parser/AddReservationCommandParser.java index 9b48cb3bfe4..b9b6a13c99f 100644 --- a/src/main/java/seedu/address/logic/parser/AddReservationCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddReservationCommandParser.java @@ -1,6 +1,7 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_MEMBER_DISPLAYED_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_TIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; @@ -35,7 +36,7 @@ public AddReservationCommandParser(Model model, ExecutionStatus executionStatus) this.executionStatus = executionStatus; } - private String generateId(seedu.address.model.member.Id id) { + private String generateId(seedu.address.model.member.Id id) throws ParseException { List lastShownList = model.getUpdatedMemberList(); Member memberToEdit = lastShownList.stream() .filter(member -> id.equals(member.getId())).findAny().orElse(null); @@ -43,11 +44,14 @@ private String generateId(seedu.address.model.member.Id id) { List reservationList = memberToEdit.getReservations(); long latestId = 0; if (reservationList.size() > 0) { - latestId = Long.parseLong(reservationList.get(reservationList.size() - 1).getId().value); + latestId = reservationList.get(reservationList.size() - 1).getId().getLongValue(); } - return String.format(seedu.address.model.member.Id.PATTERN, latestId + 1); + if (latestId == seedu.address.model.reservation.Id.MAX) { + throw new ParseException(AddReservationCommand.MESSAGE_FULL); + } + return Long.toString(latestId + 1); } else { - return ID_STUB; + throw new ParseException(MESSAGE_INVALID_MEMBER_DISPLAYED_ID); } } diff --git a/src/main/java/seedu/address/logic/parser/AddTransactionCommandParser.java b/src/main/java/seedu/address/logic/parser/AddTransactionCommandParser.java index 5641717bf57..7b12b697e44 100644 --- a/src/main/java/seedu/address/logic/parser/AddTransactionCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddTransactionCommandParser.java @@ -1,6 +1,7 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_MEMBER_DISPLAYED_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_BILLING; import static seedu.address.logic.parser.CliSyntax.PREFIX_ID; import static seedu.address.logic.parser.CliSyntax.PREFIX_TRANSACTION; @@ -14,7 +15,6 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.Timestamp; -import seedu.address.model.member.Id; import seedu.address.model.member.Member; import seedu.address.model.transaction.Billing; import seedu.address.model.transaction.Transaction; @@ -37,7 +37,7 @@ public AddTransactionCommandParser(Model model, ExecutionStatus executionStatus) this.executionStatus = executionStatus; } - private String generateId(seedu.address.model.member.Id id) { + private String generateId(seedu.address.model.member.Id id) throws ParseException { List lastShownList = model.getUpdatedMemberList(); Member memberToEdit = lastShownList.stream() .filter(member -> id.equals(member.getId())).findAny().orElse(null); @@ -45,11 +45,14 @@ private String generateId(seedu.address.model.member.Id id) { List transactionList = memberToEdit.getTransactions(); long latestId = 0; if (transactionList.size() > 0) { - latestId = Long.parseLong(transactionList.get(transactionList.size() - 1).getId().value); + latestId = transactionList.get(transactionList.size() - 1).getId().getLongValue(); } - return String.format(Id.PATTERN, latestId + 1); + if (latestId == seedu.address.model.transaction.Id.MAX) { + throw new ParseException(AddTransactionCommand.MESSAGE_FULL); + } + return Long.toString(latestId + 1); } else { - return ID_STUB; + throw new ParseException(MESSAGE_INVALID_MEMBER_DISPLAYED_ID); } } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 09e68f87f00..d5072cf16ef 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -18,6 +18,11 @@ public interface Model { */ Predicate PREDICATE_SHOW_ALL_MEMBERS = unused -> true; + /** + * {@code Comparator} sort members by id asc + */ + Comparator COMPARATOR_SORT_MEMBERS_BY_ID_ASC = Comparator.comparingLong(m -> m.getId().getLongValue()); + /** * Replaces user prefs data with the data in {@code userPrefs}. */ diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index dd2d30eaada..7e08ea56020 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -48,6 +48,7 @@ public ModelManager(ReadOnlyAccount account, ReadOnlyEzFoodie ezFoodie, ReadOnly filteredMembers = new FilteredList<>(this.ezFoodie.getMemberList()); filteredMembersForView = new FilteredList<>(this.ezFoodie.getMemberList()); sortedMembers = new SortedList<>(filteredMembers); // Wrap the FilteredList in a SortedList + sortedMembers.setComparator(COMPARATOR_SORT_MEMBERS_BY_ID_ASC); } public ModelManager() { diff --git a/src/main/java/seedu/address/model/member/Credit.java b/src/main/java/seedu/address/model/member/Credit.java index 6cc9ec5d8f6..d129695ee08 100644 --- a/src/main/java/seedu/address/model/member/Credit.java +++ b/src/main/java/seedu/address/model/member/Credit.java @@ -11,7 +11,7 @@ public class Credit { public static final int MAX = 99999999; public static final String MESSAGE_CONSTRAINTS = - "Credits should only contain no more than 8 digits and it should not be blank, and max amount is " + MAX; + "Credits should only contain no more than 8 digits and it should not be blank, and max credit is " + MAX; public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int LENGTH = 8; // Max credit is 99999999 diff --git a/src/main/java/seedu/address/model/member/CreditSortComparator.java b/src/main/java/seedu/address/model/member/CreditSortComparator.java index 17bc96ec86a..44beddb55f6 100644 --- a/src/main/java/seedu/address/model/member/CreditSortComparator.java +++ b/src/main/java/seedu/address/model/member/CreditSortComparator.java @@ -5,7 +5,7 @@ import seedu.address.commons.status.SortStatus; /** - * Tests that a {@code Member}'s {@code Email} matches any of the keywords given. + * Compares that the credits between 2 members. */ public class CreditSortComparator implements Comparator { diff --git a/src/main/java/seedu/address/model/member/Id.java b/src/main/java/seedu/address/model/member/Id.java index 78a41b9708a..2dc06b070b3 100644 --- a/src/main/java/seedu/address/model/member/Id.java +++ b/src/main/java/seedu/address/model/member/Id.java @@ -9,11 +9,13 @@ */ public class Id { + public static final int MAX = 99999; public static final String MESSAGE_CONSTRAINTS = - "Ids should only contain 5 digits, and it should not be blank"; + "Member IDs should only contain 5 digits and it should not be blank, and max ID is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final String PATTERN = "%05d"; - public static final int LENGTH = 5; + public static final int LENGTH = 5; // Max ID is 99999 public final String value; @@ -25,14 +27,26 @@ public class Id { public Id(String id) { requireNonNull(id); checkArgument(isValidId(id), MESSAGE_CONSTRAINTS); - value = id; + value = String.format(PATTERN, Long.parseLong(id)); } /** * Returns true if a given string is a valid id. */ public static boolean isValidId(String test) { - return test.matches(VALIDATION_REGEX) && test.length() == LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Long.parseLong(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } + } + + /** + * Returns long value of id. + */ + public Long getLongValue() { + return Long.parseLong(value); } @Override diff --git a/src/main/java/seedu/address/model/member/Member.java b/src/main/java/seedu/address/model/member/Member.java index dae5abb13f4..c62f4c73a56 100644 --- a/src/main/java/seedu/address/model/member/Member.java +++ b/src/main/java/seedu/address/model/member/Member.java @@ -33,7 +33,6 @@ public class Member { private final Point point; private final Set tags = new HashSet<>(); - private final List redemptionsList = new ArrayList<>(); private final List transactions = new ArrayList<>(); private final List reservations = new ArrayList<>(); diff --git a/src/main/java/seedu/address/model/member/Point.java b/src/main/java/seedu/address/model/member/Point.java index f6ea27dffbe..64d0edca1d0 100644 --- a/src/main/java/seedu/address/model/member/Point.java +++ b/src/main/java/seedu/address/model/member/Point.java @@ -11,7 +11,7 @@ public class Point { public static final int MAX = 99999999; public static final String MESSAGE_CONSTRAINTS = - "Points should only contain no more than 8 digits and it should not be blank, and max amount is " + MAX; + "Points should only contain no more than 8 digits and it should not be blank, and max point is " + MAX; public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final int LENGTH = 8; // Max point is 99999999 diff --git a/src/main/java/seedu/address/model/reservation/Id.java b/src/main/java/seedu/address/model/reservation/Id.java index fd93568e1e4..2cd6028ea3c 100644 --- a/src/main/java/seedu/address/model/reservation/Id.java +++ b/src/main/java/seedu/address/model/reservation/Id.java @@ -5,15 +5,17 @@ /** * Represents a Reservation's id in the ezFoodie. - * Guarantees: ummutable, is valid as declared in {@link #isValidId(String)} + * Guarantees: immutable, is valid as declared in {@link #isValidId(String)} */ public class Id { + public static final int MAX = 999999; public static final String MESSAGE_CONSTRAINTS = - "Reservation IDs should only contain 6 digits, and it should not be blank"; + "Reservation IDs should only contain 6 digits and it should not be blank, and max ID is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final String PATTERN = "%06d"; - public static final int LENGTH = 6; + public static final int LENGTH = 6; // Max ID is 999999 public final String value; @@ -25,14 +27,26 @@ public class Id { public Id(String id) { requireNonNull(id); checkArgument(isValidId(id), MESSAGE_CONSTRAINTS); - value = id; + value = String.format(PATTERN, Long.parseLong(id)); } /** * Returns true if a given string is a valid id. */ public static boolean isValidId(String test) { - return test.matches(VALIDATION_REGEX) && test.length() == LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Long.parseLong(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } + } + + /** + * Returns long value of id. + */ + public Long getLongValue() { + return Long.parseLong(value); } @Override @@ -51,4 +65,5 @@ public boolean equals(Object other) { public int hashCode() { return value.hashCode(); } + } diff --git a/src/main/java/seedu/address/model/transaction/Id.java b/src/main/java/seedu/address/model/transaction/Id.java index 4bc2a1813c0..6945bf28485 100644 --- a/src/main/java/seedu/address/model/transaction/Id.java +++ b/src/main/java/seedu/address/model/transaction/Id.java @@ -9,11 +9,13 @@ */ public class Id { + public static final int MAX = 999999; public static final String MESSAGE_CONSTRAINTS = - "Transactions should only contain 6 digits, and it should not be blank"; + "Transaction IDs should only contain 6 digits and it should not be blank, and max ID is " + MAX; + public static final String TRIM_LEADING_ZERO_REGEX = "^0+(?!$)"; public static final String VALIDATION_REGEX = "[\\p{Digit}]*"; public static final String PATTERN = "%06d"; - public static final int LENGTH = 6; + public static final int LENGTH = 6; // Max ID is 999999 public final String value; @@ -25,14 +27,26 @@ public class Id { public Id(String id) { requireNonNull(id); checkArgument(isValidId(id), MESSAGE_CONSTRAINTS); - value = id; + value = String.format(PATTERN, Long.parseLong(id)); } /** * Returns true if a given string is a valid id. */ public static boolean isValidId(String test) { - return test.matches(VALIDATION_REGEX) && test.length() == LENGTH; + test = test.replaceFirst(TRIM_LEADING_ZERO_REGEX, ""); + try { + return test.length() <= LENGTH && Long.parseLong(test) <= MAX && test.matches(VALIDATION_REGEX); + } catch (NumberFormatException e) { + return false; + } + } + + /** + * Returns long value of id. + */ + public Long getLongValue() { + return Long.parseLong(value); } @Override