some fixes to IItemStackList impls

This commit is contained in:
way2muchnoise
2016-11-27 22:42:32 +01:00
parent 77ebfeea4a
commit 05a486bfa4
2 changed files with 8 additions and 4 deletions

View File

@@ -127,7 +127,7 @@ public class ItemStackList implements IItemStackList {
public void clean() {
List<Pair<Item, ItemStack>> toRemove = stacks.asMap().entrySet().stream()
.flatMap(entry -> entry.getValue().stream().map(value -> Pair.of(entry.getKey(), value)))
.filter(pair -> pair.getValue().getCount() <= 0)
.filter(pair -> pair.getValue().isEmpty())
.collect(Collectors.toList());
toRemove.forEach(pair -> stacks.remove(pair.getLeft(), pair.getRight()));

View File

@@ -86,10 +86,10 @@ public class ItemStackListOredicted implements IItemStackList {
if (stacks != null && !stacks.isEmpty()) {
int i = 0;
ItemStack returnStack = stacks.get(i++);
while (returnStack.getCount() == 0 && i < stacks.size()) {
while (returnStack.isEmpty() && i < stacks.size()) {
returnStack = stacks.get(i++);
}
if (returnStack.getCount() != 0) {
if (!returnStack.isEmpty()) {
return returnStack;
}
}
@@ -102,17 +102,21 @@ public class ItemStackListOredicted implements IItemStackList {
@Nullable
@Override
public ItemStack get(int hash) {
if (underlyingList.needsCleanup) {
clean();
}
return underlyingList.get(hash);
}
@Override
public void clear() {
stacks.clear();
underlyingList.clear();
}
private void localClean() {
List<Map.Entry<Integer, ItemStack>> toRemove = stacks.entries().stream()
.filter(entry -> entry.getValue().getCount() <= 0)
.filter(entry -> entry.getValue().isEmpty())
.collect(Collectors.toList());
toRemove.forEach(entry -> stacks.remove(entry.getKey(), entry.getValue()));