From 75a5ffcb10ba4dfa3387e6ad8dc8764b25236785 Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Wed, 9 Jan 2013 22:18:41 -0500 Subject: [PATCH] Cleanup our iterators. --- .../java/com/gmail/nossr50/config/TreasuresConfig.java | 10 ++-------- .../gmail/nossr50/config/mods/CustomArmorConfig.java | 6 +----- .../gmail/nossr50/config/mods/CustomBlocksConfig.java | 6 +----- .../gmail/nossr50/config/mods/CustomToolsConfig.java | 6 +----- .../com/gmail/nossr50/runnables/ChunkletUnloader.java | 8 ++++---- .../util/blockmeta/chunkmeta/HashChunkManager.java | 7 +++---- 6 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java index d1caf6a31..e412a7caf 100644 --- a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java +++ b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.config; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -50,10 +49,8 @@ public class TreasuresConfig extends ConfigLoader{ Map treasures = new HashMap(); ConfigurationSection treasureSection = config.getConfigurationSection("Treasures"); Set treasureConfigSet = treasureSection.getKeys(false); - Iterator iterator = treasureConfigSet.iterator(); - while (iterator.hasNext()) { - String treasureName = iterator.next(); + for (String treasureName : treasureConfigSet) { // Validate all the things! List reason = new ArrayList(); @@ -191,11 +188,8 @@ public class TreasuresConfig extends ConfigLoader{ List excavationTreasures = config.getStringList("Excavation.Treasure"); List fishingTreasures = config.getStringList("Fishing.Treasure"); - // Iterator treasureIterator = treasures.keySet().iterator(); - Iterator> treasureIterator = treasures.entrySet().iterator(); - while (treasureIterator.hasNext()) { - Entry nextEntry = treasureIterator.next(); + for (Entry nextEntry : treasures.entrySet()) { String treasureKey = nextEntry.getKey(); Treasure treasure = nextEntry.getValue(); diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java index a0d0fd530..356e55412 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.config.mods; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -54,11 +53,8 @@ public class CustomArmorConfig extends ConfigLoader{ return; Set armorConfigSet = armorSection.getKeys(false); - Iterator iterator = armorConfigSet.iterator(); - - while (iterator.hasNext()) { - String armorName = iterator.next(); + for (String armorName : armorConfigSet) { int id = config.getInt(armorType + "." + armorName + ".ID", 0); boolean repairable = config.getBoolean(armorType + "." + armorName + ".Repairable"); int repairID = config.getInt(armorType + "." + armorName + ".Repair_Material_ID", 0); diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java index ad4deceb7..0b1051efe 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlocksConfig.java @@ -1,7 +1,6 @@ package com.gmail.nossr50.config.mods; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -54,11 +53,8 @@ public class CustomBlocksConfig extends ConfigLoader { return; Set skillConfigSet = skillSection.getKeys(false); - Iterator iterator = skillConfigSet.iterator(); - - while (iterator.hasNext()) { - String blockName = iterator.next(); + for (String blockName : skillConfigSet) { int id = config.getInt(skillType + "." + blockName + ".ID", 0); byte data = (byte) config.getInt(skillType + "." + blockName + ".Data_Value", 0); int xp = config.getInt(skillType + "." + blockName + ".XP_Gain", 0); diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java index e0b3f5d7a..a32f772bb 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomToolsConfig.java @@ -2,7 +2,6 @@ package com.gmail.nossr50.config.mods; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Set; @@ -58,11 +57,8 @@ public class CustomToolsConfig extends ConfigLoader { return; Set toolConfigSet = toolSection.getKeys(false); - Iterator iterator = toolConfigSet.iterator(); - - while (iterator.hasNext()) { - String toolName = iterator.next(); + for (String toolName : toolConfigSet) { int id = config.getInt(toolType + "." + toolName + ".ID", 0); double multiplier = config.getDouble(toolType + "." + toolName + ".XP_Modifier", 1.0); boolean abilityEnabled = config.getBoolean(toolType + "." + toolName + ".Ability_Enabled", true); diff --git a/src/main/java/com/gmail/nossr50/runnables/ChunkletUnloader.java b/src/main/java/com/gmail/nossr50/runnables/ChunkletUnloader.java index d3aa49eba..7395b6181 100644 --- a/src/main/java/com/gmail/nossr50/runnables/ChunkletUnloader.java +++ b/src/main/java/com/gmail/nossr50/runnables/ChunkletUnloader.java @@ -33,8 +33,8 @@ public class ChunkletUnloader implements Runnable { @Override public void run() { - for (Iterator> it = unloadedChunks.entrySet().iterator() ; it.hasNext() ; ) { - Entry entry = it.next(); + for (Iterator> unloadedChunkIterator = unloadedChunks.entrySet().iterator() ; unloadedChunkIterator.hasNext() ; ) { + Entry entry = unloadedChunkIterator.next(); Chunk chunk = entry.getKey(); if (!chunk.isLoaded()) { @@ -46,7 +46,7 @@ public class ChunkletUnloader implements Runnable { continue; mcMMO.placeStore.unloadChunk(chunk.getX(), chunk.getZ(), chunk.getWorld()); - it.remove(); + unloadedChunkIterator.remove(); continue; } @@ -54,7 +54,7 @@ public class ChunkletUnloader implements Runnable { } else { //Just remove the entry if the chunk has been reloaded. - it.remove(); + unloadedChunkIterator.remove(); } } } diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java index 5e55934b8..96675e270 100755 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java @@ -38,12 +38,11 @@ public class HashChunkManager implements ChunkManager { public synchronized void closeAll() { for (UUID uid : regionFiles.keySet()) { HashMap worldRegions = regionFiles.get(uid); - Iterator itr = worldRegions.values().iterator(); - while (itr.hasNext()) { - mcMMOSimpleRegionFile rf = itr.next(); + for (Iterator worldRegionIterator = worldRegions.values().iterator(); worldRegionIterator.hasNext();) { + mcMMOSimpleRegionFile rf = worldRegionIterator.next(); if (rf != null) { rf.close(); - itr.remove(); + worldRegionIterator.remove(); } } }