Skip to content

Commit 3114db4

Browse files
committed
Added a getIniMap() method and test
1 parent e268b4e commit 3114db4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/com/nikhaldimann/inieditor/IniEditor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,19 @@ public Map< String, String > getSectionMap(String section) {
286286
return null;
287287
}
288288

289+
/**
290+
* Returns a nested map of the entire Ini file for simple reading.
291+
*
292+
* @return HashMap of section/option/value for entire ini file
293+
*/
294+
public Map<String , Map<String, String>> getIniMap() {
295+
Map<String, Map<String, String>> iniMap = new HashMap<String, Map<String, String>>();
296+
for(String section: sectionNames()) {
297+
iniMap.put(section, getSectionMap(section));
298+
}
299+
return iniMap;
300+
}
301+
289302
/**
290303
* Sets the value of an option in a section, if the option exist, otherwise
291304
* adds the option to the section. Trims white space from the start and the

test/com/nikhaldimann/inieditor/IniEditorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ public void testGetSectionMap() {
150150
assertEquals(i.getSectionMap("common"), new HashMap<String, String>());
151151
}
152152

153+
public void testGetIniMap() {
154+
IniEditor i = new IniEditor();
155+
Map<String, Map<String, String>> temp = new HashMap<String, Map<String, String>>();
156+
assertEquals(i.getIniMap(), temp);
157+
i.addSection("test");
158+
temp.put("test", new HashMap<String, String>());
159+
assertEquals(i.getIniMap(), temp);
160+
i.set("test", "hallo", "bike");
161+
temp.get("test").put("hallo", "bike");
162+
assertEquals(i.getIniMap(), temp);
163+
}
164+
153165
/**
154166
* Setting options with illegal names.
155167
*/

0 commit comments

Comments
 (0)