Improved MEInventoryHandler.getAccess()
Changed the public fields to setters and getters Added a cache for the evaluated values instead of calculating with each access
This commit is contained in:
parent
95fb894ba3
commit
1bb0109c45
7 changed files with 95 additions and 43 deletions
|
@ -101,14 +101,14 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
|||
priorityList.add( AEItemStack.create( is ) );
|
||||
}
|
||||
|
||||
this.myWhitelist = hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
||||
this.setWhitelist( hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
|
||||
if ( !priorityList.isEmpty() )
|
||||
{
|
||||
if ( hasFuzzy )
|
||||
this.myPartitionList = new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode );
|
||||
this.setPartitionList( new FuzzyPriorityList<IAEItemStack>( priorityList, fzMode ) );
|
||||
else
|
||||
this.myPartitionList = new PrecisePriorityList<IAEItemStack>( priorityList );
|
||||
this.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,19 +116,19 @@ public class CellInventoryHandler extends MEInventoryHandler<IAEItemStack> imple
|
|||
@Override
|
||||
public boolean isPreformatted()
|
||||
{
|
||||
return ! this.myPartitionList.isEmpty();
|
||||
return ! this.getPartitionList().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFuzzy()
|
||||
{
|
||||
return this.myPartitionList instanceof FuzzyPriorityList;
|
||||
return this.getPartitionList() instanceof FuzzyPriorityList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncludeExclude getIncludeExcludeMode()
|
||||
{
|
||||
return this.myWhitelist;
|
||||
return this.getWhitelist();
|
||||
}
|
||||
|
||||
public int getStatusForCell()
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
|
@ -31,6 +32,7 @@ import appeng.api.storage.data.IItemList;
|
|||
import appeng.util.prioitylist.DefaultPriorityList;
|
||||
import appeng.util.prioitylist.IPartitionList;
|
||||
|
||||
|
||||
public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
||||
{
|
||||
|
||||
|
@ -38,24 +40,78 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
final protected IMEMonitor<T> monitor;
|
||||
final protected IMEInventoryHandler<T> internal;
|
||||
|
||||
public int myPriority = 0;
|
||||
public IncludeExclude myWhitelist = IncludeExclude.WHITELIST;
|
||||
public AccessRestriction myAccess = AccessRestriction.READ_WRITE;
|
||||
public IPartitionList<T> myPartitionList = new DefaultPriorityList<T>();
|
||||
private int myPriority;
|
||||
private IncludeExclude myWhitelist;
|
||||
private AccessRestriction myAccess;
|
||||
private IPartitionList<T> myPartitionList;
|
||||
|
||||
public MEInventoryHandler(IMEInventory<T> i, StorageChannel channel) {
|
||||
private AccessRestriction cachedAccessRestriction;
|
||||
private boolean hasReadAccess;
|
||||
private boolean hasWriteAccess;
|
||||
|
||||
public MEInventoryHandler( IMEInventory<T> i, StorageChannel channel )
|
||||
{
|
||||
this.channel = channel;
|
||||
|
||||
if ( i instanceof IMEInventoryHandler )
|
||||
this.internal = (IMEInventoryHandler<T>) i;
|
||||
this.internal = ( IMEInventoryHandler<T> ) i;
|
||||
else
|
||||
this.internal = new MEPassThrough<T>( i, channel );
|
||||
|
||||
this.monitor = this.internal instanceof IMEMonitor ? (IMEMonitor<T>) this.internal : null;
|
||||
this.monitor = this.internal instanceof IMEMonitor ? ( IMEMonitor<T> ) this.internal : null;
|
||||
|
||||
this.setPriority( 0 );
|
||||
this.setWhitelist( IncludeExclude.WHITELIST );
|
||||
this.setBaseAccess( AccessRestriction.READ_WRITE );
|
||||
this.setPartitionList( new DefaultPriorityList<T>() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems(T input, Actionable type, BaseActionSource src)
|
||||
public int getPriority()
|
||||
{
|
||||
return this.myPriority;
|
||||
}
|
||||
|
||||
public void setPriority( int myPriority )
|
||||
{
|
||||
this.myPriority = myPriority;
|
||||
}
|
||||
|
||||
public IncludeExclude getWhitelist()
|
||||
{
|
||||
return this.myWhitelist;
|
||||
}
|
||||
|
||||
public void setWhitelist( IncludeExclude myWhitelist )
|
||||
{
|
||||
this.myWhitelist = myWhitelist;
|
||||
}
|
||||
|
||||
public AccessRestriction getBaseAccess()
|
||||
{
|
||||
return this.myAccess;
|
||||
}
|
||||
|
||||
public void setBaseAccess( AccessRestriction myAccess )
|
||||
{
|
||||
this.myAccess = myAccess;
|
||||
this.cachedAccessRestriction = this.myAccess.restrictPermissions( this.internal.getAccess() );
|
||||
this.hasReadAccess = this.getAccess().hasPermission( AccessRestriction.READ );
|
||||
this.hasWriteAccess = this.getAccess().hasPermission( AccessRestriction.WRITE );
|
||||
}
|
||||
|
||||
public IPartitionList<T> getPartitionList()
|
||||
{
|
||||
return this.myPartitionList;
|
||||
}
|
||||
|
||||
public void setPartitionList( IPartitionList<T> myPartitionList )
|
||||
{
|
||||
this.myPartitionList = myPartitionList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( T input, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( !this.canAccept( input ) )
|
||||
return input;
|
||||
|
@ -64,18 +120,18 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
}
|
||||
|
||||
@Override
|
||||
public T extractItems(T request, Actionable type, BaseActionSource src)
|
||||
public T extractItems( T request, Actionable type, BaseActionSource src )
|
||||
{
|
||||
if ( !this.getAccess().hasPermission( AccessRestriction.READ ) )
|
||||
if ( !hasReadAccess )
|
||||
return null;
|
||||
|
||||
return this.internal.extractItems( request, type, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(IItemList<T> out)
|
||||
public IItemList<T> getAvailableItems( IItemList<T> out )
|
||||
{
|
||||
if ( !this.getAccess().hasPermission( AccessRestriction.READ ) )
|
||||
if ( !hasReadAccess )
|
||||
return out;
|
||||
|
||||
return this.internal.getAvailableItems( out );
|
||||
|
@ -90,11 +146,11 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
@Override
|
||||
public AccessRestriction getAccess()
|
||||
{
|
||||
return this.myAccess.restrictPermissions( this.internal.getAccess() );
|
||||
return this.cachedAccessRestriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrioritized(T input)
|
||||
public boolean isPrioritized( T input )
|
||||
{
|
||||
if ( this.myWhitelist == IncludeExclude.WHITELIST )
|
||||
return this.myPartitionList.isListed( input ) || this.internal.isPrioritized( input );
|
||||
|
@ -102,9 +158,9 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canAccept(T input)
|
||||
public boolean canAccept( T input )
|
||||
{
|
||||
if ( !this.getAccess().hasPermission( AccessRestriction.WRITE ) )
|
||||
if ( !hasWriteAccess )
|
||||
return false;
|
||||
|
||||
if ( this.myWhitelist == IncludeExclude.BLACKLIST && this.myPartitionList.isListed( input ) )
|
||||
|
@ -114,12 +170,6 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
return this.myPartitionList.isListed( input ) && this.internal.canAccept( input );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.myPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlot()
|
||||
{
|
||||
|
@ -132,7 +182,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean validForPass(int i)
|
||||
public boolean validForPass( int i )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
|
@ -64,7 +65,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
|||
public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) {
|
||||
this.myChannel = chan;
|
||||
this.security = security;
|
||||
this.priorityInventory = new ConcurrentSkipListMap<Integer, List<IMEInventoryHandler<T>>>( PRIORITY_SORTER ); // TreeMultimap.create( prioritySorter, hashSorter );
|
||||
this.priorityInventory = new TreeMap<Integer, List<IMEInventoryHandler<T>>>( PRIORITY_SORTER ); // TreeMultimap.create( prioritySorter, hashSorter );
|
||||
}
|
||||
|
||||
public void addNewStorage(IMEInventoryHandler<T> h)
|
||||
|
|
|
@ -313,9 +313,10 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
|
|||
|
||||
private void updateHandler()
|
||||
{
|
||||
this.myHandler.myAccess = AccessRestriction.WRITE;
|
||||
this.myHandler.myWhitelist = this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
||||
this.myHandler.myPriority = this.priority;
|
||||
this.myHandler.setBaseAccess( AccessRestriction.WRITE );
|
||||
;
|
||||
this.myHandler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.myHandler.setPriority( this.priority );
|
||||
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
|
@ -328,9 +329,9 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
|
|||
}
|
||||
|
||||
if ( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
this.myHandler.myPartitionList = new FuzzyPriorityList( priorityList, ( FuzzyMode ) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
|
||||
this.myHandler.setPartitionList( new FuzzyPriorityList( priorityList, ( FuzzyMode ) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
else
|
||||
this.myHandler.myPartitionList = new PrecisePriorityList( priorityList );
|
||||
this.myHandler.setPartitionList( new PrecisePriorityList( priorityList ) );
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -319,9 +319,9 @@ public class PartStorageBus
|
|||
|
||||
this.handler = new MEInventoryHandler( inv, StorageChannel.ITEMS );
|
||||
|
||||
this.handler.myAccess = ( AccessRestriction ) this.getConfigManager().getSetting( Settings.ACCESS );
|
||||
this.handler.myWhitelist = this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
||||
this.handler.myPriority = this.priority;
|
||||
this.handler.setBaseAccess( ( AccessRestriction ) this.getConfigManager().getSetting( Settings.ACCESS ) );;
|
||||
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.handler.setPriority( this.priority );
|
||||
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
|
@ -334,9 +334,9 @@ public class PartStorageBus
|
|||
}
|
||||
|
||||
if ( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
this.handler.myPartitionList = new FuzzyPriorityList( priorityList, ( FuzzyMode ) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
|
||||
this.handler.setPartitionList( new FuzzyPriorityList( priorityList, ( FuzzyMode ) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
else
|
||||
this.handler.myPartitionList = new PrecisePriorityList( priorityList );
|
||||
this.handler.setPartitionList ( new PrecisePriorityList( priorityList ));
|
||||
|
||||
if ( inv instanceof IMEMonitor )
|
||||
( ( IMEMonitor ) inv ).addListener( this, this.handler );
|
||||
|
|
|
@ -427,7 +427,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
|
|||
return null;
|
||||
|
||||
MEInventoryHandler ih = new MEInventoryHandler( h, h.getChannel() );
|
||||
ih.myPriority = this.priority;
|
||||
ih.setPriority( this.priority );
|
||||
|
||||
MEMonitorHandler<StackType> g = new ChestMonitorHandler<StackType>( ih );
|
||||
g.addListener( new ChestNetNotifier( h.getChannel() ), g );
|
||||
|
|
|
@ -245,7 +245,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
|||
power += this.handlersBySlot[x].cellIdleDrain( is, cell );
|
||||
|
||||
DriveWatcher<IAEItemStack> ih = new DriveWatcher( cell, is, this.handlersBySlot[x], this );
|
||||
ih.myPriority = this.priority;
|
||||
ih.setPriority( this.priority );
|
||||
this.invBySlot[x] = ih;
|
||||
this.items.add( ih );
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
|||
power += this.handlersBySlot[x].cellIdleDrain( is, cell );
|
||||
|
||||
DriveWatcher<IAEItemStack> ih = new DriveWatcher( cell, is, this.handlersBySlot[x], this );
|
||||
ih.myPriority = this.priority;
|
||||
ih.setPriority( this.priority );
|
||||
this.invBySlot[x] = ih;
|
||||
this.fluids.add( ih );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue