Example usage for java.util SortedMap firstKey

List of usage examples for java.util SortedMap firstKey

Introduction

In this page you can find the example usage for java.util SortedMap firstKey.

Prototype

K firstKey();

Source Link

Document

Returns the first (lowest) key currently in this map.

Usage

From source file:org.sakuli.services.forwarder.gearman.model.NagiosCheckResultTest.java

@Test
public void testGetPayload() throws Exception {

    NagiosCheckResult checkResult = testling.build();

    SortedMap<PayLoadFields, String> map = checkResult.getPayload();
    Assert.assertEquals(map.firstKey(), PayLoadFields.TYPE);
    Assert.assertEquals(map.lastKey(), PayLoadFields.OUTPUT);
}

From source file:CacheMap.java

/**
 * Search a key that starts with the specified prefix from the map, and
 * return the value corresponding to the key.
 * /*from  www .ja  v  a  2s. c  o m*/
 * @param prefix
 *            target prefix
 * @return the value whose key starts with prefix, or null if not available
 */
public Object matchStartsWith(String prefix) {
    SortedMap<String, Object> smap = super.tailMap(prefix);
    Object okey;
    try {
        okey = smap.firstKey();
    } catch (NoSuchElementException e) {
        return null;
    }
    if (!(okey instanceof String))
        return null;
    String key = (String) okey;
    // System.err.println("MSW:" + key + " / " + prefix);
    if (!key.startsWith(prefix))
        return null;
    return super.get(key);
}

From source file:FocusTraversalExample.java

public Component getFirstComponent(Container focusCycleRoot) {
    SortedMap buttons = getSortedButtons(focusCycleRoot);
    if (buttons.isEmpty()) {
        return null;
    }// w w  w . j a  va  2 s. c om
    return (Component) buttons.get(buttons.firstKey());
}

From source file:com.boozallen.cognition.ingest.storm.vo.Entity.java

/**
 * Use the provided <code>row</code> to fill in the fields of this entity.
 *
 * @param row/*  w  w  w.ja v a  2 s.  com*/
 */
@Override
public void populate(SortedMap<Key, Value> row) {
    id = row.firstKey().getRow().toString();
    metaProps = readMap(row, "meta", true);
    properties = readMap(row, "item", true);
}

From source file:com.octo.mbo.domain.ApproachingMatcher.java

public Optional<String> findBestMatch(Collection<String> srcSlidesKeys, Collection<String> tgtSlideKeys,
        String tgtKeyToMatch) {/* w  w w.  ja  v a 2s  .  c o m*/
    assert srcSlidesKeys != null;
    assert tgtSlideKeys != null;
    assert tgtKeyToMatch != null;

    SortedMap<Integer, Set<String>> sortedSrcSlidesKeys = sortByDistanceWithKey(srcSlidesKeys, tgtKeyToMatch);
    int smallestDistanceBtwTgtKeyToMatchAndSrcKey = sortedSrcSlidesKeys.firstKey();
    Set<String> potentialKeys = sortedSrcSlidesKeys.get(smallestDistanceBtwTgtKeyToMatchAndSrcKey);
    if (potentialKeys.size() > 1) {
        log.warn("Tgt key '{}' could both match {} with levenstein distance {}", tgtKeyToMatch, potentialKeys,
                smallestDistanceBtwTgtKeyToMatchAndSrcKey);
        return Optional.empty();
    } else {
        String potentialKey = potentialKeys.iterator().next();
        //Be sure that this potential key is to at the equal distance of another tgtKey
        SortedMap<Integer, Set<String>> sortedTgtSlideKeys = sortByDistanceWithKey(tgtSlideKeys, potentialKey);
        int smallestDistanceBtwPotentialKeyAndTgtKey = sortedTgtSlideKeys.firstKey();
        Set<String> potentialTgtKeys = sortedTgtSlideKeys.get(smallestDistanceBtwPotentialKeyAndTgtKey);
        if (potentialTgtKeys.size() > 1) {
            log.warn(
                    "Potential Src key '{}' matching Tgt keys {} could both match TgtKeys {} with levenstein distance {}",
                    tgtKeyToMatch, potentialKeys, potentialTgtKeys, smallestDistanceBtwTgtKeyToMatchAndSrcKey);
            return Optional.empty();
        } else {
            String potentialTgtKey = potentialTgtKeys.iterator().next();
            if (potentialTgtKey.equals(tgtKeyToMatch)) {
                log.info("Src key '{}' has been associated with Tgt key '{}'", potentialKey, potentialTgtKey);
                return Optional.of(potentialKey);
            } else {
                log.warn(
                        "Potential Src key '{}' matches Tgt key '{}' with distance '{}' with is different from the Tgt we looked up '{}'",
                        potentialKey, potentialTgtKey, smallestDistanceBtwPotentialKeyAndTgtKey, tgtKeyToMatch);
                return Optional.empty();
            }
        }
    }
}

From source file:org.apache.hadoop.chukwa.util.DumpChunks.java

protected void displayResults(PrintStream out) throws IOException {
    for (Map.Entry<String, SortedMap<Long, ChunkImpl>> streamE : matchCatalog.entrySet()) {
        String header = streamE.getKey();
        SortedMap<Long, ChunkImpl> stream = streamE.getValue();
        long nextToPrint = 0;
        if (stream.firstKey() > 0)
            System.err.println("---- map starts at " + stream.firstKey());
        for (Map.Entry<Long, ChunkImpl> e : stream.entrySet()) {
            if (e.getKey() >= nextToPrint) {
                if (e.getKey() > nextToPrint)
                    System.err.println("---- printing bytes starting at " + e.getKey());

                out.write(e.getValue().getData());
                nextToPrint = e.getValue().getSeqID();
            } else if (e.getValue().getSeqID() < nextToPrint) {
                continue; //data already printed
            } else {
                //tricky case: chunk overlaps with already-printed data, but not completely
                ChunkImpl c = e.getValue();
                long chunkStartPos = e.getKey();
                int numToPrint = (int) (c.getSeqID() - nextToPrint);
                int printStartOffset = (int) (nextToPrint - chunkStartPos);
                out.write(c.getData(), printStartOffset, numToPrint);
                nextToPrint = c.getSeqID();
            }//from  w ww  . java  2  s  .  co m
        }
        out.println("\n--------" + header + "--------");
    }
}

From source file:org.jactr.core.queue.collection.PrioritizedQueue.java

/**
 * first key after afterPriority, or NaN
 * //from ww  w  . j  a va  2  s . c  o  m
 * @param afterPriority
 * @return
 */
synchronized public double getFirstPriorityAfter(double afterPriority) {
    SortedMap<Double, Collection<T>> submap = _backingMap.subMap(_backingMap.firstKey(), afterPriority);
    if (!submap.isEmpty())
        return submap.firstKey();
    return Double.NaN;
}

From source file:com.openkappa.rst.Classifier.java

private Container findWithPrefix(int attributeIndex, String prefix) {
    SortedMap<String, Container> prefixMap = criteria[attributeIndex].prefixMap(prefix);
    if (null == prefixMap || prefixMap.isEmpty()) {
        return fallback(attributeIndex);
    }/*from w w  w  .j  a va2 s  . c  o  m*/
    return prefixMap.get(prefixMap.firstKey());
}

From source file:gridool.routing.strategy.ConsistentHash.java

public GridNode get(@Nonnull byte[] key) {
    if (circle.isEmpty()) {
        return null;
    }/*from  ww  w.  j ava  2  s  .  c  om*/
    Long hash = hashFunction.hash(key);
    GridNode node = circle.get(hash);
    if (node != null) {
        return node;
    }
    SortedMap<Long, GridNode> tailMap = circle.tailMap(hash);
    hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey();
    return circle.get(hash);
}

From source file:org.archive.crawler.processor.LexicalCrawlMapper.java

/**
 * Look up the crawler node name to which the given CrawlURI 
 * should be mapped. //ww  w.  j ava2 s .co  m
 * 
 * @param cauri CrawlURI to consider
 * @return String node name which should handle URI
 */
protected String map(CrawlURI cauri) {
    // get classKey, via frontier to generate if necessary
    String classKey = frontier.getClassKey(cauri);
    SortedMap<String, String> tail = map.tailMap(classKey);
    if (tail.isEmpty()) {
        // wraparound
        tail = map;
    }
    // target node is value of nearest subsequent key
    return (String) tail.get(tail.firstKey());
}