Skip to content

Commit

Permalink
get all objects as string
Browse files Browse the repository at this point in the history
  • Loading branch information
nurmuhammad committed Mar 17, 2017
1 parent 54140f5 commit 5a263cd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main/java/com/rvc/jsondb/JsonDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @author Nurmuhammad
Expand Down Expand Up @@ -122,14 +124,31 @@ public BaseObject get(String collection, String id) {
}
}

public String getContent(String collection, String id) {
if (!contains(collection, id)) {
return null;
}

try {
Path path = Paths.get(this.path.toString(), collection, id + EXT);
return new String(Files.readAllBytes(path));
} catch (IOException e) {
throw new JsonDBException("I/O exception.", e);
}
}

public List<BaseObject> list(String collection) {
List<BaseObject> list = new ArrayList<>();
ids(collection).forEach(id -> {
list.add(get(collection, id));
});
ids(collection).forEach(id -> list.add(get(collection, id)));
return list;
}

public Map<String, String> map(String collection) {
Map<String, String> map = new LinkedHashMap<>();
ids(collection).forEach(id -> map.put(id, getContent(collection, id)));
return map;
}

public List<String> ids(String collection) {
List<String> list = new ArrayList<>();
Path directoryPath = Paths.get(this.path.toString(), collection);
Expand Down

0 comments on commit 5a263cd

Please sign in to comment.