aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java')
-rw-r--r--ufund-api/src/main/java/com/ufund/api/ufundapi/persistence/CupboardFileDAO.java31
1 files changed, 11 insertions, 20 deletions
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
index 521acae..7efda83 100644
--- 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
@@ -1,15 +1,16 @@
package com.ufund.api.ufundapi.persistence;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.ufund.api.ufundapi.model.Need;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ufund.api.ufundapi.model.Need;
+
@Component
public class CupboardFileDAO implements CupboardDAO {
@@ -52,31 +53,20 @@ public class CupboardFileDAO implements CupboardDAO {
}
/**
- * Return an array of the needs
- *
- * @return An array of all the needs
- */
- private Need[] getNeedsArray() {
- return needs.values().toArray(Need[]::new);
- }
-
- /**
* Saves the needs to json
*
- * @return True if the save was successful, false otherwise
* @throws IOException If there was an IO issue saving the file
*/
- private boolean save() throws IOException {
- Need[] needArray = getNeedsArray();
+ private void save() throws IOException {
+ Need[] needArray = needs.values().toArray(Need[]::new);
objectMapper.writeValue(new File(filename), needArray);
- return true;
}
@Override
public Need[] getNeeds() {
synchronized (needs) {
- return getNeedsArray();
+ return needs.values().toArray(Need[]::new);
}
}
@@ -117,7 +107,8 @@ public class CupboardFileDAO implements CupboardDAO {
synchronized (needs) {
if (needs.containsKey(id)) {
needs.remove(id);
- return save();
+ save();
+ return true;
} else {
return false;
}