diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/api')
6 files changed, 31 insertions, 404 deletions
diff --git a/src/main/java/gtPlusPlus/api/objects/data/AutoMap.java b/src/main/java/gtPlusPlus/api/objects/data/AutoMap.java deleted file mode 100644 index 4de2e9ab78..0000000000 --- a/src/main/java/gtPlusPlus/api/objects/data/AutoMap.java +++ /dev/null @@ -1,356 +0,0 @@ -package gtPlusPlus.api.objects.data; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Queue; -import java.util.Set; - -public class AutoMap<V> implements Iterable<V>, Cloneable, Serializable, Collection<V>, Queue<V>, List<V> { - - /** - * The Internal Map - */ - protected final Map<Integer, V> mInternalMap; - - protected final Map<String, Integer> mInternalNameMap; - - /** - * The Internal ID - */ - private int mInternalID = 0; - - private static final long serialVersionUID = 3771412318075131790L; - - public AutoMap() { - this(new LinkedHashMap<>()); - } - - public Map<Integer, V> getMap() { - return mInternalMap; - } - - public AutoMap(Map<Integer, V> defaultMapType) { - mInternalMap = defaultMapType; - mInternalNameMap = new LinkedHashMap<>(); - } - - /** - * Generates an AutoMap from the List. - * - * @param aList - Data to be inserted into the AutoMap. - */ - public AutoMap(List<V> aList) { - mInternalMap = new LinkedHashMap<>(); - mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && !aList.isEmpty()) { - for (V obj : aList) { - add(obj); - } - } - } - - /** - * Generates an AutoMap from a Set. - * - * @param aList - Data to be inserted into the AutoMap. - */ - public AutoMap(Set<V> aList) { - mInternalMap = new LinkedHashMap<>(); - mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && !aList.isEmpty()) { - for (V obj : aList) { - add(obj); - } - } - } - - /** - * Generates an AutoMap from a Collection. - * - * @param aList - Data to be inserted into the AutoMap. - */ - public AutoMap(Collection<V> aList) { - mInternalMap = new LinkedHashMap<>(); - mInternalNameMap = new LinkedHashMap<>(); - if (aList != null && !aList.isEmpty()) { - for (V obj : aList) { - add(obj); - } - } - } - - /** - * Generates an AutoMap from a Array. - * - * @param aArray - Data to be inserted into the AutoMap. - */ - public AutoMap(V[] aArray) { - mInternalMap = new LinkedHashMap<>(); - mInternalNameMap = new LinkedHashMap<>(); - if (aArray != null) { - for (V obj : aArray) { - add(obj); - } - } - } - - @Override - public Iterator<V> iterator() { - return values().iterator(); - } - - public synchronized boolean setValue(V object) { - int mOriginalID = this.mInternalID; - put(object); - return this.mInternalMap.get(mOriginalID) - .equals(object) || mOriginalID > this.mInternalID; - } - - public synchronized V put(V object) { - return set(object); - } - - @Override - public synchronized boolean add(V object) { - return set(object) != null; - } - - public synchronized V set(V object) { - if (object == null) { - return null; - } - mInternalNameMap.put("" + object.hashCode(), (mInternalID + 1)); - return mInternalMap.put(mInternalID++, object); - } - - @Override - public synchronized V get(int id) { - return mInternalMap.get(id); - } - - public synchronized Collection<V> values() { - return mInternalMap.values(); - } - - @Override - public synchronized int size() { - return mInternalMap.size(); - } - - public synchronized int hashCode() { - return mInternalMap.hashCode(); - } - - public synchronized boolean containsKey(int key) { - return mInternalMap.containsKey(key); - } - - public synchronized boolean containsValue(V value) { - return mInternalMap.containsValue(value); - } - - @Override - public synchronized boolean isEmpty() { - return mInternalMap.isEmpty(); - } - - @Override - public synchronized void clear() { - this.mInternalID = 0; - this.mInternalMap.clear(); - this.mInternalNameMap.clear(); - } - - @Override - @SuppressWarnings("unchecked") - public V[] toArray() { - V[] toR = (V[]) java.lang.reflect.Array.newInstance( - mInternalMap.get(0) - .getClass(), - mInternalMap.size()); - for (int i = 0; i < mInternalMap.size(); i++) { - toR[i] = mInternalMap.get(i); - } - return toR; - } - - public final synchronized int getInternalID() { - return mInternalID; - } - - @Override - public final synchronized boolean remove(Object value) { - value.getClass(); - if (this.mInternalMap.containsValue(value)) { - return this.mInternalMap.remove(mInternalNameMap.get("" + value.hashCode()), value); - } - return false; - } - - @Override - public boolean contains(Object o) { - for (V g : this.mInternalMap.values()) { - if (g.equals(o)) { - return true; - } - } - return false; - } - - @SuppressWarnings("unchecked") - @Override - public <V> V[] toArray(V[] a) { - return (V[]) toArray(); - } - - @Override - public boolean containsAll(Collection<?> c) { - boolean aTrue = true; - for (Object g : c) { - if (!this.contains(g)) { - aTrue = false; - } - } - return aTrue; - } - - @Override - public boolean addAll(Collection<? extends V> c) { - boolean aTrue = true; - for (V g : c) { - if (!this.add(g)) { - aTrue = false; - } - } - return aTrue; - } - - @Override - public boolean removeAll(Collection<?> c) { - boolean aTrue = true; - for (Object g : c) { - if (!this.remove(g)) { - aTrue = false; - } - } - return aTrue; - } - - @Override - public boolean retainAll(Collection<?> c) { - AutoMap<?> aTempAllocation = new AutoMap<>(); - boolean aTrue = false; - aTempAllocation = this; - aTempAllocation.removeAll(c); - aTempAllocation.clear(); - aTrue = aTempAllocation.isEmpty(); - aTempAllocation.clear(); - return aTrue; - } - - @Override - public boolean offer(V e) { - return add(e); - } - - @Override - public V remove() { - V y = this.get(0); - if (remove(y)) return y; - else return null; - } - - @Override - public V poll() { - if (this.mInternalMap.isEmpty()) { - return null; - } - return remove(); - } - - @Override - public V element() { - if (this.mInternalMap.isEmpty()) { - return null; - } - return this.get(0); - } - - @Override - public V peek() { - return element(); - } - - @Override - public boolean addAll(int index, Collection<? extends V> c) { - for (V y : c) { - add(y); - } - return true; - } - - @Override - public V set(int index, V element) { - return mInternalMap.put(index, element); - } - - @Override - public void add(int index, V element) { - add(element); - } - - @Override - public V remove(int index) { - V h = mInternalMap.get(index); - set(index, null); - return h; - } - - @Override - public int indexOf(Object o) { - int aCount = 0; - for (V of : mInternalMap.values()) { - if (of != o) { - aCount++; - } else { - return aCount; - } - } - return -1; - } - - @Override - public int lastIndexOf(Object o) { - // TODO - return indexOf(o); - } - - @Override - public ListIterator<V> listIterator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public ListIterator<V> listIterator(int index) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List<V> subList(int fromIndex, int toIndex) { - AutoMap<V> aNewSubList = new AutoMap<>(); - for (int slot = fromIndex; slot <= toIndex; slot++) { - V obj = mInternalMap.get(slot); - if (obj != null) { - aNewSubList.put(obj); - } - } - return aNewSubList; - } -} diff --git a/src/main/java/gtPlusPlus/api/objects/data/weakref/WeakAutoMap.java b/src/main/java/gtPlusPlus/api/objects/data/weakref/WeakAutoMap.java deleted file mode 100644 index 199d20e06a..0000000000 --- a/src/main/java/gtPlusPlus/api/objects/data/weakref/WeakAutoMap.java +++ /dev/null @@ -1,14 +0,0 @@ -package gtPlusPlus.api.objects.data.weakref; - -import java.util.WeakHashMap; - -import gtPlusPlus.api.objects.data.AutoMap; - -public class WeakAutoMap<T> extends AutoMap<T> { - - private static final long serialVersionUID = 8328345351801363386L; - - public WeakAutoMap() { - super(new WeakHashMap<>()); - } -} diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java index 3853f61793..047b5dbeaf 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -1,6 +1,7 @@ package gtPlusPlus.api.objects.minecraft; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashSet; import java.util.Set; @@ -10,7 +11,6 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gtPlusPlus.api.objects.data.AutoMap; public class BlockPos implements Serializable { @@ -151,14 +151,14 @@ public class BlockPos implements Serializable { return new BlockPos(this.xPos, this.yPos, this.zPos - 1, this.dim); } - public AutoMap<BlockPos> getSurroundingBlocks() { - AutoMap<BlockPos> sides = new AutoMap<>(); - sides.put(getUp()); - sides.put(getDown()); - sides.put(getXPos()); - sides.put(getXNeg()); - sides.put(getZPos()); - sides.put(getZNeg()); + public ArrayList<BlockPos> getSurroundingBlocks() { + ArrayList<BlockPos> sides = new ArrayList<>(); + sides.add(getUp()); + sides.add(getDown()); + sides.add(getXPos()); + sides.add(getXNeg()); + sides.add(getZPos()); + sides.add(getZNeg()); return sides; } @@ -195,7 +195,7 @@ public class BlockPos implements Serializable { * @return - Does this block have a neighbour that is the same? */ public boolean hasSimilarNeighbour(boolean strict) { - for (BlockPos g : getSurroundingBlocks().values()) { + for (BlockPos g : getSurroundingBlocks()) { if (getBlockAtPos(g) == getBlockAtPos()) { if (!strict) { return true; @@ -209,7 +209,7 @@ public class BlockPos implements Serializable { return false; } - public AutoMap<BlockPos> getSimilarNeighbour() { + public ArrayList<BlockPos> getSimilarNeighbour() { return getSimilarNeighbour(false); } @@ -217,15 +217,15 @@ public class BlockPos implements Serializable { * @param strict - Does this check Meta Data? * @return - Does this block have a neighbour that is the same? */ - public AutoMap<BlockPos> getSimilarNeighbour(boolean strict) { - AutoMap<BlockPos> sides = new AutoMap<>(); - for (BlockPos g : getSurroundingBlocks().values()) { + public ArrayList<BlockPos> getSimilarNeighbour(boolean strict) { + ArrayList<BlockPos> sides = new ArrayList<>(); + for (BlockPos g : getSurroundingBlocks()) { if (getBlockAtPos(g) == getBlockAtPos()) { if (!strict) { - sides.put(g); + sides.add(g); } else { if (getMetaAtPos() == getMetaAtPos(g)) { - sides.put(g); + sides.add(g); } } } @@ -234,12 +234,8 @@ public class BlockPos implements Serializable { } public Set<BlockPos> getValidNeighboursAndSelf() { - AutoMap<BlockPos> h = getSimilarNeighbour(true); - h.put(this); - Set<BlockPos> result = new HashSet<>(); - for (BlockPos f : h.values()) { - result.add(f); - } - return result; + ArrayList<BlockPos> h = getSimilarNeighbour(true); + h.add(this); + return new HashSet<>(h); } } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java b/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java index 5620b76895..fe3c6da840 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/CubicObject.java @@ -1,8 +1,8 @@ package gtPlusPlus.api.objects.minecraft; -import net.minecraftforge.common.util.ForgeDirection; +import java.util.ArrayList; -import gtPlusPlus.api.objects.data.AutoMap; +import net.minecraftforge.common.util.ForgeDirection; public class CubicObject<T> { @@ -15,7 +15,7 @@ public class CubicObject<T> { public final T UP; public final T DOWN; - public CubicObject(AutoMap<T> aDataSet) { + public CubicObject(ArrayList<T> aDataSet) { this(aDataSet.get(0), aDataSet.get(1), aDataSet.get(2), aDataSet.get(3), aDataSet.get(4), aDataSet.get(5)); } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/ItemPackage.java b/src/main/java/gtPlusPlus/api/objects/minecraft/ItemPackage.java index e03fbc3c12..a858f5a295 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/ItemPackage.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/ItemPackage.java @@ -12,9 +12,9 @@ public abstract class ItemPackage implements RunnableWithInfo<String> { public ItemPackage(boolean hasExtraLateRun) { // Register for late run - CompatHandler.mObjectsToRunInPostInit.put(this); + CompatHandler.mObjectsToRunInPostInit.add(this); if (hasExtraLateRun) { - CompatHandler.mObjectsToRunInOnLoadComplete.put(this); + CompatHandler.mObjectsToRunInOnLoadComplete.add(this); } init(); } diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java index 4da6ef3a1f..6852c93f05 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/ShapedRecipe.java @@ -1,12 +1,13 @@ package gtPlusPlus.api.objects.minecraft; +import java.util.ArrayList; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.ShapedOreRecipe; import gregtech.api.interfaces.IRecipeMutableAccess; import gtPlusPlus.api.objects.Logger; -import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.util.minecraft.ItemUtils; @@ -76,7 +77,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { } // Build a Pair for each slot - AutoMap<Pair<Character, Object>> aRecipePairs = new AutoMap<>(); + ArrayList<Pair<Character, Object>> aRecipePairs = new ArrayList<>(); int aCharSlot = 0; int aMemSlot = 0; int aInfoSlot = 0; @@ -91,7 +92,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { } mInfo = ((ItemStack) stack).getDisplayName(); } - aRecipePairs.put(new Pair<>(CHARS.charAt(aCharSlot), stack)); + aRecipePairs.add(new Pair<>(CHARS.charAt(aCharSlot), stack)); Logger.RECIPE( "Storing '" + CHARS.charAt(aCharSlot) + "' with an object of type " @@ -103,7 +104,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { aCharSlot++; aLoggingInfo[aInfoSlot++] = mInfo; } else { - aRecipePairs.put(new Pair<>(' ', (ItemStack) null)); + aRecipePairs.add(new Pair<>(' ', (ItemStack) null)); Logger.RECIPE("Storing ' ' with an object of type null"); aChar[aMemSlot++] = ' '; aLoggingInfo[aInfoSlot++] = "Empty"; @@ -155,7 +156,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { } mInfo = ((ItemStack) stack).getDisplayName(); } - aRecipePairs.put(new Pair<>(CHARS.charAt(aCharSlot), stack)); + aRecipePairs.add(new Pair<>(CHARS.charAt(aCharSlot), stack)); Logger.RECIPE( "Registering Pair of '" + CHARS.charAt(aCharSlot) + "' and a " @@ -211,7 +212,7 @@ public class ShapedRecipe implements IRecipeMutableAccess { Logger.RECIPE("+ = + = + = +"); for (int r = 0; r < 9; r++) { if (aChar[r] != ' ') { - Logger.RECIPE("" + aChar[r] + " : " + aLoggingInfo[r]); + Logger.RECIPE(aChar[r] + " : " + aLoggingInfo[r]); } } |