Merge pull request #277 from yueh/fix-276
Changed TreeMap to a threadsafe implementation
This commit is contained in:
commit
88570117bc
3 changed files with 44 additions and 32 deletions
|
@ -5,9 +5,10 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
|
@ -49,7 +50,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
|||
|
||||
final InventoryAdaptor adaptor;
|
||||
|
||||
final TreeMap<Integer, CachedItemStack> memory;
|
||||
private final NavigableMap<Integer, CachedItemStack> memory;
|
||||
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>();
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
|
|||
public MEMonitorIInventory(InventoryAdaptor adaptor)
|
||||
{
|
||||
this.adaptor = adaptor;
|
||||
memory = new TreeMap<Integer, CachedItemStack>();
|
||||
memory = new ConcurrentSkipListMap<Integer, CachedItemStack>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,8 @@ import java.util.Comparator;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
|
@ -40,12 +41,12 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
|||
final SecurityCache security;
|
||||
|
||||
// final TreeMultimap<Integer, IMEInventoryHandler<T>> priorityInventory;
|
||||
final TreeMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
|
||||
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
|
||||
|
||||
public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) {
|
||||
myChannel = chan;
|
||||
this.security = security;
|
||||
priorityInventory = new TreeMap<Integer, List<IMEInventoryHandler<T>>>( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter );
|
||||
priorityInventory = new ConcurrentSkipListMap<Integer, List<IMEInventoryHandler<T>>>( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter );
|
||||
}
|
||||
|
||||
public void addNewStorage(IMEInventoryHandler<T> h)
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public final class ItemList<StackType extends IAEStack> implements IItemList<StackType>
|
||||
{
|
||||
|
||||
private final TreeMap<StackType, StackType> records = new TreeMap<StackType, StackType>();
|
||||
private final NavigableMap<StackType, StackType> records = new ConcurrentSkipListMap<StackType, StackType>();
|
||||
private final Class<? extends IAEStack> clz;
|
||||
|
||||
// private int currentPriority = Integer.MIN_VALUE;
|
||||
|
@ -22,12 +32,12 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
int iteration = Integer.MIN_VALUE;
|
||||
public Throwable stacktrace;
|
||||
|
||||
public ItemList(Class<? extends IAEStack> cla)
|
||||
public ItemList( Class<? extends IAEStack> cla )
|
||||
{
|
||||
clz = cla;
|
||||
}
|
||||
|
||||
private boolean checkStackType(StackType st)
|
||||
private boolean checkStackType( StackType st )
|
||||
{
|
||||
if ( st == null )
|
||||
return true;
|
||||
|
@ -39,7 +49,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
}
|
||||
|
||||
@Override
|
||||
synchronized public void add(StackType option)
|
||||
synchronized public void add( StackType option )
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
@ -53,13 +63,13 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addStorage(StackType option) // adds a stack as
|
||||
synchronized public void addStorage( StackType option ) // adds a stack as
|
||||
// stored.
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
|
@ -74,14 +84,14 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addCrafting(StackType option) // adds a stack as
|
||||
// craftable.
|
||||
synchronized public void addCrafting( StackType option ) // adds a stack as
|
||||
// craftable.
|
||||
{
|
||||
if ( checkStackType( option ) )
|
||||
return;
|
||||
|
@ -95,7 +105,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
|
@ -104,7 +114,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addRequestable(StackType option) // adds a stack
|
||||
synchronized public void addRequestable( StackType option ) // adds a stack
|
||||
// as
|
||||
// requestable.
|
||||
{
|
||||
|
@ -116,11 +126,11 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
if ( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
((IAEItemStack) st).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
( ( IAEItemStack ) st ).setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = (StackType) option.copy();
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
|
@ -132,7 +142,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
@Override
|
||||
synchronized public StackType getFirstItem()
|
||||
{
|
||||
for (StackType stackType : this)
|
||||
for ( StackType stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
|
@ -142,7 +152,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
@Override
|
||||
synchronized public void resetStatus()
|
||||
{
|
||||
for (StackType i : this)
|
||||
for ( StackType i : this )
|
||||
i.reset();
|
||||
}
|
||||
|
||||
|
@ -158,7 +168,7 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise(StackType i)
|
||||
synchronized public StackType findPrecise( StackType i )
|
||||
{
|
||||
if ( checkStackType( i ) )
|
||||
return null;
|
||||
|
@ -184,15 +194,15 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return !iterator().hasNext();
|
||||
}
|
||||
|
||||
public Collection<StackType> findFuzzyDamage(AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta)
|
||||
public Collection<StackType> findFuzzyDamage( AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta )
|
||||
{
|
||||
StackType low = (StackType) filter.getLow( fuzzy, ignoreMeta );
|
||||
StackType high = (StackType) filter.getHigh( fuzzy, ignoreMeta );
|
||||
StackType low = ( StackType ) filter.getLow( fuzzy, ignoreMeta );
|
||||
StackType high = ( StackType ) filter.getHigh( fuzzy, ignoreMeta );
|
||||
return records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy(StackType filter, FuzzyMode fuzzy)
|
||||
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
|
||||
{
|
||||
if ( checkStackType( filter ) )
|
||||
return new ArrayList<StackType>();
|
||||
|
@ -209,21 +219,21 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
|||
return result;
|
||||
}
|
||||
|
||||
AEItemStack ais = (AEItemStack) filter;
|
||||
AEItemStack ais = ( AEItemStack ) filter;
|
||||
if ( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if ( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
return findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList<StackType>();
|
||||
|
||||
for (IAEItemStack is : or.getAEEquivalents())
|
||||
output.addAll( findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
for ( IAEItemStack is : or.getAEEquivalents() )
|
||||
output.addAll( findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue