Example usage for java.util SortedSet headSet

List of usage examples for java.util SortedSet headSet

Introduction

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

Prototype

SortedSet<E> headSet(E toElement);

Source Link

Document

Returns a view of the portion of this set whose elements are strictly less than toElement .

Usage

From source file:org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceManager.java

/**
 * Cleans a log file and all older files from ZK. Called when we are sure that a
 * log file is closed and has no more entries.
 * @param key Path to the log//from  www.j a  v  a 2 s  .  co  m
 * @param id id of the peer cluster
 * @param queueRecovered Whether this is a recovered queue
 */
public void cleanOldLogs(String key, String id, boolean queueRecovered) {
    synchronized (this.hlogsById) {
        SortedSet<String> hlogs = this.hlogsById.get(id);
        if (queueRecovered || hlogs.first().equals(key)) {
            return;
        }
        SortedSet<String> hlogSet = hlogs.headSet(key);
        for (String hlog : hlogSet) {
            this.replicationQueues.removeLog(id, hlog);
        }
        hlogSet.clear();
    }
}

From source file:org.archive.util.PrefixFinder.java

/**
 * Extracts prefixes of a given string from a SortedSet.  If an element
 * of the given set is a prefix of the given string, then that element
 * is added to the result list./*w  w  w.j  a  v a 2  s.  co m*/
 * 
 * <p>Put another way, for every element in the result list, the following 
 * expression will be true: <tt>string.startsWith(element.getKey())</tt>.
 * 
 * @param set     the sorted set containing potential prefixes
 * @param input   the string whose prefixes to find 
 * @return   the list of prefixes 
 */
public static List<String> find(SortedSet<String> set, String input) {
    LinkedList<String> result = new LinkedList<String>();
    set = headSetInclusive(set, input);
    for (String last = last(set); last != null; last = last(set)) {
        if (input.startsWith(last)) {
            result.push(last);
            set = set.headSet(last);
        } else {
            // Find the longest common prefix.
            int p = StringUtils.indexOfDifference(input, last);
            if (p <= 0) {
                return result;
            }
            last = input.substring(0, p);
            set = headSetInclusive(set, last);
        }
    }
    return result;
}

From source file:org.archive.util.PrefixFinder.java

protected static SortedSet<String> headSetInclusive(SortedSet<String> set, String input) {
    // use NavigableSet inclusive version if available
    if (set instanceof NavigableSet) {
        return ((NavigableSet<String>) set).headSet(input, true);
    }/* w ww  . j av  a  2s.  c o  m*/
    // use Stored*Set inclusive version if available
    if (set instanceof StoredSortedKeySet) {
        return ((StoredSortedKeySet<String>) set).headSet(input, true);
    }
    if (set instanceof StoredSortedValueSet) {
        return ((StoredSortedValueSet<String>) set).headSet(input, true);
    }
    // Use synthetic "one above" trick
    // NOTE: because '\0' sorts in the middle in "java modified UTF-8",
    // used in the Stored* class StringBindings, this trick won't work
    // there
    return set.headSet(input + '\0');
}

From source file:org.kalypso.model.wspm.ui.profil.wizard.createDivider.CreateDividerOperation.java

private Integer[] mixExistingWithIntersectionPoint(final IProfile profil, final Integer intersectionIndex) {
    final Integer[] markerPoints = existingMarkersAsIndices(profil);
    final SortedSet<Integer> markerIndices = new TreeSet<>(Arrays.asList(markerPoints));

    // depends on the side of the profile!
    final IProfileRecord lowestPoint = ProfileVisitors.findLowestPoint(profil);
    if (Objects.isNull(lowestPoint))
        return new Integer[] { intersectionIndex };

    final Collection<Integer> result = new ArrayList<>(2);
    result.add(intersectionIndex);//from   w  w w.ja  va2s. com

    if (intersectionIndex > lowestPoint.getIndex()) {
        // use leftmost of all left markers
        final SortedSet<Integer> leftSet = markerIndices.headSet(lowestPoint.getIndex());
        if (!leftSet.isEmpty()) {
            result.add(leftSet.first());
        }
    } else {
        // use leftmost of all left markers
        final SortedSet<Integer> rightSet = markerIndices.tailSet(lowestPoint.getIndex());
        if (!rightSet.isEmpty()) {
            result.add(rightSet.last());
        }
    }

    return result.toArray(new Integer[result.size()]);
}

From source file:therian.operator.immutablecheck.DefaultImmutableChecker.java

private static void addTypeTo(final Set<Class<?>> target, final SortedSet<String> sortedSet) {
    addTypeTo(target, (Collection<?>) sortedSet);
    addTypeTo(target, (Set<String>) sortedSet.headSet("foo"));
    addTypeTo(target, (Set<String>) sortedSet.tailSet("foo"));
    addTypeTo(target, (Set<String>) sortedSet.subSet("foo", "foo"));
}