Removed seome unnecessary usages of hash codes as hash map keys.

This commit is contained in:
Robin Kupper
2011-11-09 13:33:44 +01:00
parent c0dcf4ea1a
commit 067dff06d1
2 changed files with 10 additions and 9 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
/.settings /.settings
/bin /bin
/release /release
/agitar

View File

@@ -39,7 +39,7 @@ public class Consumer extends TimerTask
private final Set<Integer> hiddenPlayers, hiddenBlocks; private final Set<Integer> hiddenPlayers, hiddenBlocks;
private final Set<String> failedPlayers = new HashSet<String>(); private final Set<String> failedPlayers = new HashSet<String>();
private final LogBlock logblock; private final LogBlock logblock;
private final Map<Integer, Integer> players = new HashMap<Integer, Integer>(); private final Map<String, Integer> playerIds = new HashMap<String, Integer>();
private final Lock lock = new ReentrantLock(); private final Lock lock = new ReentrantLock();
Consumer(LogBlock logblock) { Consumer(LogBlock logblock) {
@@ -263,7 +263,7 @@ public class Consumer extends TimerTask
if (r == null) if (r == null)
continue; continue;
for (final String player : r.getPlayers()) for (final String player : r.getPlayers())
if (!players.containsKey(player.hashCode())) if (!playerIds.containsKey(player))
if (!addPlayer(state, player)) { if (!addPlayer(state, player)) {
if (!failedPlayers.contains(player)) { if (!failedPlayers.contains(player)) {
failedPlayers.add(player); failedPlayers.add(player);
@@ -298,7 +298,7 @@ public class Consumer extends TimerTask
public void writeToFile() throws FileNotFoundException { public void writeToFile() throws FileNotFoundException {
final long time = System.currentTimeMillis(); final long time = System.currentTimeMillis();
final Set<Integer> insertedPlayers = new HashSet<Integer>(); final Set<String> insertedPlayers = new HashSet<String>();
int counter = 0; int counter = 0;
new File("plugins/LogBlock/import/").mkdirs(); new File("plugins/LogBlock/import/").mkdirs();
PrintWriter writer = new PrintWriter(new File("plugins/LogBlock/import/queue-" + time + "-0.sql")); PrintWriter writer = new PrintWriter(new File("plugins/LogBlock/import/queue-" + time + "-0.sql"));
@@ -307,9 +307,9 @@ public class Consumer extends TimerTask
if (r == null) if (r == null)
continue; continue;
for (final String player : r.getPlayers()) for (final String player : r.getPlayers())
if (!players.containsKey(player.hashCode()) && !insertedPlayers.contains(player.hashCode())) { if (!playerIds.containsKey(player) && !insertedPlayers.contains(player)) {
writer.println("INSERT IGNORE INTO `lb-players` (playername) VALUES ('" + player + "');"); writer.println("INSERT IGNORE INTO `lb-players` (playername) VALUES ('" + player + "');");
insertedPlayers.add(player.hashCode()); insertedPlayers.add(player);
} }
for (final String insert : r.getInserts()) for (final String insert : r.getInserts())
writer.println(insert); writer.println(insert);
@@ -340,9 +340,9 @@ public class Consumer extends TimerTask
state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('" + playerName + "')"); state.execute("INSERT IGNORE INTO `lb-players` (playername) VALUES ('" + playerName + "')");
final ResultSet rs = state.executeQuery("SELECT playerid FROM `lb-players` WHERE playername = '" + playerName + "'"); final ResultSet rs = state.executeQuery("SELECT playerid FROM `lb-players` WHERE playername = '" + playerName + "'");
if (rs.next()) if (rs.next())
players.put(playerName.hashCode(), rs.getInt(1)); playerIds.put(playerName, rs.getInt(1));
rs.close(); rs.close();
return players.containsKey(playerName.hashCode()); return playerIds.containsKey(playerName);
} }
private void queueBlock(String playerName, Location loc, int typeBefore, int typeAfter, byte data, String signtext, ChestAccess ca) { private void queueBlock(String playerName, Location loc, int typeBefore, int typeAfter, byte data, String signtext, ChestAccess ca) {
@@ -357,7 +357,7 @@ public class Consumer extends TimerTask
private String playerID(String playerName) { private String playerID(String playerName) {
if (playerName == null) if (playerName == null)
return "NULL"; return "NULL";
final Integer id = players.get(playerName.hashCode()); final Integer id = playerIds.get(playerName);
if (id != null) if (id != null)
return id.toString(); return id.toString();
return "(SELECT playerid FROM `lb-players` WHERE playername = '" + playerName + "')"; return "(SELECT playerid FROM `lb-players` WHERE playername = '" + playerName + "')";