Example usage for com.google.common.collect Multisets immutableEntry

List of usage examples for com.google.common.collect Multisets immutableEntry

Introduction

In this page you can find the example usage for com.google.common.collect Multisets immutableEntry.

Prototype

public static <E> Multiset.Entry<E> immutableEntry(@Nullable E e, int n) 

Source Link

Document

Returns an immutable multiset entry with the specified element and count.

Usage

From source file:io.atomix.core.multiset.impl.TranscodingAsyncDistributedMultiset.java

@Override
public AsyncDistributedSet<Multiset.Entry<E1>> entrySet() {
    Function<Multiset.Entry<E1>, Multiset.Entry<E2>> entryEncoder = entry -> Multisets
            .immutableEntry(elementEncoder.apply(entry.getElement()), entry.getCount());
    Function<Multiset.Entry<E2>, Multiset.Entry<E1>> entryDecoder = entry -> Multisets
            .immutableEntry(elementDecoder.apply(entry.getElement()), entry.getCount());
    return new TranscodingAsyncDistributedSet<>(backingMultiset.entrySet(), entryEncoder, entryDecoder);
}

From source file:io.atomix.core.multiset.impl.DefaultDistributedMultisetService.java

@Override
public IteratorBatch<Multiset.Entry<String>> nextEntries(long iteratorId, int position) {
    IteratorContext context = entryIterators.get(iteratorId);
    if (context == null) {
        return null;
    }//w  w w . j  a  v a 2 s  .  c  om

    List<Multiset.Entry<String>> entries = new ArrayList<>();
    int size = 0;
    while (context.iterator.hasNext()) {
        context.position++;
        if (context.position > position) {
            Multiset.Entry<String> entry = context.iterator.next();
            entries.add(Multisets.immutableEntry(entry.getElement(), entry.getCount()));
            size += entry.getElement().length() + 4;

            if (size >= MAX_ITERATOR_BATCH_SIZE) {
                break;
            }
        }
    }

    if (entries.isEmpty()) {
        return null;
    }
    return new IteratorBatch<>(iteratorId, context.position, entries, !context.iterator.hasNext());
}

From source file:io.atomix.core.multimap.impl.AbstractAtomicMultimapService.java

@Override
public IteratorBatch<Multiset.Entry<byte[]>> nextValuesSet(long iteratorId, int position) {
    IteratorContext context = entryIterators.get(iteratorId);
    if (context == null) {
        return null;
    }/* w w  w  . j a  v a 2s  . c  om*/

    List<Multiset.Entry<byte[]>> entries = new ArrayList<>();
    int size = 0;
    while (context.iterator.hasNext()) {
        context.position++;
        if (context.position > position) {
            Map.Entry<String, MapEntryValues> entry = context.iterator.next();
            if (!entry.getValue().values().isEmpty()) {
                byte[] value = entry.getValue().values().iterator().next();
                int count = entry.getValue().values().size();
                size += value.length + 4;
                entries.add(Multisets.immutableEntry(value, count));
            }

            if (size >= MAX_ITERATOR_BATCH_SIZE) {
                break;
            }
        }
    }

    if (entries.isEmpty()) {
        return null;
    }
    return new IteratorBatch<>(iteratorId, context.position, entries, !context.iterator.hasNext());
}