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

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

Introduction

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

Prototype

SortedMultiset<E> descendingMultiset();

Source Link

Usage

From source file:c5db.interfaces.replication.QuorumConfiguration.java

private static long getGreatestIndexCommittedByMajority(Set<Long> peers, Map<Long, Long> peersLastAckedIndex) {
    SortedMultiset<Long> committedIndexes = TreeMultiset.create();
    committedIndexes.addAll(peers.stream().map(peerId -> peersLastAckedIndex.getOrDefault(peerId, 0L))
            .collect(Collectors.toList()));
    return Iterables.get(committedIndexes.descendingMultiset(), calculateNumericalMajority(peers.size()) - 1);
}

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);
        }/*ww w. jav  a  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;
}