Basic reformat, hit once, hope never again
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
@@ -28,10 +27,10 @@ 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 com.google.common.collect.Lists;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
@@ -46,84 +45,157 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
private final Class<? extends IAEStack> clz;
|
||||
|
||||
// private int currentPriority = Integer.MIN_VALUE;
|
||||
|
||||
int iteration = Integer.MIN_VALUE;
|
||||
public Throwable stacktrace;
|
||||
int iteration = Integer.MIN_VALUE;
|
||||
|
||||
public ItemList( Class<? extends IAEStack> cla )
|
||||
{
|
||||
this.clz = cla;
|
||||
}
|
||||
|
||||
private boolean checkStackType( StackType st )
|
||||
{
|
||||
if ( st == null )
|
||||
return true;
|
||||
|
||||
if ( !this.clz.isInstance( st ) )
|
||||
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void add( StackType option )
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
this.records.put( opt, opt );
|
||||
}
|
||||
|
||||
private boolean checkStackType( StackType st )
|
||||
{
|
||||
if( st == null )
|
||||
return true;
|
||||
|
||||
if( !this.clz.isInstance( st ) )
|
||||
throw new RuntimeException( "WRONG TYPE - got " + st.getClass().getName() + " expected " + this.clz.getName() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise( StackType i )
|
||||
{
|
||||
if( this.checkStackType( i ) )
|
||||
return null;
|
||||
|
||||
StackType is = this.records.get( i );
|
||||
if( is != null )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
|
||||
{
|
||||
if( this.checkStackType( filter ) )
|
||||
return new ArrayList<StackType>();
|
||||
|
||||
if( filter instanceof IAEFluidStack )
|
||||
{
|
||||
List<StackType> result = Lists.newArrayList();
|
||||
|
||||
if( filter.equals( this ) )
|
||||
{
|
||||
result.add( filter );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
AEItemStack ais = (AEItemStack) filter;
|
||||
if( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList<StackType>();
|
||||
|
||||
for( IAEItemStack is : or.getAEEquivalents() )
|
||||
output.addAll( this.findFuzzyDamage( (AEItemStack) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( ais, fuzzy, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
public Collection<StackType> findFuzzyDamage( AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta )
|
||||
{
|
||||
StackType low = (StackType) filter.getLow( fuzzy, ignoreMeta );
|
||||
StackType high = (StackType) filter.getHigh( fuzzy, ignoreMeta );
|
||||
return this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void addStorage( StackType option ) // adds a stack as
|
||||
// stored.
|
||||
// stored.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
this.records.put( opt, opt );
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
synchronized public void addCrafting( StackType option ) // adds a stack as
|
||||
// craftable.
|
||||
// craftable.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
if( st != null )
|
||||
{
|
||||
// st.setPriority( currentPriority );
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
|
||||
StackType opt = ( StackType ) option.copy();
|
||||
StackType opt = (StackType) option.copy();
|
||||
// opt.setPriority( currentPriority );
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
@@ -133,22 +205,22 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
|
||||
@Override
|
||||
synchronized public void addRequestable( StackType option ) // adds a stack
|
||||
// as
|
||||
// requestable.
|
||||
// as
|
||||
// requestable.
|
||||
{
|
||||
if ( this.checkStackType( option ) )
|
||||
if( this.checkStackType( option ) )
|
||||
return;
|
||||
|
||||
StackType st = this.records.get( option );
|
||||
|
||||
if ( st != null )
|
||||
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 );
|
||||
@@ -160,46 +232,13 @@ 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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void resetStatus()
|
||||
{
|
||||
for ( StackType i : this )
|
||||
i.reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* synchronized public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
||||
*/
|
||||
|
||||
@Override
|
||||
synchronized public Iterator<StackType> iterator()
|
||||
{
|
||||
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public StackType findPrecise( StackType i )
|
||||
{
|
||||
if ( this.checkStackType( i ) )
|
||||
return null;
|
||||
|
||||
StackType is = this.records.get( i );
|
||||
if ( is != null )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public int size()
|
||||
{
|
||||
@@ -207,56 +246,15 @@ public final class ItemList<StackType extends IAEStack> implements IItemList<Sta
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
synchronized public Iterator<StackType> iterator()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
public Collection<StackType> findFuzzyDamage( AEItemStack filter, FuzzyMode fuzzy, boolean ignoreMeta )
|
||||
{
|
||||
StackType low = ( StackType ) filter.getLow( fuzzy, ignoreMeta );
|
||||
StackType high = ( StackType ) filter.getHigh( fuzzy, ignoreMeta );
|
||||
return this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
return new MeaningfulIterator<StackType>( this.records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StackType> findFuzzy( StackType filter, FuzzyMode fuzzy )
|
||||
synchronized public void resetStatus()
|
||||
{
|
||||
if ( this.checkStackType( filter ) )
|
||||
return new ArrayList<StackType>();
|
||||
|
||||
if ( filter instanceof IAEFluidStack )
|
||||
{
|
||||
List<StackType> result = Lists.newArrayList();
|
||||
|
||||
if ( filter.equals( this ) )
|
||||
{
|
||||
result.add( filter );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
AEItemStack ais = ( AEItemStack ) filter;
|
||||
if ( ais.isOre() )
|
||||
{
|
||||
OreReference or = ais.def.isOre;
|
||||
if ( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
return this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection<StackType> output = new LinkedList<StackType>();
|
||||
|
||||
for ( IAEItemStack is : or.getAEEquivalents() )
|
||||
output.addAll( this.findFuzzyDamage( ( AEItemStack ) is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( ais, fuzzy, false );
|
||||
for( StackType i : this )
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user