Example usage for java.util.concurrent ConcurrentSkipListSet isEmpty

List of usage examples for java.util.concurrent ConcurrentSkipListSet isEmpty

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListSet isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:org.apache.hadoop.hbase.regionserver.Memcache.java

private void getRowKeyAtOrBefore(final ConcurrentSkipListSet<KeyValue> set, final KeyValue kv,
        final NavigableSet<KeyValue> candidates, final NavigableSet<KeyValue> deletes, final long now) {
    if (set.isEmpty()) {
        return;//from   ww w .  j  a  v  a  2  s.c om
    }
    // We want the earliest possible to start searching from.  Start before
    // the candidate key in case it turns out a delete came in later.
    KeyValue search = candidates.isEmpty() ? kv : candidates.first();

    // Get all the entries that come equal or after our search key
    SortedSet<KeyValue> tailset = set.tailSet(search);

    // if there are items in the tail map, there's either a direct match to
    // the search key, or a range of values between the first candidate key
    // and the ultimate search key (or the end of the cache)
    if (!tailset.isEmpty() && this.comparator.compareRows(tailset.first(), search) <= 0) {
        // Keep looking at cells as long as they are no greater than the 
        // ultimate search key and there's still records left in the map.
        KeyValue deleted = null;
        KeyValue found = null;
        for (Iterator<KeyValue> iterator = tailset.iterator(); iterator.hasNext()
                && (found == null || this.comparator.compareRows(found, kv) <= 0);) {
            found = iterator.next();
            if (this.comparator.compareRows(found, kv) <= 0) {
                if (found.isDeleteType()) {
                    Store.handleDeletes(found, candidates, deletes);
                    if (deleted == null) {
                        deleted = found;
                    }
                } else {
                    if (Store.notExpiredAndNotInDeletes(this.ttl, found, now, deletes)) {
                        candidates.add(found);
                    } else {
                        if (deleted == null) {
                            deleted = found;
                        }
                        // TODO: Check this removes the right key.
                        // Its expired.  Remove it.
                        iterator.remove();
                    }
                }
            }
        }
        if (candidates.isEmpty() && deleted != null) {
            getRowKeyBefore(set, deleted, candidates, deletes, now);
        }
    } else {
        // The tail didn't contain any keys that matched our criteria, or was 
        // empty. Examine all the keys that proceed our splitting point.
        getRowKeyBefore(set, search, candidates, deletes, now);
    }
}