From 50b0285c15aee27e3a94d474ea063cdf8dda2900 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 23 Jul 2014 14:20:47 -0500 Subject: [PATCH] Some refactoring. --- me/cache/EnergyGridCache.java | 46 ++++--------------- me/cache/PathGridCache.java | 8 ++-- me/cache/SecurityCache.java | 4 +- me/cache/TickManagerCache.java | 8 ++-- me/cluster/MBCalculator.java | 2 +- .../CraftingCPUCalculator.java | 4 +- .../implementations/CraftingCPUCluster.java | 6 +-- .../implementations/QuantumCalculator.java | 2 +- .../implementations/QuantumCluster.java | 4 +- .../SpatialPylonCalculator.java | 2 +- .../implementations/SpatialPylonCluster.java | 6 +-- 11 files changed, 32 insertions(+), 60 deletions(-) diff --git a/me/cache/EnergyGridCache.java b/me/cache/EnergyGridCache.java index e140842c..d235ddff 100644 --- a/me/cache/EnergyGridCache.java +++ b/me/cache/EnergyGridCache.java @@ -58,11 +58,6 @@ public class EnergyGridCache implements IEnergyGrid double tickDrainPerTick = 0; double tickInjectionPerTick = 0; - // Double[] totalDrainPastTicks = new Double[] { 0.0, 0.0, 0.0, 0.0, 0.0, - // 0.0, 0.0, 0.0, 0.0, 0.0 }; - // Double[] totalInjectionPastTicks = new Double[] { 0.0, 0.0, 0.0, 0.0, - // 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - /** * power status */ @@ -76,13 +71,15 @@ public class EnergyGridCache implements IEnergyGrid double extra = 0; IAEPowerStorage lastProvider; - Set providers = new LinkedHashSet(); + final Set providers = new LinkedHashSet(); IAEPowerStorage lastRequestor; - Set requesters = new LinkedHashSet(); + final Set requesters = new LinkedHashSet(); - public TreeSet interests = new TreeSet(); - private HashMap watchers = new HashMap(); + final public TreeSet interests = new TreeSet(); + final private HashMap watchers = new HashMap(); + + final private Set localSeen = new HashSet(); private double buffer() { @@ -111,7 +108,7 @@ public class EnergyGridCache implements IEnergyGrid return lastProvider; } - Multiset gproviders = HashMultiset.create(); + final Multiset gproviders = HashMultiset.create(); final IGrid myGrid; PathGridCache pgc; @@ -259,8 +256,6 @@ public class EnergyGridCache implements IEnergyGrid return Math.max( 0.0, amt - buffer() ); } - Set localSeen = new HashSet(); - @Override public double extractAEPower(double amt, Actionable mode, PowerMultiplier pm) { @@ -388,15 +383,6 @@ public class EnergyGridCache implements IEnergyGrid tickDrainPerTick = 0; tickInjectionPerTick = 0; - // next tick is here... - // for (int x = 0; x < totalDrainPastTicks.length - 1; x++) - // totalDrainPastTicks[x + 1] = totalDrainPastTicks[x]; - // totalDrainPastTicks[0] = 0.0; - - // for (int x = 0; x < totalInjectionPastTicks.length - 1; x++) - // totalInjectionPastTicks[x + 1] = totalInjectionPastTicks[x]; - // totalInjectionPastTicks[0] = 0.0; - // power information. double drained = extractAEPower( getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); boolean currentlyHasPower = drained >= drainPerTick - 0.001; @@ -417,8 +403,6 @@ public class EnergyGridCache implements IEnergyGrid publicPowerState( false, myGrid ); availableTicksSinceUpdate++; - // if ( extra > 32 ) - // injectPower( 0.0, Actionable.MODULATE ); } private void publicPowerState(boolean newState, IGrid grid) @@ -559,25 +543,13 @@ public class EnergyGridCache implements IEnergyGrid @Override public double getAvgPowerUsage() { - return avgDrainPerTick;/* - * double out = 0; - * - * for (double x : totalDrainPastTicks) out += x; - * - * return out / totalDrainPastTicks.length; - */ + return avgDrainPerTick; } @Override public double getAvgPowerInjection() { - return avgInjectionPerTick;/* - * double out = 0; - * - * for (double x : totalInjectionPastTicks) out += x; - * - * return out / totalInjectionPastTicks.length; - */ + return avgInjectionPerTick; } @Override diff --git a/me/cache/PathGridCache.java b/me/cache/PathGridCache.java index b38e610e..e8790adf 100644 --- a/me/cache/PathGridCache.java +++ b/me/cache/PathGridCache.java @@ -39,16 +39,16 @@ public class PathGridCache implements IPathingGrid boolean updateNetwork = true; boolean booting = false; - LinkedList active = new LinkedList(); + final LinkedList active = new LinkedList(); ControllerState controllerState = ControllerState.NO_CONTROLLER; int instance = Integer.MIN_VALUE; int ticksUntilReady = 20; - Set controllers = new HashSet(); - Set requireChannels = new HashSet(); - Set blockDense = new HashSet(); + final Set controllers = new HashSet(); + final Set requireChannels = new HashSet(); + final Set blockDense = new HashSet(); final IGrid myGrid; private HashSet semiOpen = new HashSet(); diff --git a/me/cache/SecurityCache.java b/me/cache/SecurityCache.java index 3ef0d991..fa3af5ca 100644 --- a/me/cache/SecurityCache.java +++ b/me/cache/SecurityCache.java @@ -22,8 +22,8 @@ import appeng.me.GridNode; public class SecurityCache implements IGridCache, ISecurityGrid { - private List securityProvider = new ArrayList(); - private HashMap> playerPerms = new HashMap>(); + final private List securityProvider = new ArrayList(); + final private HashMap> playerPerms = new HashMap>(); public SecurityCache(IGrid g) { myGrid = g; diff --git a/me/cache/TickManagerCache.java b/me/cache/TickManagerCache.java index 18ff54fe..2f54d49f 100644 --- a/me/cache/TickManagerCache.java +++ b/me/cache/TickManagerCache.java @@ -24,12 +24,12 @@ public class TickManagerCache implements ITickManager myGrid = g; } - HashMap alertable = new HashMap(); + final HashMap alertable = new HashMap(); - HashMap sleeping = new HashMap(); - HashMap awake = new HashMap(); + final HashMap sleeping = new HashMap(); + final HashMap awake = new HashMap(); - PriorityQueue upcomingTicks = new PriorityQueue(); + final PriorityQueue upcomingTicks = new PriorityQueue(); public long getCurrentTick() { diff --git a/me/cluster/MBCalculator.java b/me/cluster/MBCalculator.java index 1151c0fd..8ac2d541 100644 --- a/me/cluster/MBCalculator.java +++ b/me/cluster/MBCalculator.java @@ -10,7 +10,7 @@ import appeng.util.Platform; public abstract class MBCalculator { - private IAEMultiBlock target; + final private IAEMultiBlock target; public MBCalculator(IAEMultiBlock t) { target = t; diff --git a/me/cluster/implementations/CraftingCPUCalculator.java b/me/cluster/implementations/CraftingCPUCalculator.java index 9d619d0e..063053fd 100644 --- a/me/cluster/implementations/CraftingCPUCalculator.java +++ b/me/cluster/implementations/CraftingCPUCalculator.java @@ -17,8 +17,8 @@ import appeng.tile.crafting.TileCraftingTile; public class CraftingCPUCalculator extends MBCalculator { - - TileCraftingTile tqb; + + final TileCraftingTile tqb; public CraftingCPUCalculator(IAEMultiBlock t) { super( t ); diff --git a/me/cluster/implementations/CraftingCPUCluster.java b/me/cluster/implementations/CraftingCPUCluster.java index 78d7ca8e..3580f3ec 100644 --- a/me/cluster/implementations/CraftingCPUCluster.java +++ b/me/cluster/implementations/CraftingCPUCluster.java @@ -75,9 +75,9 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU IItemList waitingFor = AEApi.instance().storage().createItemList(); // instance sate - private LinkedList tiles = new LinkedList(); - private LinkedList storage = new LinkedList(); - private LinkedList status = new LinkedList(); + final private LinkedList tiles = new LinkedList(); + final private LinkedList storage = new LinkedList(); + final private LinkedList status = new LinkedList(); long availableStorage = 0; public ICraftingLink myLastLink; diff --git a/me/cluster/implementations/QuantumCalculator.java b/me/cluster/implementations/QuantumCalculator.java index 7c730424..baa0597b 100644 --- a/me/cluster/implementations/QuantumCalculator.java +++ b/me/cluster/implementations/QuantumCalculator.java @@ -13,7 +13,7 @@ import appeng.util.Platform; public class QuantumCalculator extends MBCalculator { - TileQuantumBridge tqb; + final private TileQuantumBridge tqb; public QuantumCalculator(IAEMultiBlock t) { super( t ); diff --git a/me/cluster/implementations/QuantumCluster.java b/me/cluster/implementations/QuantumCluster.java index 8d3525e8..d222ec5b 100644 --- a/me/cluster/implementations/QuantumCluster.java +++ b/me/cluster/implementations/QuantumCluster.java @@ -26,8 +26,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class QuantumCluster implements ILocatable, IAECluster { - public WorldCoord min; - public WorldCoord max; + final public WorldCoord min; + final public WorldCoord max; public boolean isDestroyed = false; public boolean updateStatus = true; diff --git a/me/cluster/implementations/SpatialPylonCalculator.java b/me/cluster/implementations/SpatialPylonCalculator.java index a7f8aeff..bbef920a 100644 --- a/me/cluster/implementations/SpatialPylonCalculator.java +++ b/me/cluster/implementations/SpatialPylonCalculator.java @@ -12,7 +12,7 @@ import appeng.tile.spatial.TileSpatialPylon; public class SpatialPylonCalculator extends MBCalculator { - TileSpatialPylon tqb; + private final TileSpatialPylon tqb; public SpatialPylonCalculator(IAEMultiBlock t) { super( t ); diff --git a/me/cluster/implementations/SpatialPylonCluster.java b/me/cluster/implementations/SpatialPylonCluster.java index 471ce9da..4339e1f4 100644 --- a/me/cluster/implementations/SpatialPylonCluster.java +++ b/me/cluster/implementations/SpatialPylonCluster.java @@ -17,13 +17,13 @@ public class SpatialPylonCluster implements IAECluster X, Y, Z, UNFORMED }; - public DimensionalCoord min; - public DimensionalCoord max; + final public DimensionalCoord min; + final public DimensionalCoord max; public boolean isDestroyed = false; public Axis currentAxis = Axis.UNFORMED; - List line = new ArrayList(); + final List line = new ArrayList(); public boolean isValid; public boolean hasPower; public boolean hasChannel;