mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-05 23:33:36 +00:00
jdb: Add countDocuments method
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
fancylibVersion=37
|
||||
fancysitulaVersion=0.0.13
|
||||
jdbVersion=1.0.1
|
||||
jdbVersion=1.0.2
|
||||
plugintestsVersion=1.0.0
|
||||
org.gradle.parallel=false
|
||||
org.gradle.caching=true
|
||||
@@ -95,6 +95,26 @@ public class JDB {
|
||||
return documents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of documents in the specified directory path.
|
||||
*
|
||||
* @param path the relative directory path
|
||||
* @return the number of documents in the directory
|
||||
*/
|
||||
public int countDocuments(@NotNull String path) {
|
||||
File directory = new File(baseDirectory, path);
|
||||
if (!directory.exists()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return files.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given value as a document at the specified path.
|
||||
*
|
||||
|
||||
@@ -110,6 +110,23 @@ public class JDBTest {
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountDocuments() throws IOException {
|
||||
// Prepare
|
||||
String basePath = "./test_files/";
|
||||
JDB jdb = new JDB(basePath);
|
||||
String path = "test_files";
|
||||
jdb.set(path + "/obj1", "Test message 1");
|
||||
jdb.set(path + "/obj2", "Test message 2");
|
||||
jdb.set(path + "/obj3", "Test message 3");
|
||||
|
||||
// Act
|
||||
int count = jdb.countDocuments(path);
|
||||
|
||||
// Assert
|
||||
assertEquals(3, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetNewObject() throws IOException {
|
||||
// Prepare
|
||||
|
||||
Reference in New Issue
Block a user