Skip to content

Commit 025397e

Browse files
committed
#372 Use "path" internally in YamlFileReader where appropriate (not "key")
1 parent 809462c commit 025397e

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/main/java/ch/jalu/configme/resource/YamlFileReader.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,29 @@ public boolean contains(@NotNull String path) {
9999
if (root == null) {
100100
return Collections.emptySet();
101101
}
102-
Set<String> allKeys = new LinkedHashSet<>();
103-
collectKeysIntoSet("", root, allKeys, onlyLeafNodes);
104-
return allKeys;
102+
Set<String> allPaths = new LinkedHashSet<>();
103+
collectPathsIntoSet("", root, allPaths, onlyLeafNodes);
104+
return allPaths;
105105
}
106106

107107
/**
108-
* Recursively collects keys from maps into the given set.
108+
* Recursively collects keys from maps and adds them as paths to {@code result}.
109109
*
110-
* @param path the path of the given map
110+
* @param path the path to the given map
111111
* @param map the map to process recursively
112-
* @param result set to save keys to
112+
* @param result set to save paths to
113113
* @param onlyLeafNodes whether only leaf nodes should be added to the result set
114114
*/
115-
private static void collectKeysIntoSet(@NotNull String path, @NotNull Map<String, Object> map,
116-
@NotNull Set<String> result, boolean onlyLeafNodes) {
115+
private static void collectPathsIntoSet(@NotNull String path, @NotNull Map<String, Object> map,
116+
@NotNull Set<String> result, boolean onlyLeafNodes) {
117117
for (Map.Entry<String, Object> entry : map.entrySet()) {
118118
String childPath = PathUtils.concat(path, entry.getKey());
119119
if (!onlyLeafNodes || isLeafValue(entry.getValue())) {
120120
result.add(childPath);
121121
}
122122

123123
if (entry.getValue() instanceof Map) {
124-
collectKeysIntoSet(childPath, (Map) entry.getValue(), result, onlyLeafNodes);
124+
collectPathsIntoSet(childPath, (Map) entry.getValue(), result, onlyLeafNodes);
125125
}
126126
}
127127
}
@@ -159,6 +159,9 @@ private static boolean isLeafValue(@Nullable Object o) {
159159
return new MapNormalizer().normalizeMap(map);
160160
}
161161

162+
/**
163+
* @return the file this reader read from
164+
*/
162165
protected final @NotNull Path getPath() {
163166
return path;
164167
}

0 commit comments

Comments
 (0)