Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
+162 -163
View File
@@ -18,6 +18,7 @@
package appeng.me.cache;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -53,25 +54,23 @@ import appeng.me.helpers.GenericInterestManager;
import appeng.me.storage.ItemWatcher;
import appeng.me.storage.NetworkInventoryHandler;
public class GridStorageCache implements IStorageGrid
{
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
final public GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<ItemWatcher>( this.interests );
final public IGrid myGrid;
final HashSet<ICellProvider> activeCellProviders = new HashSet<ICellProvider>();
final HashSet<ICellProvider> inactiveCellProviders = new HashSet<ICellProvider>();
final public IGrid myGrid;
private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
final public GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<ItemWatcher>( this.interests );
private final NetworkMonitor<IAEItemStack> itemMonitor = new NetworkMonitor<IAEItemStack>( this, StorageChannel.ITEMS );
private NetworkInventoryHandler<IAEFluidStack> myFluidNetwork;
private final NetworkMonitor<IAEFluidStack> fluidMonitor = new NetworkMonitor<IAEFluidStack>( this, StorageChannel.FLUIDS );
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<IGridNode, IStackWatcher>();
private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
private NetworkInventoryHandler<IAEFluidStack> myFluidNetwork;
public GridStorageCache(IGrid g) {
public GridStorageCache( IGrid g )
{
this.myGrid = g;
}
@@ -82,82 +81,86 @@ public class GridStorageCache implements IStorageGrid
this.fluidMonitor.onTick();
}
private class CellChangeTrackerRecord
@Override
public void removeNode( IGridNode node, IGridHost machine )
{
if( machine instanceof ICellContainer )
{
ICellContainer cc = (ICellContainer) machine;
final StorageChannel channel;
final int up_or_down;
final IItemList list;
final BaseActionSource src;
public CellChangeTrackerRecord(StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc) {
this.channel = channel;
this.up_or_down = i;
this.src = actionSrc;
if ( channel == StorageChannel.ITEMS )
this.list = ((IMEInventoryHandler<IAEItemStack>) h).getAvailableItems( AEApi.instance().storage().createItemList() );
else if ( channel == StorageChannel.FLUIDS )
this.list = ((IMEInventoryHandler<IAEFluidStack>) h).getAvailableItems( AEApi.instance().storage().createFluidList() );
else
this.list = null;
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
this.removeCellProvider( cc, new CellChangeTracker() ).applyChanges();
this.inactiveCellProviders.remove( cc );
}
public void applyChanges()
if( machine instanceof IStackWatcherHost )
{
GridStorageCache.this.postChangesToNetwork( this.channel, this.up_or_down, this.list, this.src );
}
}
private class CellChangeTracker
{
final List<CellChangeTrackerRecord> data = new LinkedList<CellChangeTrackerRecord>();
public void postChanges(StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc)
{
this.data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) );
}
public void applyChanges()
{
for (CellChangeTrackerRecord rec : this.data)
rec.applyChanges();
IStackWatcher myWatcher = this.watchers.get( machine );
if( myWatcher != null )
{
myWatcher.clear();
this.watchers.remove( machine );
}
}
}
@Override
public void registerCellProvider(ICellProvider provider)
public void addNode( IGridNode node, IGridHost machine )
{
this.inactiveCellProviders.add( provider );
this.addCellProvider( provider, new CellChangeTracker() ).applyChanges();
if( machine instanceof ICellContainer )
{
ICellContainer cc = (ICellContainer) machine;
this.inactiveCellProviders.add( cc );
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
if( node.isActive() )
this.addCellProvider( cc, new CellChangeTracker() ).applyChanges();
}
if( machine instanceof IStackWatcherHost )
{
IStackWatcherHost swh = (IStackWatcherHost) machine;
ItemWatcher iw = new ItemWatcher( this, swh );
this.watchers.put( node, iw );
swh.updateWatcher( iw );
}
}
@Override
public void unregisterCellProvider(ICellProvider provider)
public void onSplit( IGridStorage storageB )
{
this.removeCellProvider( provider, new CellChangeTracker() ).applyChanges();
this.inactiveCellProviders.remove( provider );
}
public CellChangeTracker addCellProvider(ICellProvider cc, CellChangeTracker tracker)
@Override
public void onJoin( IGridStorage storageB )
{
if ( this.inactiveCellProviders.contains( cc ) )
}
@Override
public void populateGridStorage( IGridStorage storage )
{
}
public CellChangeTracker addCellProvider( ICellProvider cc, CellChangeTracker tracker )
{
if( this.inactiveCellProviders.contains( cc ) )
{
this.inactiveCellProviders.remove( cc );
this.activeCellProviders.add( cc );
BaseActionSource actionSrc = new BaseActionSource();
if ( cc instanceof IActionHost )
if( cc instanceof IActionHost )
actionSrc = new MachineSource( (IActionHost) cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
for( IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ) )
{
tracker.postChanges( StorageChannel.ITEMS, 1, h, actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
for( IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ) )
{
tracker.postChanges( StorageChannel.FLUIDS, 1, h, actionSrc );
}
@@ -166,23 +169,23 @@ public class GridStorageCache implements IStorageGrid
return tracker;
}
public CellChangeTracker removeCellProvider(ICellProvider cc, CellChangeTracker tracker)
public CellChangeTracker removeCellProvider( ICellProvider cc, CellChangeTracker tracker )
{
if ( this.activeCellProviders.contains( cc ) )
if( this.activeCellProviders.contains( cc ) )
{
this.inactiveCellProviders.add( cc );
this.activeCellProviders.remove( cc );
BaseActionSource actionSrc = new BaseActionSource();
if ( cc instanceof IActionHost )
if( cc instanceof IActionHost )
actionSrc = new MachineSource( (IActionHost) cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
for( IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ) )
{
tracker.postChanges( StorageChannel.ITEMS, -1, h, actionSrc );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
for( IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ) )
{
tracker.postChanges( StorageChannel.FLUIDS, -1, h, actionSrc );
}
@@ -192,7 +195,7 @@ public class GridStorageCache implements IStorageGrid
}
@MENetworkEventSubscribe
public void cellUpdate(MENetworkCellArrayUpdate ev)
public void cellUpdate( MENetworkCellArrayUpdate ev )
{
this.myItemNetwork = null;
this.myFluidNetwork = null;
@@ -203,20 +206,20 @@ public class GridStorageCache implements IStorageGrid
CellChangeTracker tracker = new CellChangeTracker();
for (ICellProvider cc : ll)
for( ICellProvider cc : ll )
{
boolean Active = true;
if ( cc instanceof IActionHost )
if( cc instanceof IActionHost )
{
IGridNode node = ((IActionHost) cc).getActionableNode();
if ( node != null && node.isActive() )
IGridNode node = ( (IActionHost) cc ).getActionableNode();
if( node != null && node.isActive() )
Active = true;
else
Active = false;
}
if ( Active )
if( Active )
this.addCellProvider( cc, tracker );
else
this.removeCellProvider( cc, tracker );
@@ -228,118 +231,81 @@ public class GridStorageCache implements IStorageGrid
tracker.applyChanges();
}
@Override
public void removeNode(IGridNode node, IGridHost machine)
private void postChangesToNetwork( StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src )
{
if ( machine instanceof ICellContainer )
switch( chan )
{
ICellContainer cc = (ICellContainer) machine;
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
this.removeCellProvider( cc, new CellChangeTracker() ).applyChanges();
this.inactiveCellProviders.remove( cc );
}
if ( machine instanceof IStackWatcherHost )
{
IStackWatcher myWatcher = this.watchers.get( machine );
if ( myWatcher != null )
{
myWatcher.clear();
this.watchers.remove( machine );
}
}
}
@Override
public void addNode(IGridNode node, IGridHost machine)
{
if ( machine instanceof ICellContainer )
{
ICellContainer cc = (ICellContainer) machine;
this.inactiveCellProviders.add( cc );
this.myGrid.postEvent( new MENetworkCellArrayUpdate() );
if ( node.isActive() )
this.addCellProvider( cc, new CellChangeTracker() ).applyChanges();
}
if ( machine instanceof IStackWatcherHost )
{
IStackWatcherHost swh = (IStackWatcherHost) machine;
ItemWatcher iw = new ItemWatcher( this, swh );
this.watchers.put( node, iw );
swh.updateWatcher( iw );
}
}
private void buildNetworkStorage(StorageChannel chan)
{
SecurityCache security = this.myGrid.getCache( ISecurityGrid.class );
switch (chan)
{
case FLUIDS:
this.myFluidNetwork = new NetworkInventoryHandler<IAEFluidStack>( StorageChannel.FLUIDS, security );
for (ICellProvider cc : this.activeCellProviders)
{
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan ))
this.myFluidNetwork.addNewStorage( h );
}
break;
case ITEMS:
this.myItemNetwork = new NetworkInventoryHandler<IAEItemStack>( StorageChannel.ITEMS, security );
for (ICellProvider cc : this.activeCellProviders)
{
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan ))
this.myItemNetwork.addNewStorage( h );
}
break;
default:
}
}
private void postChangesToNetwork(StorageChannel chan, int up_or_down, IItemList availableItems, BaseActionSource src)
{
switch (chan)
{
case FLUIDS:
this.fluidMonitor.postChange( up_or_down > 0, availableItems, src );
break;
case ITEMS:
this.itemMonitor.postChange( up_or_down > 0, availableItems, src );
break;
default:
case FLUIDS:
this.fluidMonitor.postChange( up_or_down > 0, availableItems, src );
break;
case ITEMS:
this.itemMonitor.postChange( up_or_down > 0, availableItems, src );
break;
default:
}
}
public IMEInventoryHandler<IAEItemStack> getItemInventoryHandler()
{
if ( this.myItemNetwork == null )
if( this.myItemNetwork == null )
this.buildNetworkStorage( StorageChannel.ITEMS );
return this.myItemNetwork;
}
private void buildNetworkStorage( StorageChannel chan )
{
SecurityCache security = this.myGrid.getCache( ISecurityGrid.class );
switch( chan )
{
case FLUIDS:
this.myFluidNetwork = new NetworkInventoryHandler<IAEFluidStack>( StorageChannel.FLUIDS, security );
for( ICellProvider cc : this.activeCellProviders )
{
for( IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan ) )
this.myFluidNetwork.addNewStorage( h );
}
break;
case ITEMS:
this.myItemNetwork = new NetworkInventoryHandler<IAEItemStack>( StorageChannel.ITEMS, security );
for( ICellProvider cc : this.activeCellProviders )
{
for( IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan ) )
this.myItemNetwork.addNewStorage( h );
}
break;
default:
}
}
public IMEInventoryHandler<IAEFluidStack> getFluidInventoryHandler()
{
if ( this.myFluidNetwork == null )
if( this.myFluidNetwork == null )
this.buildNetworkStorage( StorageChannel.FLUIDS );
return this.myFluidNetwork;
}
@Override
public void postAlterationOfStoredItems(StorageChannel chan, Iterable<? extends IAEStack> input, BaseActionSource src)
public void postAlterationOfStoredItems( StorageChannel chan, Iterable<? extends IAEStack> input, BaseActionSource src )
{
if ( chan == StorageChannel.ITEMS )
if( chan == StorageChannel.ITEMS )
this.itemMonitor.postChange( true, (Iterable<IAEItemStack>) input, src );
else if ( chan == StorageChannel.FLUIDS )
else if( chan == StorageChannel.FLUIDS )
this.fluidMonitor.postChange( true, (Iterable<IAEFluidStack>) input, src );
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
public void registerCellProvider( ICellProvider provider )
{
return this.fluidMonitor;
this.inactiveCellProviders.add( provider );
this.addCellProvider( provider, new CellChangeTracker() ).applyChanges();
}
@Override
public void unregisterCellProvider( ICellProvider provider )
{
this.removeCellProvider( provider, new CellChangeTracker() ).applyChanges();
this.inactiveCellProviders.remove( provider );
}
@Override
@@ -349,21 +315,54 @@ public class GridStorageCache implements IStorageGrid
}
@Override
public void onSplit(IGridStorage storageB)
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
return this.fluidMonitor;
}
@Override
public void onJoin(IGridStorage storageB)
private class CellChangeTrackerRecord
{
final StorageChannel channel;
final int up_or_down;
final IItemList list;
final BaseActionSource src;
public CellChangeTrackerRecord( StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc )
{
this.channel = channel;
this.up_or_down = i;
this.src = actionSrc;
if( channel == StorageChannel.ITEMS )
this.list = ( (IMEInventoryHandler<IAEItemStack>) h ).getAvailableItems( AEApi.instance().storage().createItemList() );
else if( channel == StorageChannel.FLUIDS )
this.list = ( (IMEInventoryHandler<IAEFluidStack>) h ).getAvailableItems( AEApi.instance().storage().createFluidList() );
else
this.list = null;
}
public void applyChanges()
{
GridStorageCache.this.postChangesToNetwork( this.channel, this.up_or_down, this.list, this.src );
}
}
@Override
public void populateGridStorage(IGridStorage storage)
private class CellChangeTracker
{
}
final List<CellChangeTrackerRecord> data = new LinkedList<CellChangeTrackerRecord>();
public void postChanges( StorageChannel channel, int i, IMEInventoryHandler<? extends IAEStack> h, BaseActionSource actionSrc )
{
this.data.add( new CellChangeTrackerRecord( channel, i, h, actionSrc ) );
}
public void applyChanges()
{
for( CellChangeTrackerRecord rec : this.data )
rec.applyChanges();
}
}
}