From be155cb28c8c5662a6dd9ce9268b06869087b4a0 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sun, 16 Feb 2025 11:05:59 -0500 Subject: Organize into sub-packages --- .../main/java/com/ufund/api/ufundapi/Cupboard.java | 58 --------------- .../com/ufund/api/ufundapi/CupboardController.java | 43 ----------- .../java/com/ufund/api/ufundapi/CupboardDAO.java | 81 --------------------- .../com/ufund/api/ufundapi/CupboardFileDao.java | 27 ------- .../src/main/java/com/ufund/api/ufundapi/Need.java | 67 ----------------- .../ufundapi/controller/CupboardController.java | 47 ++++++++++++ .../com/ufund/api/ufundapi/model/Cupboard.java | 58 +++++++++++++++ .../java/com/ufund/api/ufundapi/model/Need.java | 67 +++++++++++++++++ .../api/ufundapi/persistence/CupboardDAO.java | 83 ++++++++++++++++++++++ .../api/ufundapi/persistence/CupboardFileDao.java | 29 ++++++++ 10 files changed, 284 insertions(+), 276 deletions(-) delete mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java delete mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java delete mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardDAO.java delete mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardFileDao.java delete mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/Need.java create mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java create mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java create mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java create mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardDAO.java create mode 100644 ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java (limited to 'ufund-api/src/main/java') diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java deleted file mode 100644 index 420e62e..0000000 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.ufund.api.ufundapi; - -import java.util.ArrayList; - -public class Cupboard { - ArrayList needs; - - public Cupboard() { - needs = new ArrayList(); - } - - public void addNeed(Need need) { - needs.add(need); - } - - public void createNeed(String name, double max, Need.GoalType type) { - int id = needs.size(); - Need need = new Need(name, id, max, type); - addNeed(need); - } - - public void updateID(int id) { - for (int i = 0; i < needs.size(); i++) { - needs.get(i).setID(i); - } - } - - public void removeNeed(Need need) { - needs.remove(need); - } - - public void updateNeed(Need need) { - for (int i = 0; i < needs.size(); i++) { - if (needs.get(i).getID() == need.getID()) { - needs.set(i, need); - return; - } - } - } - - public void removeNeed(String name) { - for (int i = 0; i < needs.size(); i++) { - if (needs.get(i).getName().equals(name)) { - needs.remove(i); - return; - } - } - } - - public Need[] getNeeds() { - return needs.toArray(new Need[0]); - } - - public Need getNeed(int index) { - return needs.get(index); - } - -} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java deleted file mode 100644 index 85f9933..0000000 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ufund.api.ufundapi; - -import java.util.ArrayList; - -public class CupboardController { - private ArrayList needs; - private Cupboard cupboard; - private CupboardDAO dao; - - public CupboardController(CupboardDAO dao) { - this.dao = dao; - } - - public void createNeed(String name, double max, Need.GoalType type) {; - cupboard.createNeed(name, max, type); - //dao.createNeed(need); - //implement in dao - } - - public Need[] getNeeds() { - return cupboard.getNeeds(); - //return dao.getNeeds(); - //implement in dao - } - - public Need getNeed(int index) { - return cupboard.getNeed(index); - //return dao.getNeed(); - //implement in dao - } - public void updateNeed(Need need) { - cupboard.updateNeed(need); - //dao.updateNeed(need); - //implement in dao - } - - public void deleteNeed(String name) { - cupboard.removeNeed(name); - //dao.removeNeed(name); - //implement in dao - } - -} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardDAO.java deleted file mode 100644 index 4e67cf7..0000000 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardDAO.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.ufund.api.ufundapi; - -import java.io.IOException; - -/** - * Defines the interface for Need object persistence - * - * @author Team 2B Jelly Solutions - */ -public interface CupboardDAO { - /** - * Retrieves all {@linkplain Need needs} - * - * @return An array of {@link Need need} objects, may be empty - * - * @throws IOException if an issue with underlying storage - */ - Need[] getNeeds() throws IOException; - - /** - * Finds all {@linkplain Need needs} whose name contains the given text - * - * @param containsText The text to match against - * - * @return An array of {@link Need needs} whose nemes contains the given text, may be empty - * - * @throws IOException if an issue with underlying storage - */ - Need[] findNeeds(String targetName) throws IOException; - - /** - * Retrieves a {@linkplain Need need} with the given name - * - * @param name The name of the {@link Need need} to get - * - * @return a {@link Need need} object with the matching name - *
- * null if no {@link Need need} with a matching name is found - * - * @throws IOException if an issue with underlying storage - */ - Need getNeed(int id) throws IOException; - - /** - * Creates and saves a {@linkplain Need need} - * - * @param need {@linkplain Need need} object to be created and saved - *
- * The id of the need object is automatically incremented. - * - * @return new {@link Need need} if successful, false otherwise - * - * @throws IOException if an issue with underlying storage - */ - Need createNeed(Need need) throws IOException; - - /** - * Updates and saves a {@linkplain Need need} - * - * @param {@link Need need} object to be updated and saved - * - * @return updated {@link Need need} if successful, null if - * {@link Need need} could not be found - * - * @throws IOException if underlying storage cannot be accessed - */ - Need updateNeed(Need need) throws IOException; - - /** - * Deletes a {@linkplain Need need} with the given id - * - * @param id The id of the {@link Need need} - * - * @return true if the {@link Need need} was deleted - *
- * false if need with the given id does not exist - * - * @throws IOException if underlying storage cannot be accessed - */ - boolean deleteNeed(int id) throws IOException; -} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardFileDao.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardFileDao.java deleted file mode 100644 index dda20b8..0000000 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardFileDao.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.ufund.api.ufundapi; - -import java.util.ArrayList; - -public class CupboardFileDao { - - private ArrayList needs; - private final String filePath; - - public CupboardFileDao(String filepath) { - this.filePath = filepath; - } - - public ArrayList getNeeds() { - return needs; - } - - public String getFilePath() { - return filePath; - } - - public void addNeed(Need need) { - needs.add(need); - } - - -} \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/Need.java deleted file mode 100644 index ea294bf..0000000 --- a/ufund-api/src/main/java/com/ufund/api/ufundapi/Need.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.ufund.api.ufundapi; - -public class Need { - - public enum GoalType { - MONETARY, - PHYSICAL - } - - private String name; - private int id; - private String[] filterAttributes; - final private GoalType type; - private double maxGoal; - private double current; - - public Need(String name, int id, double maxGoal, GoalType type) { - this.id = id; - this.name = name; - this.maxGoal = maxGoal; - this.type = type; - } - - public String getName() { - return name; - } - - public int getID() { - return id; - } - - public String[] getFilterAttributes() { - return filterAttributes; - } - - public GoalType getType() { - return type; - } - - public double getMaxGoal() { - return maxGoal; - } - - public double getCurrent() { - return current; - } - - public void setCurrent(double current) { - this.current = current; - } - - public void setFilterAttributes(String[] filterAttributes) { - this.filterAttributes = filterAttributes; - } - - public void setMaxGoal(double maxGoal) { - this.maxGoal = maxGoal; - } - - public void setName(String name) { - this.name = name; - } - - public void setID(int id){ - this.id = id; - } -} \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java new file mode 100644 index 0000000..dba88db --- /dev/null +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java @@ -0,0 +1,47 @@ +package com.ufund.api.ufundapi.controller; + +import com.ufund.api.ufundapi.model.Cupboard; +import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.persistence.CupboardDAO; + +import java.util.ArrayList; + +public class CupboardController { + private ArrayList needs; + private Cupboard cupboard; + private CupboardDAO dao; + + public CupboardController(CupboardDAO dao) { + this.dao = dao; + } + + public void createNeed(String name, double max, Need.GoalType type) {; + cupboard.createNeed(name, max, type); + //dao.createNeed(need); + //implement in dao + } + + public Need[] getNeeds() { + return cupboard.getNeeds(); + //return dao.getNeeds(); + //implement in dao + } + + public Need getNeed(int index) { + return cupboard.getNeed(index); + //return dao.getNeed(); + //implement in dao + } + public void updateNeed(Need need) { + cupboard.updateNeed(need); + //dao.updateNeed(need); + //implement in dao + } + + public void deleteNeed(String name) { + cupboard.removeNeed(name); + //dao.removeNeed(name); + //implement in dao + } + +} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java new file mode 100644 index 0000000..fedf04e --- /dev/null +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Cupboard.java @@ -0,0 +1,58 @@ +package com.ufund.api.ufundapi.model; + +import java.util.ArrayList; + +public class Cupboard { + ArrayList needs; + + public Cupboard() { + needs = new ArrayList<>(); + } + + public void addNeed(Need need) { + needs.add(need); + } + + public void createNeed(String name, double max, Need.GoalType type) { + int id = needs.size(); + Need need = new Need(name, id, max, type); + addNeed(need); + } + + public void updateID(int id) { + for (int i = 0; i < needs.size(); i++) { + needs.get(i).setID(i); + } + } + + public void removeNeed(Need need) { + needs.remove(need); + } + + public void updateNeed(Need need) { + for (int i = 0; i < needs.size(); i++) { + if (needs.get(i).getID() == need.getID()) { + needs.set(i, need); + return; + } + } + } + + public void removeNeed(String name) { + for (int i = 0; i < needs.size(); i++) { + if (needs.get(i).getName().equals(name)) { + needs.remove(i); + return; + } + } + } + + public Need[] getNeeds() { + return needs.toArray(new Need[0]); + } + + public Need getNeed(int index) { + return needs.get(index); + } + +} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java new file mode 100644 index 0000000..df65032 --- /dev/null +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/model/Need.java @@ -0,0 +1,67 @@ +package com.ufund.api.ufundapi.model; + +public class Need { + + public enum GoalType { + MONETARY, + PHYSICAL + } + + private String name; + private int id; + private String[] filterAttributes; + final private GoalType type; + private double maxGoal; + private double current; + + public Need(String name, int id, double maxGoal, GoalType type) { + this.id = id; + this.name = name; + this.maxGoal = maxGoal; + this.type = type; + } + + public String getName() { + return name; + } + + public int getID() { + return id; + } + + public String[] getFilterAttributes() { + return filterAttributes; + } + + public GoalType getType() { + return type; + } + + public double getMaxGoal() { + return maxGoal; + } + + public double getCurrent() { + return current; + } + + public void setCurrent(double current) { + this.current = current; + } + + public void setFilterAttributes(String[] filterAttributes) { + this.filterAttributes = filterAttributes; + } + + public void setMaxGoal(double maxGoal) { + this.maxGoal = maxGoal; + } + + public void setName(String name) { + this.name = name; + } + + public void setID(int id){ + this.id = id; + } +} \ No newline at end of file diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardDAO.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardDAO.java new file mode 100644 index 0000000..4b016fa --- /dev/null +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardDAO.java @@ -0,0 +1,83 @@ +package com.ufund.api.ufundapi.persistence; + +import com.ufund.api.ufundapi.model.Need; + +import java.io.IOException; + +/** + * Defines the interface for Need object persistence + * + * @author Team 2B Jelly Solutions + */ +public interface CupboardDAO { + /** + * Retrieves all {@linkplain Need needs} + * + * @return An array of {@link Need need} objects, may be empty + * + * @throws IOException if an issue with underlying storage + */ + Need[] getNeeds() throws IOException; + + /** + * Finds all {@linkplain Need needs} whose name contains the given text + * + * @param containsText The text to match against + * + * @return An array of {@link Need needs} whose nemes contains the given text, may be empty + * + * @throws IOException if an issue with underlying storage + */ + Need[] findNeeds(String targetName) throws IOException; + + /** + * Retrieves a {@linkplain Need need} with the given name + * + * @param name The name of the {@link Need need} to get + * + * @return a {@link Need need} object with the matching name + *
+ * null if no {@link Need need} with a matching name is found + * + * @throws IOException if an issue with underlying storage + */ + Need getNeed(int id) throws IOException; + + /** + * Creates and saves a {@linkplain Need need} + * + * @param need {@linkplain Need need} object to be created and saved + *
+ * The id of the need object is automatically incremented. + * + * @return new {@link Need need} if successful, false otherwise + * + * @throws IOException if an issue with underlying storage + */ + Need createNeed(Need need) throws IOException; + + /** + * Updates and saves a {@linkplain Need need} + * + * @param {@link Need need} object to be updated and saved + * + * @return updated {@link Need need} if successful, null if + * {@link Need need} could not be found + * + * @throws IOException if underlying storage cannot be accessed + */ + Need updateNeed(Need need) throws IOException; + + /** + * Deletes a {@linkplain Need need} with the given id + * + * @param id The id of the {@link Need need} + * + * @return true if the {@link Need need} was deleted + *
+ * false if need with the given id does not exist + * + * @throws IOException if underlying storage cannot be accessed + */ + boolean deleteNeed(int id) throws IOException; +} diff --git a/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java new file mode 100644 index 0000000..f2c70f9 --- /dev/null +++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDao.java @@ -0,0 +1,29 @@ +package com.ufund.api.ufundapi.persistence; + +import com.ufund.api.ufundapi.model.Need; + +import java.util.ArrayList; + +public class CupboardFileDao { + + private ArrayList needs; + private final String filePath; + + public CupboardFileDao(String filepath) { + this.filePath = filepath; + } + + public ArrayList getNeeds() { + return needs; + } + + public String getFilePath() { + return filePath; + } + + public void addNeed(Need need) { + needs.add(need); + } + + +} \ No newline at end of file -- cgit v1.2.3