aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java44
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java40
2 files changed, 82 insertions, 2 deletions
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
index 6b200d3..a11e7ab 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/Cupboard.java
@@ -4,4 +4,48 @@ import java.util.ArrayList;
public class Cupboard {
ArrayList<Need> needs;
+
+ public Cupboard() {
+ needs = new ArrayList<Need>();
+ }
+
+ public void addNeed(Need need) {
+ needs.add(need);
+ }
+
+ public void createNeed(String name, double max, Need.GoalType type) {
+ Need need = new Need(name, 0, max, type);
+ addNeed(need);
+ }
+
+ 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
index 6b200d3..85f9933 100644
--- a/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java
+++ b/ufund-api/src/main/java/com/ufund/api/ufundapi/CupboardController.java
@@ -2,6 +2,42 @@ package com.ufund.api.ufundapi;
import java.util.ArrayList;
-public class Cupboard {
- ArrayList<Need> needs;
+public class CupboardController {
+ private ArrayList<Need> 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
+ }
+
}