From ee114f82ec2f92bcfd31a50ea2b6d5e8528bac51 Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 22 Feb 2015 13:30:16 -0800 Subject: [PATCH] Tidy Configuration.java --- .../forestry/core/config/Configuration.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/forestry/core/config/Configuration.java b/src/main/java/forestry/core/config/Configuration.java index 7ecd5dca5..787fcf569 100755 --- a/src/main/java/forestry/core/config/Configuration.java +++ b/src/main/java/forestry/core/config/Configuration.java @@ -17,6 +17,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TreeMap; @@ -28,8 +29,8 @@ import forestry.core.proxy.Proxies; public class Configuration { private final String newLine; - private final ArrayList purge = new ArrayList(); - private final TreeMap> categorized = new TreeMap>(); + private final List purge = new ArrayList(); + private final TreeMap> categorized = new TreeMap>(); public Configuration() { newLine = System.getProperty("line.separator"); @@ -38,7 +39,7 @@ public class Configuration { public void addPurge(String key) { purge.add(key); } - + public Property get(String key, String category, boolean defaultVal) { Property existing = getExisting(key, category); @@ -171,7 +172,10 @@ public class Configuration { try { if (file.getParentFile() != null) { - file.getParentFile().mkdirs(); + boolean createdDir = file.getParentFile().mkdirs(); + if (!createdDir) { + return; + } } if (!file.exists()) { @@ -229,17 +233,20 @@ public class Configuration { } public void save() { - for (Map.Entry> entry : categorized.entrySet()) { + for (Map.Entry> entry : categorized.entrySet()) { saveFile(getCategoryFile(entry.getKey()), entry.getValue()); } } - private void saveFile(File file, ArrayList properties) { + private void saveFile(File file, List properties) { try { if (file.getParentFile() != null) { - file.getParentFile().mkdirs(); + boolean createdDir = file.getParentFile().mkdirs(); + if (!createdDir) { + return; + } } if (!file.exists() && !file.createNewFile()) { @@ -262,11 +269,10 @@ public class Configuration { writer.write("# backpacks.conf\t-\t Contains custom configurations for backpacks" + newLine); writer.write("# pipes.conf\t\t-\t Configures item id for the apiarist's pipe" + newLine); writer.write("# gamemodes/\t\t-\t Configures available gamemodes"); - TreeMap> subsectioned = getSubsectioned(properties); + TreeMap> subsectioned = getSubsectioned(properties); - for (Map.Entry> entry : subsectioned.entrySet()) { - writer.write(newLine + newLine + "#####################" + newLine + "# " + entry.getKey().toUpperCase() + newLine + "#####################" - + newLine); + for (Map.Entry> entry : subsectioned.entrySet()) { + writer.write(newLine + newLine + "#####################" + newLine + "# " + entry.getKey().toUpperCase() + newLine + "#####################" + newLine); for (Property property : entry.getValue()) { if (purge.contains(property.key)) { @@ -287,8 +293,8 @@ public class Configuration { } - private TreeMap> getSubsectioned(ArrayList properties) { - TreeMap> subsectioned = new TreeMap>(); + private TreeMap> getSubsectioned(List properties) { + TreeMap> subsectioned = new TreeMap>(); for (Property property : properties) { String subsection = property.key.split("\\.")[0];