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

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

Introduction

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

Prototype

@Override
Iterator<E> iterator();

Source Link

Document

Elements that occur multiple times in the multiset will appear multiple times in this iterator, though not necessarily sequentially.

Usage

From source file:com.cinchapi.concourse.server.storage.db.Block.java

/**
 * Seek revisions that contain components from {@code byteables} and append
 * them to {@code record}. The seek will be perform in memory iff this block
 * is mutable, otherwise, the seek happens on disk.
 * //  w w w. j a  va2 s .  com
 * @param record
 * @param byteables
 */
private void seek(Record<L, K, V> record, Byteable... byteables) {
    Locks.lockIfCondition(read, mutable);
    try {
        if (filter.mightContain(byteables)) {
            SortedMultiset<Revision<L, K, V>> revisions = softRevisions.get();
            if (revisions != null) {
                Iterator<Revision<L, K, V>> it = revisions.iterator();
                boolean processing = false; // Since the revisions are
                                            // sorted, I can toggle this
                                            // flag on once I reach a
                                            // revision that I care about so
                                            // that I can break out of the
                                            // loop once I reach a revision
                                            // I don't care about again.
                boolean checkSecond = byteables.length > 1;
                while (it.hasNext()) {
                    Revision<L, K, V> revision = it.next();
                    if (revision.getLocator().equals(byteables[0])
                            && ((checkSecond && revision.getKey().equals(byteables[1])) || !checkSecond)) {
                        processing = true;
                        record.append(revision);
                    } else if (processing) {
                        break;
                    }
                }
            } else {
                int start = index.getStart(byteables);
                int length = index.getEnd(byteables) - (start - 1);
                if (start != BlockIndex.NO_ENTRY && length > 0) {
                    ByteBuffer bytes = FileSystem.map(file, MapMode.READ_ONLY, start, length);
                    Iterator<ByteBuffer> it = ByteableCollections.iterator(bytes);
                    while (it.hasNext()) {
                        Revision<L, K, V> revision = Byteables.read(it.next(), xRevisionClass());
                        Logger.debug("Attempting to append {} from {} to " + "{}", revision, this, record);
                        record.append(revision);
                    }
                }
            }
        }
    } finally {
        Locks.unlockIfCondition(read, mutable);
    }
}