I am working with the Spigot API (for Minecraft plugins). When saving configurations, there is an option to save a List < Map< ?, ? > >. So that data structure would look like:
Item
- Key : Value
- Key : Value
- Key : Value
I want to be able to save configuration information related to specific users. What I want is a data structure that looks like this:
Users
- User1
- Setting 1 : Value
- Setting 2 : Value
- User2
- Setting 1 : Value
- Setting 2 : Value
- User3
- Setting 1 : Value
- Setting 2 : Value
The code that I have been writing is utterly disgusting. I've made it more readable by removing the wildcards, but here it is:
List<Map<String, Map<String, String>>> users = new ArrayList<Map<String, Map<String, String>>>();
Map<String, Map<String, String>> justin = new HashMap<String, Map<String, String>>() {{}};
for (Map<String, String> config : justin.values()) {
config.put("key1", "value1");
config.put("key2", "value2");
config.put("key3", "value3");
}
Map<String, Map<String, String>> not_justin = new HashMap<String, Map<String, String>>() {{}};
for (Map<String, String> config : not_justin.values()) {
config.put("key1", "value1");
config.put("key2", "value2");
config.put("key3", "value3");
}
users.add(justin);
users.add(not_justin);
}
When I try to print this, I recieve this as an output:
[{}, {}]
I have tried iterating through everything, and still don't get any actual values. So my two questions are
a) is there a simpler way to do this that I'm forgetting about
b) if there isn't, why isn't my code printing?
Thank you,
Justin