Skip to content

Commit c2a9e22

Browse files
committed
feat(section): Add ConfigureSection#asMap function
1 parent 251dd20 commit c2a9e22

File tree

19 files changed

+119
-91
lines changed

19 files changed

+119
-91
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>easyconfiguration-parent</artifactId>
77
<groupId>cc.carm.lib</groupId>
8-
<version>4.0.8</version>
8+
<version>4.0.9</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<properties>

core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSection.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public interface ConfigureSection {
4848
return (parent().isRoot() ? "" : parent().fullPath() + pathSeparator()) + path();
4949
}
5050

51-
5251
/**
5352
* Get the path separator for the section.
5453
*
@@ -143,6 +142,17 @@ default Map<String, Object> values() {
143142
return getValues(false);
144143
}
145144

145+
/**
146+
* Get this section as a map.
147+
* <p>
148+
* In this map, child {@link ConfigureSection}s will also be represented as {@link Map}s.
149+
*
150+
* @return Map of data values contained within this Section.
151+
*/
152+
@NotNull
153+
@UnmodifiableView
154+
Map<String, Object> asMap();
155+
146156
/**
147157
* Create a stream of all values in this section.
148158
*
@@ -153,7 +163,7 @@ default Stream<Map.Entry<String, Object>> stream() {
153163
}
154164

155165
/**
156-
* Iterates over all keys in this section.
166+
* Iterates over all key-values in this section (include child sections)
157167
*
158168
* @param action The action to apply to each key.
159169
*/

core/src/main/java/cc/carm/lib/configuration/source/section/ConfigureSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public boolean isExpired(long parsedTime) {
107107
return section().getKeys(deep);
108108
}
109109

110+
@Override
111+
public @NotNull @UnmodifiableView Map<String, Object> asMap() {
112+
return section().asMap();
113+
}
114+
110115
@Override
111116
public @NotNull ConfigureSection createSection(@NotNull String path, @NotNull Map<?, ?> data) {
112117
return section().createSection(path, data);

demo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>easyconfiguration-parent</artifactId>
77
<groupId>cc.carm.lib</groupId>
8-
<version>4.0.8</version>
8+
<version>4.0.9</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<properties>

features/commentable/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>cc.carm.lib</groupId>
88
<artifactId>easyconfiguration-parent</artifactId>
9-
<version>4.0.8</version>
9+
<version>4.0.9</version>
1010
<relativePath>../../pom.xml</relativePath>
1111
</parent>
1212
<properties>

features/file/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>cc.carm.lib</groupId>
88
<artifactId>easyconfiguration-parent</artifactId>
9-
<version>4.0.8</version>
9+
<version>4.0.9</version>
1010
<relativePath>../../pom.xml</relativePath>
1111
</parent>
1212
<properties>

features/section/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>cc.carm.lib</groupId>
88
<artifactId>easyconfiguration-parent</artifactId>
9-
<version>4.0.8</version>
9+
<version>4.0.9</version>
1010
<relativePath>../../pom.xml</relativePath>
1111
</parent>
1212
<properties>

features/section/src/main/java/cc/carm/lib/configuration/source/section/AbstractMapSection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ public int size(boolean deep) {
7575
return deep ? getKeys(true).size() : this.data.size();
7676
}
7777

78+
@Override
7879
@UnmodifiableView
79-
public @NotNull Map<String, Object> rawMap() {
80+
public @NotNull Map<String, Object> asMap() {
8081
Map<String, Object> output = new LinkedHashMap<>();
8182
for (Map.Entry<String, Object> entry : this.data.entrySet()) {
8283
if (entry.getValue() instanceof AbstractMapSection<?>) {
83-
output.put(entry.getKey(), ((AbstractMapSection<?>) entry.getValue()).rawMap());
84+
output.put(entry.getKey(), ((AbstractMapSection<?>) entry.getValue()).asMap());
8485
} else if (entry.getValue() instanceof List<?>) {
8586
List<Object> list = new ArrayList<>();
8687
for (Object obj : (List<?>) entry.getValue()) {
8788
if (obj instanceof AbstractMapSection<?>) {
88-
list.add(((AbstractMapSection<?>) obj).rawMap());
89+
list.add(((AbstractMapSection<?>) obj).asMap());
8990
} else {
9091
list.add(obj);
9192
}

0 commit comments

Comments
 (0)