Reduce visibility of fields
Implement against interfaces Enforce immutability instead resetting it hard via new instantiation.
This commit is contained in:
+13
-27
@@ -1,21 +1,13 @@
|
|||||||
package appeng.me.cache;
|
package appeng.me.cache;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
|
||||||
|
import com.google.common.collect.*;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import appeng.api.config.AccessRestriction;
|
import appeng.api.config.AccessRestriction;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
@@ -58,31 +50,25 @@ import appeng.tile.crafting.TileCraftingStorageTile;
|
|||||||
import appeng.tile.crafting.TileCraftingTile;
|
import appeng.tile.crafting.TileCraftingTile;
|
||||||
import appeng.util.ItemSorters;
|
import appeng.util.ItemSorters;
|
||||||
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.ImmutableCollection;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.SetMultimap;
|
|
||||||
|
|
||||||
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
final HashSet<CraftingCPUCluster> cpuClusters = new HashSet<CraftingCPUCluster>();
|
private final Set<CraftingCPUCluster> cpuClusters = new HashSet<CraftingCPUCluster>();
|
||||||
final HashSet<ICraftingProvider> providers = new HashSet<ICraftingProvider>();
|
private final Set<ICraftingProvider> providers = new HashSet<ICraftingProvider>();
|
||||||
|
|
||||||
private final HashMap<IGridNode, ICraftingWatcher> watchers = new HashMap<IGridNode, ICraftingWatcher>();
|
private final Map<IGridNode, ICraftingWatcher> watchers = new HashMap<IGridNode, ICraftingWatcher>();
|
||||||
|
|
||||||
final IGrid grid;
|
private final IGrid grid;
|
||||||
IStorageGrid sg;
|
IStorageGrid sg;
|
||||||
IEnergyGrid eg;
|
IEnergyGrid eg;
|
||||||
|
|
||||||
final HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap<ICraftingPatternDetails, List<ICraftingMedium>>();
|
private final Map<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap<ICraftingPatternDetails, List<ICraftingMedium>>();
|
||||||
HashMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new HashMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>>();
|
private final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new HashMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>>();
|
||||||
final HashSet<IAEItemStack> emitableItems = new HashSet<IAEItemStack>();
|
private final Set<IAEItemStack> emitableItems = new HashSet<IAEItemStack>();
|
||||||
final HashMap<String, CraftingLinkNexus> links = new HashMap<String, CraftingLinkNexus>();
|
private final Map<String, CraftingLinkNexus> links = new HashMap<String, CraftingLinkNexus>();
|
||||||
|
|
||||||
boolean updateList = false;
|
boolean updateList = false;
|
||||||
final private SetMultimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
|
private final Multimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
|
||||||
final public GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( interests );
|
final public GenericInterestManager<CraftingWatcher> interestManager = new GenericInterestManager<CraftingWatcher>( interests );
|
||||||
|
|
||||||
static class ActiveCpuIterator implements Iterator<ICraftingCPU>
|
static class ActiveCpuIterator implements Iterator<ICraftingCPU>
|
||||||
@@ -296,11 +282,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
|
|
||||||
private void updatePatterns()
|
private void updatePatterns()
|
||||||
{
|
{
|
||||||
HashMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = craftableItems;
|
Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = craftableItems;
|
||||||
|
|
||||||
// erase list.
|
// erase list.
|
||||||
craftingMethods.clear();
|
craftingMethods.clear();
|
||||||
craftableItems = new HashMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>>();
|
craftableItems.clear();
|
||||||
emitableItems.clear();
|
emitableItems.clear();
|
||||||
|
|
||||||
// update the stuff that was in the list...
|
// update the stuff that was in the list...
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
package appeng.me.cache;
|
package appeng.me.cache;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -75,7 +76,7 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||||||
|
|
||||||
if ( myGridCache.interestManager.containsKey( changedItem ) )
|
if ( myGridCache.interestManager.containsKey( changedItem ) )
|
||||||
{
|
{
|
||||||
Set<ItemWatcher> list = myGridCache.interestManager.get( changedItem );
|
Collection<ItemWatcher> list = myGridCache.interestManager.get( changedItem );
|
||||||
if ( !list.isEmpty() )
|
if ( !list.isEmpty() )
|
||||||
{
|
{
|
||||||
IAEStack fullStack = myStorageList.findPrecise( changedItem );
|
IAEStack fullStack = myStorageList.findPrecise( changedItem );
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
|
|
||||||
if ( sg.interestManager.containsKey( diff ) )
|
if ( sg.interestManager.containsKey( diff ) )
|
||||||
{
|
{
|
||||||
Set<CraftingWatcher> list = sg.interestManager.get( diff );
|
Collection<CraftingWatcher> list = sg.interestManager.get( diff );
|
||||||
|
|
||||||
if ( !list.isEmpty() )
|
if ( !list.isEmpty() )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package appeng.me.helpers;
|
package appeng.me.helpers;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import appeng.api.storage.data.IAEStack;
|
import appeng.api.storage.data.IAEStack;
|
||||||
|
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.SetMultimap;
|
import com.google.common.collect.SetMultimap;
|
||||||
|
|
||||||
public class GenericInterestManager<T>
|
public class GenericInterestManager<T>
|
||||||
@@ -24,11 +26,11 @@ public class GenericInterestManager<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SetMultimap<IAEStack, T> container;
|
private final Multimap<IAEStack, T> container;
|
||||||
private LinkedList<SavedTransactions> transactions = null;
|
private LinkedList<SavedTransactions> transactions = null;
|
||||||
private int transDepth = 0;
|
private int transDepth = 0;
|
||||||
|
|
||||||
public GenericInterestManager(SetMultimap<IAEStack, T> interests) {
|
public GenericInterestManager(Multimap<IAEStack, T> interests) {
|
||||||
container = interests;
|
container = interests;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ public class GenericInterestManager<T>
|
|||||||
return container.containsKey( stack );
|
return container.containsKey( stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<T> get(IAEStack stack)
|
public Collection<T> get(IAEStack stack)
|
||||||
{
|
{
|
||||||
return container.get( stack );
|
return container.get( stack );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user