From 0d99012fd09d75c7c591cc6040eabda64d3f426b Mon Sep 17 00:00:00 2001 From: Ivan Jerrick Koh Yu En Date: Mon, 11 Nov 2024 22:27:51 +0800 Subject: [PATCH 1/3] Fix valid hours regex --- .../java/seedu/address/model/person/Hours.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Hours.java b/src/main/java/seedu/address/model/person/Hours.java index 6c921be085c..787092fccb3 100644 --- a/src/main/java/seedu/address/model/person/Hours.java +++ b/src/main/java/seedu/address/model/person/Hours.java @@ -11,7 +11,7 @@ public class Hours { public static final String MESSAGE_CONSTRAINTS = "Hours should be non-negative integers, with a maximum of 876,000."; - public static final String VALIDATION_REGEX = "^(?:\\d{1,5}|[1-7]\\d{5}|8[0-6]\\d{4}|87[0-5]\\d{3}|876000)$"; + public static final String VALIDATION_REGEX = "^(?:0*([0-9]{1,5}|[1-7][0-9]{5}|8[0-6][0-9]{4}|87[0-5][0-9]{3}|876000))$"; public final String value; /** @@ -22,7 +22,7 @@ public class Hours { public Hours(String hour) { requireNonNull(hour); checkArgument(isValidHours(hour), MESSAGE_CONSTRAINTS); - value = hour; + value = clearLeadingZeroes(hour); } public int getHoursInt() { @@ -36,6 +36,16 @@ public static boolean isValidHours(String test) { return test.matches(VALIDATION_REGEX); } + public static String clearLeadingZeroes(String hours) { + requireNonNull(hours); + String cleanedString = hours.replaceFirst("^0+", ""); + if (cleanedString.isEmpty()) { + return "0"; + } else { + return cleanedString; + } + } + @Override public String toString() { return value; From cec3414b3eff7b6b8973bd0d476a7e032ecd24f6 Mon Sep 17 00:00:00 2001 From: Ivan Jerrick Koh Yu En Date: Mon, 11 Nov 2024 22:31:34 +0800 Subject: [PATCH 2/3] Fix checkstyle --- src/main/java/seedu/address/model/person/Hours.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/Hours.java b/src/main/java/seedu/address/model/person/Hours.java index 787092fccb3..0c968af4fd0 100644 --- a/src/main/java/seedu/address/model/person/Hours.java +++ b/src/main/java/seedu/address/model/person/Hours.java @@ -11,7 +11,8 @@ public class Hours { public static final String MESSAGE_CONSTRAINTS = "Hours should be non-negative integers, with a maximum of 876,000."; - public static final String VALIDATION_REGEX = "^(?:0*([0-9]{1,5}|[1-7][0-9]{5}|8[0-6][0-9]{4}|87[0-5][0-9]{3}|876000))$"; + public static final String VALIDATION_REGEX = + "^(?:0*([0-9]{1,5}|[1-7][0-9]{5}|8[0-6][0-9]{4}|87[0-5][0-9]{3}|876000))$"; public final String value; /** @@ -36,6 +37,14 @@ public static boolean isValidHours(String test) { return test.matches(VALIDATION_REGEX); } + /** + * Removes leading zeros from the given string representation of a number. + * If the resulting string is empty after removing the zeros, it returns "0". + * + * @param hours the string representation of the number to clean, must not be null + * @return the string with leading zeros removed; if the input consists entirely of zeros, + * returns "0" + */ public static String clearLeadingZeroes(String hours) { requireNonNull(hours); String cleanedString = hours.replaceFirst("^0+", ""); From dc58c29113a8a8a7cc9150d573e1a7363ff8bc27 Mon Sep 17 00:00:00 2001 From: Ivan Jerrick Koh Yu En Date: Mon, 11 Nov 2024 22:34:04 +0800 Subject: [PATCH 3/3] Add acknowledgements in Developer Guide --- docs/DeveloperGuide.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 78a4735d415..fbab5c58553 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -16,6 +16,7 @@ * This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org). * The feature Undo, Redo and History (including the code) was reused with minimal changes from [AddressBook-Level4](https://github.com/se-edu/addressbook-level4.git) ([UG](https://se-education.org/addressbook-level4/UserGuide.html), [DG](https://se-education.org/addressbook-level4/DeveloperGuide.html)). * The feature Import was implemented using the third-party library OpenCSV. +* GitHub CoPilot was used by Ivan Jerrick Koh to write trivial test cases in test files and JavaDocs for trivial methods. --------------------------------------------------------------------------------------------------------------------