Skip to content

Commit 29d9e29

Browse files
author
SORJAS
committed
Replaced HashMap with LinkedHashMap to preserve order in file handling methods.
1 parent ea4f016 commit 29d9e29

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/main/java/io/github/filelize/FilelizerSingle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public <T> Map<String, T> findAll(Class<T> valueType) {
3737
try {
3838
return fileHandler.readFileMap(fullPath, valueType);
3939
} catch (NoSuchFileException e) {
40-
return new HashMap<>();
40+
return new LinkedHashMap<>();
4141
} catch (IOException e) {
4242
log.error("Error occurred when trying to get " + fullPath, e);
43-
return new HashMap<>();
43+
return new LinkedHashMap<>();
4444
}
4545
}
4646

src/main/java/io/github/filelize/file/FileHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.nio.file.NoSuchFileException;
1414
import java.nio.file.Path;
1515
import java.nio.file.Paths;
16-
import java.util.HashMap;
16+
import java.util.LinkedHashMap;
1717
import java.util.Map;
1818

1919
import static io.github.filelize.FilelizeUtil.getFilelizeId;
@@ -41,15 +41,15 @@ public <T> T readFile(String fullPath, Class<T> valueType) throws IOException {
4141
public <T> Map<String, T> readFileMap(String fullPath, Class<T> valueType) throws IOException {
4242
try {
4343
JsonNode json = objectMapper.readTree(getNewBufferedReader(fullPath));
44-
JavaType mapType = objectMapper.getTypeFactory().constructMapType(Map.class, String.class, valueType);
44+
JavaType mapType = objectMapper.getTypeFactory().constructMapType(LinkedHashMap.class, String.class, valueType);
4545
return objectMapper.readValue(json.traverse(), mapType);
4646
} catch (NoSuchFileException e) {
47-
return new HashMap<>();
47+
return new LinkedHashMap<>();
4848
}
4949
}
5050

5151
public <T> Map<String, Object> readFiles(String folderPath, Class<T> valueType) throws IOException {
52-
Map<String, Object> content = new HashMap<>();
52+
Map<String, Object> content = new LinkedHashMap<>();
5353
File folder = new File(folderPath);
5454
File[] files = folder.listFiles();
5555
if (files != null) {
@@ -77,7 +77,7 @@ public void delete(String fullPath) throws IOException {
7777
try {
7878
Files.delete(Path.of(fullPath));
7979
} catch (NoSuchFileException e) {
80-
log.warn("No such file: " + fullPath);
80+
log.warn("No such file: {}", fullPath);
8181
}
8282
}
8383
}

0 commit comments

Comments
 (0)