Example usage for java.util NavigableSet headSet

List of usage examples for java.util NavigableSet headSet

Introduction

In this page you can find the example usage for java.util NavigableSet headSet.

Prototype

NavigableSet<E> headSet(E toElement, boolean inclusive);

Source Link

Document

Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement .

Usage

From source file:net.sf.jasperreports.engine.export.tabulator.DimensionEntries.java

public DimensionRange<T> getRange(int start, int end) {
    if (start > end) {
        throw new IllegalArgumentException(start + " > " + end);
    }//from  www .  j a  v  a 2  s .  com
    if (start <= DimensionEntry.MINUS_INF) {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_START_OUT_OF_RANGE, new Object[] { start });
    }
    if (end >= DimensionEntry.PLUS_INF) {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_END_OUT_OF_RANGE, new Object[] { end });
    }

    T startKey = control.entryKey(start);
    T floor = entries.floor(startKey);
    assert floor != null;

    NavigableSet<T> tailSet = entries.tailSet(floor, true);

    T endKey = control.entryKey(end);
    T ceiling = tailSet.ceiling(endKey);

    NavigableSet<T> rangeSet;
    if (ceiling == null) {
        rangeSet = tailSet;
    } else {
        rangeSet = tailSet.headSet(ceiling, false);
    }

    return new DimensionRange<T>(start, end, floor, ceiling, rangeSet);
}

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

private Member memberOfPreviousRow(NavigableSet<KeyValue> set, final GetClosestRowBeforeTracker state,
        final KeyValue firstOnRow) {
    NavigableSet<KeyValue> head = set.headSet(firstOnRow, false);
    if (head.isEmpty())
        return null;
    for (Iterator<KeyValue> i = head.descendingIterator(); i.hasNext();) {
        KeyValue found = i.next();
        if (state.isExpired(found)) {
            i.remove();/*from  w  ww .  j  ava2 s .  c o m*/
            continue;
        }
        return new Member(head, found);
    }
    return null;
}