Example usage for com.google.common.collect SortedMultiset add

List of usage examples for com.google.common.collect SortedMultiset add

Introduction

In this page you can find the example usage for com.google.common.collect SortedMultiset add.

Prototype

int add(@Nullable E element, int occurrences);

Source Link

Document

Adds a number of occurrences of an element to this multiset.

Usage

From source file:cpw.mods.inventorysorter.InventoryHandler.java

public Multiset<ItemStackHolder> getInventoryContent(Action.ActionContext context) {
    int slotLow = context.slotMapping.begin;
    int slotHigh = context.slotMapping.end + 1;
    SortedMultiset<ItemStackHolder> itemcounts = TreeMultiset
            .create(new InventoryHandler.ItemStackComparator());
    for (int i = slotLow; i < slotHigh; i++) {
        final Slot slot = context.player.openContainer.getSlot(i);
        if (!slot.canTakeStack(context.player))
            continue;
        ItemStack stack = slot.getStack();
        if (stack != null && stack.getItem() != null) {
            ItemStackHolder ish = new ItemStackHolder(stack.copy());
            itemcounts.add(ish, stack.stackSize);
        }//from   www.  ja  va  2s.  c o  m
    }
    final HashMultiset<ItemStackHolder> entries = HashMultiset.create();
    for (Multiset.Entry<ItemStackHolder> entry : itemcounts.descendingMultiset().entrySet()) {
        entries.add(entry.getElement(), entry.getCount());
    }
    return entries;
}