From 9830d9d326f54b8354045024dbf48f0d59209af7 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 22 Jan 2012 01:23:41 -0800 Subject: [PATCH] Revert "Using trove collections for most internal stuff, using array access in BlockType and ItemType" This reverts commit 410ac65c6a4eb9b22b4d81c2678b3841265da704. This has been causing compatibility issues with Spout. I haven't been ble to reproduce, but until somebody figures out why, this gets to go --- pom.xml | 10 ---- .../java/com/sk89q/worldedit/EditSession.java | 10 ++-- .../java/com/sk89q/worldedit/WorldEdit.java | 7 ++- .../com/sk89q/worldedit/blocks/BaseItem.java | 8 +-- .../com/sk89q/worldedit/blocks/BlockType.java | 53 ++++++++----------- .../com/sk89q/worldedit/blocks/ItemType.java | 32 +++++------ .../sk89q/worldedit/bukkit/BukkitWorld.java | 16 ++---- 7 files changed, 48 insertions(+), 88 deletions(-) diff --git a/pom.xml b/pom.xml index 738a7b43e..ce4918d75 100644 --- a/pom.xml +++ b/pom.xml @@ -90,14 +90,6 @@ spoutapi dev-SNAPSHOT - - - net.sf.trove4j - trove4j - 3.0.2 - jar - compile - @@ -181,10 +173,8 @@ com.sk89q:jchronic - net.sf.trove4j:trove4j - true diff --git a/src/main/java/com/sk89q/worldedit/EditSession.java b/src/main/java/com/sk89q/worldedit/EditSession.java index 45b53d8f5..b91e8899b 100644 --- a/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/src/main/java/com/sk89q/worldedit/EditSession.java @@ -39,8 +39,6 @@ import com.sk89q.worldedit.expression.ExpressionException; import com.sk89q.worldedit.expression.runtime.RValue; import com.sk89q.worldedit.masks.Mask; import com.sk89q.worldedit.patterns.*; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; /** * This class can wrap all block editing operations into one "edit session" that @@ -120,7 +118,7 @@ public class EditSession { /** * List of missing blocks; */ - private TIntSet missingBlocks = new TIntHashSet(); + private Set missingBlocks = new HashSet(); /** * Mask to cover operations. @@ -662,9 +660,9 @@ public class EditSession { * * @return */ - public TIntSet popMissingBlocks() { - TIntSet missingBlocks = this.missingBlocks; - this.missingBlocks = new TIntHashSet(); + public Set popMissingBlocks() { + Set missingBlocks = this.missingBlocks; + this.missingBlocks = new HashSet(); return missingBlocks; } diff --git a/src/main/java/com/sk89q/worldedit/WorldEdit.java b/src/main/java/com/sk89q/worldedit/WorldEdit.java index 14b7947ed..0c92943ef 100644 --- a/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -49,7 +49,6 @@ import com.sk89q.worldedit.scripting.*; import com.sk89q.worldedit.tools.*; import com.sk89q.worldedit.masks.*; import com.sk89q.worldedit.patterns.*; -import gnu.trove.set.TIntSet; /** * This class is the main entry point for WorldEdit. All events are routed @@ -975,7 +974,7 @@ public class WorldEdit { blockBag.flushChanges(); } - TIntSet missingBlocks = editSession.popMissingBlocks(); + Set missingBlocks = editSession.popMissingBlocks(); if (missingBlocks.size() > 0) { StringBuilder str = new StringBuilder(); @@ -983,12 +982,12 @@ public class WorldEdit { int size = missingBlocks.size(); int i = 0; - for (int id : missingBlocks.toArray()) { + for (Integer id : missingBlocks) { BlockType type = BlockType.fromID(id); str.append(type != null ? type.getName() + " (" + id + ")" - : id); + : id.toString()); ++i; diff --git a/src/main/java/com/sk89q/worldedit/blocks/BaseItem.java b/src/main/java/com/sk89q/worldedit/blocks/BaseItem.java index b6578d315..5494ee991 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BaseItem.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BaseItem.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.blocks; -import gnu.trove.map.TIntIntMap; -import gnu.trove.map.hash.TIntIntHashMap; +import java.util.HashMap; +import java.util.Map; /** * Represents an item. @@ -37,7 +37,7 @@ public class BaseItem { */ private short damage; - private TIntIntMap enchantments = new TIntIntHashMap(); + private Map enchantments = new HashMap(); /** * Construct the object. @@ -88,7 +88,7 @@ public class BaseItem { this.damage = damage; } - public TIntIntMap getEnchantments() { + public Map getEnchantments() { return enchantments; } } diff --git a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java index bc5d912f9..253d9f0c8 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/BlockType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/BlockType.java @@ -19,15 +19,13 @@ package com.sk89q.worldedit.blocks; -import java.util.Arrays; +import java.util.HashSet; import java.util.Map; import java.util.HashMap; +import java.util.EnumSet; import java.util.Map.Entry; import java.util.Random; -import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; +import java.util.Set; import com.sk89q.util.StringUtil; import com.sk89q.worldedit.PlayerDirection; @@ -165,7 +163,7 @@ public enum BlockType { /** * Stores a map of the IDs for fast access. */ - private static BlockType[] ids = new BlockType[256]; + private static final Map ids = new HashMap(); /** * Stores a map of the names for fast access. */ @@ -176,13 +174,8 @@ public enum BlockType { private final String[] lookupKeys; static { - for (BlockType type : values()) { - if (ids.length > type.id) { - ids[type.id] = type; - } else { - ids = Arrays.copyOf(ids, type.id + 10); - ids[type.id] = type; - } + for (BlockType type : EnumSet.allOf(BlockType.class)) { + ids.put(type.id, type); for (String key : type.lookupKeys) { lookup.put(key, type); } @@ -221,11 +214,7 @@ public enum BlockType { * @return */ public static BlockType fromID(int id) { - if (id < 0 || id >= ids.length) { - return null; - } else { - return ids[id]; - } + return ids.get(id); } /** @@ -298,7 +287,7 @@ public enum BlockType { /** * HashSet for shouldPlaceLast. */ - private static final TIntSet shouldPlaceLast = new TIntHashSet(); + private static final Set shouldPlaceLast = new HashSet(); static { shouldPlaceLast.add(BlockID.SAPLING); shouldPlaceLast.add(BlockID.BED); @@ -359,7 +348,7 @@ public enum BlockType { /** * HashSet for shouldPlaceLast. */ - private static final TIntSet shouldPlaceFinal = new TIntHashSet(); + private static final Set shouldPlaceFinal = new HashSet(); static { shouldPlaceFinal.add(BlockID.SIGN_POST); shouldPlaceFinal.add(BlockID.WOODEN_DOOR); @@ -387,7 +376,7 @@ public enum BlockType { /** * HashSet for canPassThrough. */ - private static final TIntSet canPassThrough = new TIntHashSet(); + private static final Set canPassThrough = new HashSet(); static { canPassThrough.add(BlockID.AIR); canPassThrough.add(BlockID.WATER); @@ -451,7 +440,7 @@ public enum BlockType { /** * HashSet for usesData. */ - private static final TIntSet usesData = new TIntHashSet(); + private static final Set usesData = new HashSet(); static { usesData.add(BlockID.SAPLING); usesData.add(BlockID.WATER); @@ -543,7 +532,7 @@ public enum BlockType { /** * HashSet for isContainerBlock. */ - private static final TIntSet isContainerBlock = new TIntHashSet(); + private static final Set isContainerBlock = new HashSet(); static { isContainerBlock.add(BlockID.DISPENSER); isContainerBlock.add(BlockID.FURNACE); @@ -574,7 +563,7 @@ public enum BlockType { /** * HashSet for isRedstoneBlock. */ - private static final TIntSet isRedstoneBlock = new TIntHashSet(); + private static final Set isRedstoneBlock = new HashSet(); static { isRedstoneBlock.add(BlockID.POWERED_RAIL); isRedstoneBlock.add(BlockID.DETECTOR_RAIL); @@ -618,7 +607,7 @@ public enum BlockType { /** * HashSet for canTransferRedstone. */ - private static final TIntSet canTransferRedstone = new TIntHashSet(); + private static final Set canTransferRedstone = new HashSet(); static { canTransferRedstone.add(BlockID.REDSTONE_TORCH_OFF); canTransferRedstone.add(BlockID.REDSTONE_TORCH_ON); @@ -651,7 +640,7 @@ public enum BlockType { /** * HashSet for isRedstoneSource. */ - private static final TIntSet isRedstoneSource = new TIntHashSet(); + private static final Set isRedstoneSource = new HashSet(); static { isRedstoneSource.add(BlockID.DETECTOR_RAIL); isRedstoneSource.add(BlockID.REDSTONE_TORCH_OFF); @@ -684,7 +673,7 @@ public enum BlockType { /** * HashSet for isRailBlock. */ - private static final TIntSet isRailBlock = new TIntHashSet(); + private static final Set isRailBlock = new HashSet(); static { isRailBlock.add(BlockID.POWERED_RAIL); isRailBlock.add(BlockID.DETECTOR_RAIL); @@ -713,7 +702,7 @@ public enum BlockType { /** * HashSet for isNaturalBlock. */ - private static final TIntSet isNaturalTerrainBlock = new TIntHashSet(); + private static final Set isNaturalTerrainBlock = new HashSet(); static { isNaturalTerrainBlock.add(BlockID.STONE); isNaturalTerrainBlock.add(BlockID.GRASS); @@ -762,7 +751,7 @@ public enum BlockType { /** * HashSet for emitsLight. */ - private static final TIntSet emitsLight = new TIntHashSet(); + private static final Set emitsLight = new HashSet(); static { emitsLight.add(BlockID.LAVA); emitsLight.add(BlockID.STATIONARY_LAVA); @@ -796,7 +785,7 @@ public enum BlockType { /** * HashSet for isTranslucent. */ - private static final TIntSet isTranslucent = new TIntHashSet(); + private static final Set isTranslucent = new HashSet(); static { isTranslucent.add(BlockID.AIR); isTranslucent.add(BlockID.SAPLING); @@ -1255,8 +1244,8 @@ public enum BlockType { } } - private static final TIntObjectMap dataAttachments = new TIntObjectHashMap(); - private static final TIntObjectMap nonDataAttachments = new TIntObjectHashMap(); + private static final Map dataAttachments = new HashMap(); + private static final Map nonDataAttachments = new HashMap(); static { nonDataAttachments.put(BlockID.SAPLING, PlayerDirection.DOWN); nonDataAttachments.put(BlockID.POWERED_RAIL, PlayerDirection.DOWN); diff --git a/src/main/java/com/sk89q/worldedit/blocks/ItemType.java b/src/main/java/com/sk89q/worldedit/blocks/ItemType.java index 7129044b4..5cd04dffb 100644 --- a/src/main/java/com/sk89q/worldedit/blocks/ItemType.java +++ b/src/main/java/com/sk89q/worldedit/blocks/ItemType.java @@ -19,14 +19,15 @@ package com.sk89q.worldedit.blocks; -import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.HashMap; +import java.util.EnumSet; import java.util.Map.Entry; +import java.util.Set; import com.sk89q.util.StringUtil; -import gnu.trove.set.TIntSet; -import gnu.trove.set.hash.TIntHashSet; /** * ItemType types. @@ -307,7 +308,7 @@ public enum ItemType { /** * Stores a map of the IDs for fast access. */ - private static ItemType[] ids = new ItemType[3200]; + private static final Map ids = new HashMap(); /** * Stores a map of the names for fast access. */ @@ -318,13 +319,8 @@ public enum ItemType { private final String[] lookupKeys; static { - for (ItemType type : values()) { - if (ids.length > type.id) { - ids[type.id] = type; - } else { - ids = Arrays.copyOf(ids, type.id + 10); - ids[type.id] = type; - } + for (ItemType type : EnumSet.allOf(ItemType.class)) { + ids.put(type.id, type); for (String key : type.lookupKeys) { lookup.put(key, type); } @@ -363,11 +359,7 @@ public enum ItemType { * @return */ public static ItemType fromID(int id) { - if (id < 0 || id >= ids.length) { - return null; - } else { - return ids[id]; - } + return ids.get(id); } /** @@ -377,7 +369,7 @@ public enum ItemType { * @return */ public static String toName(int id) { - ItemType type = fromID(id); + ItemType type = ids.get(id); if (type != null) { return type.getName(); } else { @@ -395,7 +387,7 @@ public enum ItemType { if (id == 0) { return "Hand"; } - ItemType type = fromID(id); + ItemType type = ids.get(id); if (type != null) { return type.getName(); } else { @@ -478,7 +470,7 @@ public enum ItemType { return lookupKeys; } - private static final TIntSet shouldNotStack = new TIntHashSet(); + private static final Set shouldNotStack = new HashSet(); static { shouldNotStack.add(ItemID.IRON_SHOVEL); shouldNotStack.add(ItemID.IRON_PICK); @@ -568,7 +560,7 @@ public enum ItemType { return shouldNotStack.contains(id); } - private static final TIntSet usesDamageValue = new TIntHashSet(); + private static final Set usesDamageValue = new HashSet(); static { usesDamageValue.add(BlockID.SAPLING); //usesDamageValue.add(BlockID.WATER); diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index b4e012d95..d98fa8cc0 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.bukkit; import java.util.HashMap; import java.util.Map; -import gnu.trove.procedure.TIntIntProcedure; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Furnace; @@ -684,20 +683,13 @@ public class BukkitWorld extends LocalWorld { } if (contents[i] != null) { - final ItemStack toAdd = new ItemStack(contents[i].getType(), + ItemStack toAdd = new ItemStack(contents[i].getType(), contents[i].getAmount(), contents[i].getDamage()); try { - contents[i].getEnchantments().forEachEntry(new TIntIntProcedure() { - @Override - public boolean execute(int key, int value) { - Enchantment ench = Enchantment.getById(key); - if (ench != null) { - toAdd.addEnchantment(ench, value); - } - return true; - } - }); + for (Map.Entry entry : contents[i].getEnchantments().entrySet()) { + toAdd.addEnchantment(Enchantment.getById(entry.getKey()), entry.getValue()); + } } catch (Throwable ignore) {} inven.setItem(i, toAdd); } else {