From 8040e139196a303860cd06bbe8135ce4d743bc48 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 13 Aug 2015 22:39:29 +1000 Subject: [PATCH] Don't use keyset on ConcurrentHashMap --- pom.xml | 2 +- .../com/intellectualcrafters/plot/PS.java | 13 +++++---- .../plot/database/SQLManager.java | 27 ++++++++++--------- .../com/plotsquared/sponge/SpongeMain.java | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 1a48c396a..68832ea1b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.0.14 + 3.0.15 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index dfda0d901..58e9c7bc1 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -11,8 +11,6 @@ import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -952,7 +950,7 @@ public class PS { @Deprecated public ArrayList sortPlotsByWorld(Collection plots) { ArrayList newPlots = new ArrayList<>(); - ArrayList worlds = new ArrayList<>(this.plots.keySet()); + ArrayList worlds = new ArrayList<>(this.plotworlds.keySet()); HashSet set = new HashSet<>(plots); Collections.sort(worlds); for (String world : worlds) { @@ -1034,7 +1032,7 @@ public class PS { * @return A String array of the plot world names */ public String[] getPlotWorldsString() { - final Set strings = plots.keySet(); + final Set strings = plotworlds.keySet(); return strings.toArray(new String[strings.size()]); } @@ -1103,9 +1101,10 @@ public class PS { */ public Set getPlots(final UUID uuid) { final ArrayList myplots = new ArrayList<>(); - for (final String world : plots.keySet()) { - if (isPlotWorld(world)) { - for (final Plot plot : plots.get(world).values()) { + for (Entry> entry : plots.entrySet()) { + if (isPlotWorld(entry.getKey())) { + for (Entry entry2 : entry.getValue().entrySet()) { + Plot plot = entry2.getValue(); if (plot.hasOwner()) { if (PlotHandler.isOwner(plot, uuid)) { myplots.add(plot); diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index e2782b891..ce7679b4d 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -234,9 +234,9 @@ public class SQLManager implements AbstractDB { PreparedStatement stmt = null; UniqueStatement task = null; UniqueStatement lastTask = null; - ArrayList keys = new ArrayList<>(plotTasks.keySet()); - for (int i = 0; i < keys.size(); i++) { - Plot plot = keys.get(i); +// ArrayList>> keys = new ArrayList<>(plotTasks.entrySet()); + for (Entry> entry : plotTasks.entrySet()) { + Plot plot = entry.getKey(); if (plotTasks.get(plot).size() == 0) { plotTasks.remove(plot); continue; @@ -271,14 +271,13 @@ public class SQLManager implements AbstractDB { PreparedStatement stmt = null; UniqueStatement task = null; UniqueStatement lastTask = null; - ArrayList keys = new ArrayList<>(clusterTasks.keySet()); - for (int i = 0; i < keys.size(); i++) { - PlotCluster plot = keys.get(i); - if (clusterTasks.get(plot).size() == 0) { - clusterTasks.remove(plot); + for (Entry> entry : clusterTasks.entrySet()) { + PlotCluster cluster = entry.getKey(); + if (clusterTasks.get(cluster).size() == 0) { + clusterTasks.remove(cluster); continue; } - task = clusterTasks.get(plot).remove(); + task = clusterTasks.get(cluster).remove(); count++; if (task != null) { if (task._method == null || !task._method.equals(method)) { @@ -1212,7 +1211,7 @@ public class SQLManager implements AbstractDB { */ @Override public ConcurrentHashMap> getPlots() { - final ConcurrentHashMap> newplots = new ConcurrentHashMap(); + final ConcurrentHashMap> newplots = new ConcurrentHashMap>(); final HashMap plots = new HashMap<>(); Statement stmt = null; try { @@ -1436,11 +1435,12 @@ public class SQLManager implements AbstractDB { } stmt.close(); } - if (plots.keySet().size() > 0) { + if (plots.entrySet().size() > 0) { this.createEmptySettings(new ArrayList(plots.keySet()), null); } boolean invalidPlot = false; - for (final String worldname : noExist.keySet()) { + for (Entry entry : noExist.entrySet()) { + String worldname = entry.getKey(); invalidPlot = true; PS.debug("&c[WARNING] Found " + noExist.get(worldname) + " plots in DB for non existant world; '" + worldname + "'."); } @@ -2167,7 +2167,8 @@ public class SQLManager implements AbstractDB { newClusters.get(world).add(c); } boolean invalidPlot = false; - for (final String w : noExist.keySet()) { + for (Entry entry : noExist.entrySet()) { + String w = entry.getKey(); invalidPlot = true; PS.debug("&c[WARNING] Found " + noExist.get(w) + " clusters in DB for non existant world; '" + w + "'."); } diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index e43607a0b..c337f00bf 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -327,7 +327,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { public void registerBlocks() { blockMap = new BlockState[256][]; - blockMapReverse = new ConcurrentHashMap(); + blockMapReverse = new HashMap(); HashMap states = new HashMap<>(); PS.get().copyFile("ids.txt", "config");