From 279b43f1f5a601415cc052bfef5a9b92449c0923 Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 10 Apr 2023 23:25:19 +0800 Subject: [PATCH 1/3] Add asserts to PetList --- .../java/seedu/pettracker/data/PetList.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/seedu/pettracker/data/PetList.java b/src/main/java/seedu/pettracker/data/PetList.java index a15da6136d..6fcdca0d27 100644 --- a/src/main/java/seedu/pettracker/data/PetList.java +++ b/src/main/java/seedu/pettracker/data/PetList.java @@ -31,7 +31,7 @@ public static void addPet(String petName) throws EmptyPetNameException, Duplicat throw new EmptyPetNameException(); } - if(petName.trim().contains("|")) { + if (petName.trim().contains("|")) { throw new InvalidPetNameException(); } @@ -45,6 +45,7 @@ public static void addPet(String petName) throws EmptyPetNameException, Duplicat } private static int find(String petName) { + assert petList != null; for (int i = 0; i < petList.size(); i++) { if (petList.get(i).getPetName().equals(petName)) { return i; @@ -54,6 +55,7 @@ private static int find(String petName) { } private static Pet get(int index) { + assert index > -1; return petList.get(index); } @@ -63,8 +65,10 @@ private static Pet get(int index) { * @param petName Name of pet to edit * @param statName Name of stat to add * @param statValue New stat Value - * @throws NumberFormatException When stat is Age/Weight and is not a number - * @throws NonPositiveIntegerException When stat is Age/Weight and is non-positive + * @throws NumberFormatException When stat is Age/Weight and is not a + * number + * @throws NonPositiveIntegerException When stat is Age/Weight and is + * non-positive * @throws InvalidStatException When stat is not Type/Age/Weight * @throws PetNotFoundException When Pet is not in PetList */ @@ -138,6 +142,7 @@ public static void list() { /** * Return the number of pets in the PetList. + * * @return number of pets in the list. */ public static int getNumberOfPets() { @@ -145,13 +150,16 @@ public static int getNumberOfPets() { } /** - * Edit pet stats of a pet in the PetList to change the previous value to a new value + * Edit pet stats of a pet in the PetList to change the previous value to a new + * value * * @param petName Name of pet to edit * @param stat Name of stat to edit * @param newValue New stat Value - * @throws NonPositiveIntegerException When stat is Age/Weight and is non-positive - * @throws NumberFormatException When stat is Age/Weight and is not a number + * @throws NonPositiveIntegerException When stat is Age/Weight and is + * non-positive + * @throws NumberFormatException When stat is Age/Weight and is not a + * number * @throws InvalidStatException When stat is not Type/Age/Weight * @throws PetNotFoundException When Pet is not in PetList */ @@ -163,20 +171,20 @@ public static void editPetStats(String petName, String stat, String newValue) } Pet petToEdit = PetList.get(index); switch (stat.toLowerCase()) { - case "name": - petToEdit.setPetName(newValue); - break; - case "type": - petToEdit.setPetType(newValue); - break; - case "age": - petToEdit.setAge(newValue); - break; - case "weight": - petToEdit.setWeight(newValue); - break; - default: - throw new InvalidStatException(); + case "name": + petToEdit.setPetName(newValue); + break; + case "type": + petToEdit.setPetType(newValue); + break; + case "age": + petToEdit.setAge(newValue); + break; + case "weight": + petToEdit.setWeight(newValue); + break; + default: + throw new InvalidStatException(); } } From 3404b9c52935e94a0aab262c2b1fbe634c3c819a Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 10 Apr 2023 23:26:18 +0800 Subject: [PATCH 2/3] Fix Merge Conflict --- src/main/java/seedu/pettracker/data/PetList.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/seedu/pettracker/data/PetList.java b/src/main/java/seedu/pettracker/data/PetList.java index 039ee55a47..1e1974ed6f 100644 --- a/src/main/java/seedu/pettracker/data/PetList.java +++ b/src/main/java/seedu/pettracker/data/PetList.java @@ -149,11 +149,8 @@ public static void list() { /** * Return the number of pets in the PetList. -<<<<<<< HEAD * -======= * ->>>>>>> f5cbc4466ea465cc05fe8762622808983fa553b4 * @return number of pets in the list. */ public static int getNumberOfPets() { From 45219b4f59c4cab720cdc4dbe9b0ed709801b67c Mon Sep 17 00:00:00 2001 From: Marek Date: Mon, 10 Apr 2023 23:29:31 +0800 Subject: [PATCH 3/3] Fix Switch Indentation --- .../java/seedu/pettracker/data/PetList.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/pettracker/data/PetList.java b/src/main/java/seedu/pettracker/data/PetList.java index 1e1974ed6f..99f79b6cd6 100644 --- a/src/main/java/seedu/pettracker/data/PetList.java +++ b/src/main/java/seedu/pettracker/data/PetList.java @@ -185,20 +185,20 @@ public static void editPetStats(String petName, String stat, String newValue) } Pet petToEdit = PetList.get(index); switch (stat.toLowerCase()) { - case "name": - petToEdit.setPetName(newValue); - break; - case "type": - petToEdit.setPetType(newValue); - break; - case "age": - petToEdit.setAge(newValue); - break; - case "weight": - petToEdit.setWeight(newValue); - break; - default: - throw new InvalidStatException(); + case "name": + petToEdit.setPetName(newValue); + break; + case "type": + petToEdit.setPetType(newValue); + break; + case "age": + petToEdit.setAge(newValue); + break; + case "weight": + petToEdit.setWeight(newValue); + break; + default: + throw new InvalidStatException(); } }