Reverts some of the changes to ItemList.
Removes the split collection as in some rare corner cases the insertion order is important to maintain the correct data in terms of self cleaning. Keeps the general cleanups and split of Fluid/ItemList. Fixes #1964
This commit is contained in:
parent
824ec1eccb
commit
fbfd13d163
|
@ -29,6 +29,7 @@ import net.minecraft.nbt.NBTBase;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.exceptions.AppEngException;
|
||||
|
@ -43,7 +44,6 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.item.UnsortedItemList;
|
||||
|
||||
|
||||
public class CellInventory implements ICellInventory
|
||||
|
@ -191,7 +191,7 @@ public class CellInventory implements ICellInventory
|
|||
|
||||
private boolean isEmpty( final IMEInventory<IAEItemStack> meInventory )
|
||||
{
|
||||
return meInventory.getAvailableItems( new UnsortedItemList() ).isEmpty();
|
||||
return meInventory.getAvailableItems( AEApi.instance().storage().createItemList() ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -446,7 +446,7 @@ public class CellInventory implements ICellInventory
|
|||
{
|
||||
if( this.cellItems == null )
|
||||
{
|
||||
this.cellItems = new UnsortedItemList();
|
||||
this.cellItems = AEApi.instance().storage().createItemList();
|
||||
}
|
||||
|
||||
this.cellItems.resetStatus(); // clears totals and stuff.
|
||||
|
|
|
@ -21,14 +21,11 @@ package appeng.util.item;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
@ -39,7 +36,7 @@ import appeng.api.storage.data.IItemList;
|
|||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
|
||||
private final Map<Item, NavigableMap<IAEItemStack, IAEItemStack>> records = new IdentityHashMap<Item, NavigableMap<IAEItemStack, IAEItemStack>>();
|
||||
private final NavigableMap<IAEItemStack, IAEItemStack> records = new ConcurrentSkipListMap<IAEItemStack, IAEItemStack>();
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
|
@ -49,7 +46,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -70,7 +67,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return null;
|
||||
}
|
||||
|
||||
return this.getItemRecord( itemStack.getItem() ).get( itemStack );
|
||||
return this.records.get( itemStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,7 +120,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -149,7 +146,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -172,7 +169,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getItemRecord( option.getItem() ).get( option );
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
|
@ -202,14 +199,7 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
@Override
|
||||
public int size()
|
||||
{
|
||||
int size = 0;
|
||||
|
||||
for( final Map<IAEItemStack, IAEItemStack> element : this.records.values() )
|
||||
{
|
||||
size += element.size();
|
||||
}
|
||||
|
||||
return size;
|
||||
return this.records.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -227,22 +217,9 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
}
|
||||
}
|
||||
|
||||
private NavigableMap<IAEItemStack, IAEItemStack> getItemRecord( final Item item )
|
||||
{
|
||||
NavigableMap<IAEItemStack, IAEItemStack> itemRecords = this.records.get( item );
|
||||
|
||||
if( itemRecords == null )
|
||||
{
|
||||
itemRecords = new ConcurrentSkipListMap<IAEItemStack, IAEItemStack>();
|
||||
this.records.put( item, itemRecords );
|
||||
}
|
||||
|
||||
return itemRecords;
|
||||
}
|
||||
|
||||
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
|
||||
{
|
||||
return this.getItemRecord( itemStack.getItem() ).put( itemStack, itemStack );
|
||||
return this.records.put( itemStack, itemStack );
|
||||
}
|
||||
|
||||
private Collection<IAEItemStack> findFuzzyDamage( final AEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
|
@ -250,6 +227,6 @@ public final class ItemList implements IItemList<IAEItemStack>
|
|||
final IAEItemStack low = filter.getLow( fuzzy, ignoreMeta );
|
||||
final IAEItemStack high = filter.getHigh( fuzzy, ignoreMeta );
|
||||
|
||||
return this.getItemRecord( filter.getItem() ).subMap( low, true, high, true ).descendingMap().values();
|
||||
return this.records.subMap( low, true, high, true ).descendingMap().values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ package appeng.util.item;
|
|||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
@ -29,47 +28,28 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T>
|
||||
{
|
||||
|
||||
private final Iterator<NavigableMap<T, T>> parent;
|
||||
private Iterator<T> innerIterater = null;
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
|
||||
public MeaningfulItemIterator( final Iterator<NavigableMap<T, T>> iterator )
|
||||
public MeaningfulItemIterator( final Iterator<T> iterator )
|
||||
{
|
||||
this.parent = iterator;
|
||||
|
||||
if( this.parent.hasNext() )
|
||||
{
|
||||
this.innerIterater = this.parent.next().values().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
if( this.innerIterater == null )
|
||||
while( this.parent.hasNext() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.next = this.parent.next();
|
||||
|
||||
while( this.innerIterater.hasNext() || this.parent.hasNext() )
|
||||
{
|
||||
if( this.innerIterater.hasNext() )
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
this.next = this.innerIterater.next();
|
||||
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.innerIterater.remove(); // self cleaning :3
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.parent.hasNext() )
|
||||
else
|
||||
{
|
||||
this.innerIterater = this.parent.next().values().iterator();
|
||||
this.parent.remove(); // self cleaning :3
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
/**
|
||||
* An unsorted {@link IItemList} providing constant access time instead of logarithmic time.
|
||||
*
|
||||
* As tradeoff it will no longer support fuzzy operations.
|
||||
* Also no advanced features like storing craftable or requestable items is supported.
|
||||
*
|
||||
*/
|
||||
public final class UnsortedItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
|
||||
/**
|
||||
* {@link Predicate} to filter all meaningful entries with {@link Iterators}
|
||||
*/
|
||||
private static final Predicate<IAEItemStack> MEANINGFUL_PREDICATE = new Predicate<IAEItemStack>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean apply( @Nonnull final IAEItemStack input )
|
||||
{
|
||||
return input.isMeaningful();
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<IAEItemStack, IAEItemStack> records = new HashMap<IAEItemStack, IAEItemStack>();
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.records.get( option );
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
this.records.put( opt, opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.records.get( itemStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.records.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return Iterators.filter( this.records.values().iterator(), MEANINGFUL_PREDICATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem()
|
||||
{
|
||||
for( final IAEItemStack stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEItemStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported due to being a unsorted collection and thus only solvable in linear or worse time.
|
||||
*
|
||||
* @deprecated to indicate this method is unsupported.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
throw new UnsupportedOperationException( "Unsupported on an unsorted collection" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||
*
|
||||
* @deprecated to indicate this method is unsupported.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addStorage( final IAEItemStack option )
|
||||
{
|
||||
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||
*
|
||||
* @deprecated to indicate this method is unsupported.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addCrafting( final IAEItemStack option )
|
||||
{
|
||||
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported to avoid being used as anything but a plain collection to store real item stacks.
|
||||
*
|
||||
* @deprecated to indicate this method is unsupported.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addRequestable( final IAEItemStack option )
|
||||
{
|
||||
throw new UnsupportedOperationException( "Purely designed for item storage" );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue