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.jahia.services.render.scripting.bundle.BundleScriptResolver.java

/**
 * Returns view scripts for the specified module bundle which match the specified path.
 *
 * @param module     the module bundle to perform lookup in
 * @param pathPrefix the resource path prefix to match
 * @return a set of matching view scripts ordered by the extension (script type)
 *//*from  ww w.  j a  v a2s  .  co  m*/
private Set<ViewResourceInfo> findBundleScripts(String module, String pathPrefix) {
    final SortedMap<String, ViewResourceInfo> allBundleScripts = availableScripts.get(module);
    if (allBundleScripts == null || allBundleScripts.isEmpty()) {
        return Collections.emptySet();
    }

    // get all the ViewResourceInfos which path is greater than or equal to the given prefix
    final SortedMap<String, ViewResourceInfo> viewInfosWithPathGTEThanPrefix = allBundleScripts
            .tailMap(pathPrefix);

    // if the tail map is empty, we won't find the path prefix in the available scripts so return an empty set
    if (viewInfosWithPathGTEThanPrefix.isEmpty()) {
        return Collections.emptySet();
    }

    // check if the first key contains the prefix. If not, the prefix will not match any entries so return an empty set
    if (!viewInfosWithPathGTEThanPrefix.firstKey().startsWith(pathPrefix)) {
        return Collections.emptySet();
    } else {
        SortedSet<ViewResourceInfo> sortedScripts = new TreeSet<ViewResourceInfo>(scriptExtensionComparator);
        for (String path : viewInfosWithPathGTEThanPrefix.keySet()) {
            // we should have only few values to look at
            if (path.startsWith(pathPrefix)) {
                sortedScripts.add(viewInfosWithPathGTEThanPrefix.get(path));
            } else {
                // as soon as the path doesn't start with the given prefix anymore, we won't have a match in the remaining so return
                return sortedScripts;
            }
        }
        return sortedScripts;
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.feature.coreference.CoreferenceFeatures.java

@Override
protected List<Feature> extract(JCas jCas, Sentence sentence, String sentencePrefix)
        throws TextClassificationException {
    List<List<CoreferenceLink>> coreferenceChains = extractCoreferenceChains(jCas);

    FrequencyDistribution<String> featuresAcrossAllChains = new FrequencyDistribution<>();
    DescriptiveStatistics chainLength = new DescriptiveStatistics();
    DescriptiveStatistics distanceToPreviousSentence = new DescriptiveStatistics();
    DescriptiveStatistics distanceToNextSentence = new DescriptiveStatistics();
    DescriptiveStatistics interSentencesCorLinks = new DescriptiveStatistics();

    for (List<CoreferenceLink> chain : coreferenceChains) {

        SortedMap<Integer, List<CoreferenceLink>> sentencesAndLinks = extractSentencesAndLinksFromChain(chain,
                jCas);/*from w  w  w.  j  av a  2  s .c  o m*/

        int currentSentencePos = getCurrentSentencePos(jCas, sentence);

        log.debug(sentencesAndLinks.keySet() + ", current " + currentSentencePos);

        // is the sentence in chain that spans more sentences?
        boolean partOfChain = sentencesAndLinks.containsKey(currentSentencePos) && sentencesAndLinks.size() > 1;

        // is part of a chain?
        if (partOfChain) {
            log.debug(chainToString(chain));
            featuresAcrossAllChains.inc(FN_PART_OF_CHAIN);

            // starts the chain?
            if (sentencesAndLinks.firstKey().equals(currentSentencePos)) {
                featuresAcrossAllChains.inc(FN_STARTS_THE_CHAIN);
            } else if (sentencesAndLinks.lastKey().equals(currentSentencePos)) {
                // ends the chain?
                featuresAcrossAllChains.inc(FN_ENDS_THE_CHAIN);
            } else {
                // in the middle of chain?
                featuresAcrossAllChains.inc(FN_IN_THE_MIDDLE_OF_CHAIN);
            }

            // length of the chain
            chainLength.addValue(sentencesAndLinks.size());

            List<CoreferenceLink> currentSentenceLinks = sentencesAndLinks.get(currentSentencePos);
            CoreferenceLink currentSentenceFirstLink = currentSentenceLinks.get(0);
            CoreferenceLink currentSentenceLastLink = currentSentenceLinks.get(currentSentenceLinks.size() - 1);

            // transition to the previous link, i.e. NOMINAL -> PRONOMINAL
            if (!sentencesAndLinks.firstKey().equals(currentSentencePos)) {
                // find the previous sentence
                List<CoreferenceLink> previousSentenceLinks = null;
                int prevSentNo = currentSentencePos;
                while (previousSentenceLinks == null && prevSentNo >= 0) {
                    prevSentNo--;

                    if (sentencesAndLinks.containsKey(prevSentNo)) {
                        previousSentenceLinks = sentencesAndLinks.get(prevSentNo);
                    }
                }

                if (previousSentenceLinks == null) {
                    throw new IllegalStateException("Oops :))");
                }

                // distance to previous sentence
                distanceToPreviousSentence.addValue(currentSentencePos - prevSentNo);

                // get the last link from the previous sentence
                CoreferenceLink prevSentenceLastLink = previousSentenceLinks
                        .get(previousSentenceLinks.size() - 1);

                // add type type transition
                String prevSentenceLastLinkReferenceType = prevSentenceLastLink.getReferenceType();
                String currentSentenceFirstLinkReferenceType = currentSentenceFirstLink.getReferenceType();
                String transitionType = prevSentenceLastLinkReferenceType + GLUE
                        + currentSentenceFirstLinkReferenceType;
                featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TYPE_TYPE + transitionType, 1);

                // add token - type transition
                String glueCoreferenceCurrentSentence = glueCoreferenceLinkTokens(currentSentenceFirstLink);
                String typeToken = prevSentenceLastLinkReferenceType + GLUE + glueCoreferenceCurrentSentence;
                featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TYPE_TOKEN + typeToken, 1);

                // add type - token transition
                String glueCoreferencePrevSentence = glueCoreferenceLinkTokens(prevSentenceLastLink);
                String tokenType = glueCoreferencePrevSentence + GLUE + currentSentenceFirstLinkReferenceType;
                featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TYPE + tokenType, 1);

                // add token token transition
                String tokenToken = glueCoreferencePrevSentence + GLUE + glueCoreferenceCurrentSentence;
                featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TOKEN + tokenToken, 1);

                // exact matching token-token reference?
                if (glueCoreferencePrevSentence.equals(glueCoreferenceCurrentSentence)) {
                    featuresAcrossAllChains.addSample(FN_TRANSITION_IN_TOKEN_TOKEN_MATCH, 1);
                }
            }

            // transition to the previous link, i.e. NOMINAL -> PRONOMINAL
            if (!sentencesAndLinks.lastKey().equals(currentSentencePos)) {
                // find the previous sentence
                List<CoreferenceLink> nextSentenceLinks = null;
                int nextSentNo = currentSentencePos;
                while (nextSentenceLinks == null && nextSentNo <= sentencesAndLinks.lastKey()) {
                    nextSentNo++;

                    if (sentencesAndLinks.containsKey(nextSentNo)) {
                        nextSentenceLinks = sentencesAndLinks.get(nextSentNo);
                    }
                }

                if (nextSentenceLinks == null) {
                    throw new IllegalStateException("Oops :))");
                }

                // distance to next sentence
                distanceToNextSentence.addValue(nextSentNo - currentSentencePos);

                // get the last link from the previous sentence
                CoreferenceLink nextSentenceFirstLink = nextSentenceLinks.get(0);

                // add type type transition
                String currentSentenceLastLinkReferenceType = currentSentenceLastLink.getReferenceType();
                String nextSentenceFirstLinkReferenceType = nextSentenceFirstLink.getReferenceType();
                String transitionType = currentSentenceLastLinkReferenceType + GLUE
                        + nextSentenceFirstLinkReferenceType;
                featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TYPE_TYPE + transitionType, 1);

                // add token - type transition
                String glueCoreferenceCurrentSent = glueCoreferenceLinkTokens(currentSentenceLastLink);
                String typeToken = glueCoreferenceCurrentSent + GLUE + nextSentenceFirstLinkReferenceType;
                featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TYPE + typeToken, 1);

                // add type - token transition
                String glueCoreferenceNextSent = glueCoreferenceLinkTokens(nextSentenceFirstLink);
                String tokenType = currentSentenceLastLinkReferenceType + GLUE + glueCoreferenceNextSent;
                featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TYPE_TOKEN + tokenType, 1);

                // add token token transition
                String tokenToken = glueCoreferenceCurrentSent + GLUE + glueCoreferenceNextSent;
                featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TOKEN + tokenToken, 1);

                // exact matching token-token reference?
                if (glueCoreferenceNextSent.equals(glueCoreferenceCurrentSent)) {
                    featuresAcrossAllChains.addSample(FN_TRANSITION_OUT_TOKEN_TOKEN_MATCH, 1);
                }
            }
        }

        // number of inter-sentence coreference links
        if (sentencesAndLinks.containsKey(currentSentencePos)) {
            int coreferenceLinks = sentencesAndLinks.get(currentSentencePos).size();
            interSentencesCorLinks.addValue(coreferenceLinks);
        }

        /*
        List<Integer> positions = positionsOfSentenceInCurrentChain(chain, sentence);
                
        // ok, we're in a chain
        if (!positions.isEmpty()) {
        log.debug(printChain(chain));
        log.debug(sentence.getCoveredText());
        log.debug(positions);
        Integer lastPosition = positions.get(positions.size() - 1);
        Integer firstPosition = positions.get(0);
                
        if (lastPosition == positions.size() - 1) {
            log.debug("Last sentence of chain");
        }
                
        log.debug("-----");
        }
        */
    }

    List<Feature> result = new ArrayList<>();

    log.debug(featuresAcrossAllChains);
    if (distanceToNextSentence.getN() > 0) {
        log.debug("Next:" + distanceToNextSentence);

        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_MIN,
                distanceToNextSentence.getMin()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_MAX,
                distanceToNextSentence.getMax()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_NEXT_AVG,
                distanceToNextSentence.getMean()));
    }
    if (distanceToPreviousSentence.getN() > 0) {

        log.debug("Prev: " + distanceToPreviousSentence);

        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_MIN,
                distanceToPreviousSentence.getMin()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_MAX,
                distanceToPreviousSentence.getMax()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_DIST_TO_PREV_AVG,
                distanceToPreviousSentence.getMean()));
    }

    if (interSentencesCorLinks.getN() > 0) {
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_MIN,
                interSentencesCorLinks.getMin()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_MAX,
                interSentencesCorLinks.getMax()));
        result.add(new Feature(sentencePrefix + FEATURE_NAME + FN_INTER_SENT_COR_AVG,
                interSentencesCorLinks.getMean()));
    }

    log.debug("----");

    for (String feat : featuresAcrossAllChains.getKeys()) {
        // binary
        result.add(new Feature(sentencePrefix + FEATURE_NAME + feat, 1));
    }

    return result;
}

From source file:edu.umd.cfar.lamp.viper.util.Range.java

/**
 * Checks to see if the interval defined as [s,e)
 * is entirely contained within this Range object.
 * //from ww w .j ava  2s.  c  om
 * @param s
 * @param e
 * @return boolean
 */
public boolean withinRange(Comparable s, Comparable e) {
    SortedMap m = spans.headMap(e);
    if (!m.isEmpty()) {
        // thankfully Range keeps contiguous spans merged,
        // so this is easy
        Comparable start = (Comparable) m.lastKey();
        Comparable end = (Comparable) m.get(start);
        if (end.compareTo(s) >= 0) {
            return start.compareTo(s) <= 0 && end.compareTo(e) >= 0;
        }
    }
    m = spans.tailMap(s);
    if (!m.isEmpty()) {
        Comparable sPrime = (Comparable) m.firstKey();
        if (sPrime.compareTo(s) == 0) {
            return e.compareTo((Comparable) m.get(sPrime)) <= 0;
        }
    }
    return false;
}

From source file:org.wrml.runtime.rest.DefaultApiLoader.java

protected Object decipherDocumentSurrogateKeyValue(final URI uri, final Prototype prototype) {

    final ApiNavigator apiNavigator = getParentApiNavigator(uri);

    if (apiNavigator == null) {
        return null;
    }// ww  w . jav a  2  s .  c o  m

    final SortedSet<Parameter> surrogateKeyComponents = apiNavigator.getSurrogateKeyComponents(uri, prototype);
    if (surrogateKeyComponents == null || surrogateKeyComponents.isEmpty()) {
        return null;
    }

    final Set<String> allKeySlotNames = prototype.getAllKeySlotNames();

    final Object surrogateKeyValue;
    if (surrogateKeyComponents.size() == 1) {
        final Parameter surrogateKeyPair = surrogateKeyComponents.first();

        final String slotName = surrogateKeyPair.getName();
        if (!allKeySlotNames.contains(slotName)) {
            return null;
        }

        final String slotTextValue = surrogateKeyPair.getValue();
        final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

        surrogateKeyValue = slotValue;
    } else {

        final SortedMap<String, Object> keySlots = new TreeMap<String, Object>();

        for (final Parameter surrogateKeyPair : surrogateKeyComponents) {

            final String slotName = surrogateKeyPair.getName();
            if (!allKeySlotNames.contains(slotName)) {
                continue;
            }

            final String slotTextValue = surrogateKeyPair.getValue();
            final Object slotValue = parseSlotValueSyntacticText(prototype, slotName, slotTextValue);

            if (slotValue == null) {
                continue;
            }

            keySlots.put(slotName, slotValue);

        }

        if (keySlots.size() == 1) {
            surrogateKeyValue = keySlots.get(keySlots.firstKey());
        } else {
            surrogateKeyValue = new CompositeKey(keySlots);
        }
    }

    return surrogateKeyValue;

}

From source file:org.jahia.services.templates.JahiaTemplateManagerService.java

public boolean differentModuleWithSameIdExists(String symbolicName, String groupId) {
    SortedMap<ModuleVersion, JahiaTemplatesPackage> moduleVersions = templatePackageRegistry
            .getAllModuleVersions().get(symbolicName);
    return moduleVersions != null && !moduleVersions.isEmpty()
            && !moduleVersions.get(moduleVersions.firstKey()).getGroupId().equals(groupId);
}

From source file:ocr.sapphire.image.EdgeBasedImagePreprocessor.java

private Point[][] findEdgePoints(int[] edgeData) {
    List<Deque<Point>> components = new ArrayList<Deque<Point>>();
    // find close paths
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (edgeData[x + y * width] == BLACK && isBridge(edgeData, x, y)) {
                edgeData[x + y * width] = WHITE;
                Deque<Point> firstPart = null, secondPart = null;
                for (int k = 0; k < DX.length; k++) {
                    int x2 = x + DX[k];
                    int y2 = y + DY[k];
                    if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) {
                        continue;
                    }//from   w w  w .  j a v a 2s .  co  m
                    if (edgeData[x2 + y2 * width] == BLACK) {
                        Deque<Point> points = findConnectedComponent(edgeData, x2, y2);
                        if (firstPart == null) {
                            firstPart = points;
                        } else {
                            secondPart = points;
                        }
                    }
                }
                firstPart.addFirst(new Point(x, y));
                if (secondPart != null) { // the path is not closed
                    join(firstPart, true, secondPart, true);
                }
                components.add(firstPart);
            }
        }
    }

    // remove contained components
    for (int i = 0; i < components.size() - 1; i++) {
        Rectangle r1 = getBounds(components.get(i));
        for (int j = i + 1; j < components.size();) {
            Rectangle r2 = getBounds(components.get(j));
            if (r1.contains(r2)) {
                components.remove(j);
            } else if (r2.contains(r1)) {
                components.set(i, components.get(j));
                components.remove(j);
            } else {
                j++;
            }
        }
    }

    // try to connect some paths
    int connectedCount;
    do {
        connectedCount = 0;
        for (int i = 0; i < components.size() - 1; i++) {
            for (int j = i + 1; j < components.size(); j++) {
                Deque<Point> a = components.get(i);
                Deque<Point> b = components.get(j);

                double d0 = d(a.getFirst(), a.getLast()) + d(b.getFirst(), b.getLast());
                double d1 = d(a.getFirst(), b.getFirst()) + d(a.getLast(), b.getLast());
                double d2 = d(a.getFirst(), b.getLast()) + d(a.getLast(), b.getFirst());
                double d3 = d(a.getFirst(), b.getFirst());
                double d4 = d(a.getFirst(), b.getLast());
                double d5 = d(a.getLast(), b.getFirst());
                double d6 = d(a.getLast(), b.getLast());

                if (d3 <= CLOSE_THRESHOLD && d3 <= d4) {
                    join(a, true, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d4 <= CLOSE_THRESHOLD && d4 <= d3) {
                    join(a, true, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d5 <= CLOSE_THRESHOLD && d5 <= d6) {
                    join(a, false, b, true);
                    components.remove(j);
                    connectedCount++;
                } else if (d6 <= CLOSE_THRESHOLD && d6 <= d5) {
                    join(a, false, b, false);
                    components.remove(j);
                    connectedCount++;
                } else if (d1 <= d0 && d1 <= d2) {
                    if (d3 < d6) {
                        join(a, true, b, true);
                    } else {
                        join(a, false, b, false);
                    }
                    components.remove(j);
                    connectedCount++;
                } else if (d2 <= d0 && d2 <= d1) {
                    if (d4 < d5) {
                        join(a, true, b, false);
                    } else {
                        join(a, false, b, true);
                    }
                    components.remove(j);
                    connectedCount++;
                }
            } // end of for j
        } // end of for i
    } while (connectedCount > 0);

    // choose (componentCount) biggest components
    SortedMap<Integer, Deque<Point>> componentMap = new TreeMap<Integer, Deque<Point>>();
    for (Deque<Point> c : components) {
        componentMap.put(-c.size(), c);
    }

    // remove noise
    boolean firstPoint = true;
    for (Iterator<Entry<Integer, Deque<Point>>> iterator = componentMap.entrySet().iterator(); iterator
            .hasNext();) {
        Entry<Integer, Deque<Point>> entry = iterator.next();
        Rectangle r = getBounds(entry.getValue());
        if (r.width <= 10 && r.height <= 10) {
            if (firstPoint) {
                firstPoint = false;
            } else {
                iterator.remove();
            }
        }
    }

    // convert components: normalize points, to array
    int foundComponentCount = Math.min(componentCount, componentMap.size());
    componentArr = new Point[foundComponentCount][];
    Rectangle r = getBounds(componentMap.get(componentMap.firstKey()));
    for (int c = 0; c < foundComponentCount; c++) {
        int key = componentMap.firstKey();
        componentArr[c] = new Point[componentMap.get(key).size()];
        normalize(componentMap.get(key)).toArray(componentArr[c]);
        componentMap.remove(key);

        for (int i = 0; i < componentArr[c].length; i++) {
            componentArr[c][i].x = (componentArr[c][i].x - r.x) / r.width;
            componentArr[c][i].y = (componentArr[c][i].y - r.y) / r.height;
        }
    }
    return componentArr;
}

From source file:okuyama.imdst.util.DataDispatcher.java

/**
 * Rule?????????KeyNode?????????.<br>
 * ConsistentHash.<br>//from w w  w  .  j  av  a 2s .  c o  m
 * ????????????????6?Third????9??<br>
 *
 * @param key 
 * @param useOldCircle 
 * @return String[] ?(??????)
 */
private static String[] decisionConsistentHashKeyNode(String key, boolean useOldCircle) {
    String[] ret = null;
    boolean noWaitFlg = false;
    SortedMap useNodeCircle = null;
    String targetNode = null;
    String[] mainDataNodeInfo = null;
    String[] slaveDataNodeInfo = null;
    String[] thirdDataNodeInfo = null;

    // ??
    String[][] allNodeDetailList = (String[][]) keyNodeMap.get("list");

    // Key?Hash?
    int execKeyInt = sha1Hash4Int(key);

    // ??
    // useOldCircle???????
    if (useOldCircle && oldCircle != null) {
        useNodeCircle = oldCircle;
    } else {
        useNodeCircle = nodeCircle;
    }

    // ?
    int hash = sha1Hash4Int(key);

    if (!useNodeCircle.containsKey(hash)) {
        SortedMap<Integer, Map> tailMap = useNodeCircle.tailMap(hash);
        if (tailMap.isEmpty()) {
            hash = ((Integer) useNodeCircle.firstKey()).intValue();
        } else {
            hash = ((Integer) tailMap.firstKey()).intValue();
        }
    }

    // ???
    targetNode = (String) useNodeCircle.get(hash);

    // ??
    mainDataNodeInfo = (String[]) keyNodeMap.get(targetNode);
    // ??
    slaveDataNodeInfo = (String[]) keyNodeMap.get(targetNode + "_sub");
    // ??
    thirdDataNodeInfo = (String[]) keyNodeMap.get(targetNode + "_third");

    // ????????
    if (thirdDataNodeInfo != null) {
        ret = new String[9];

        ret[3] = slaveDataNodeInfo[0];
        ret[4] = slaveDataNodeInfo[1];
        ret[5] = slaveDataNodeInfo[2];
        ret[6] = thirdDataNodeInfo[0];
        ret[7] = thirdDataNodeInfo[1];
        ret[8] = thirdDataNodeInfo[2];

    } else if (slaveDataNodeInfo != null) {
        // ????????
        ret = new String[6];

        ret[3] = slaveDataNodeInfo[0];
        ret[4] = slaveDataNodeInfo[1];
        ret[5] = slaveDataNodeInfo[2];
    } else {
        ret = new String[3];
    }

    ret[0] = mainDataNodeInfo[0];
    ret[1] = mainDataNodeInfo[1];
    ret[2] = mainDataNodeInfo[2];

    // ??????????(???)
    // ????????Wait
    while (true) {
        noWaitFlg = false;
        // ????
        if (ret.length == 3) {
            if (!StatusUtil.isWaitStatus(mainDataNodeInfo[2]))
                noWaitFlg = true;
        }

        if (ret.length == 6) {
            if (!StatusUtil.isWaitStatus(mainDataNodeInfo[2])
                    && !StatusUtil.isWaitStatus(slaveDataNodeInfo[2])) {

                noWaitFlg = true;
            }
        }

        if (ret.length == 9) {
            if (!StatusUtil.isWaitStatus(mainDataNodeInfo[2]) && !StatusUtil.isWaitStatus(slaveDataNodeInfo[2])
                    && !StatusUtil.isWaitStatus(thirdDataNodeInfo[2])) {

                noWaitFlg = true;
            }
        }

        if (noWaitFlg)
            break;

        try {
            //System.out.println("DataDispatcher - ?");
            Thread.sleep(50);
        } catch (Exception e) {
        }
    }

    // ??
    // ?MasterManagerHelper??
    StatusUtil.addNodeUse(mainDataNodeInfo[2]);

    if (ret.length > 3) {
        StatusUtil.addNodeUse(slaveDataNodeInfo[2]);
    }

    if (ret.length > 6) {
        StatusUtil.addNodeUse(thirdDataNodeInfo[2]);
    }

    return ret;
}

From source file:fr.landel.utils.commons.MapUtils2Test.java

/**
 * Test method for//from www.ja va  2s.  c  o  m
 * {@link MapUtils2#newMap(java.util.function.Supplier, java.lang.Class, java.lang.Class, java.lang.Object[])}.
 */
@Test
public void testNewMapSupplierClass() {
    SortedMap<String, Long> map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key1", 1L, "key2",
            2L);

    assertTrue(map instanceof TreeMap);
    assertEquals(2, map.size());

    Map<String, Long> expectedMap = new HashMap<>();
    expectedMap.put("key1", 1L);
    expectedMap.put("key2", 2L);

    for (Entry<String, Long> entry : expectedMap.entrySet()) {
        assertTrue(map.containsKey(entry.getKey()));
        assertEquals(entry.getValue(), map.get(entry.getKey()));
    }

    map = MapUtils2.newMap(TreeMap::new, String.class, Long.class);

    assertTrue(map instanceof TreeMap);
    assertTrue(map.isEmpty());

    map = MapUtils2.newMap(() -> new TreeMap<>(Comparators.STRING.desc()), String.class, Long.class, "key1", 1L,
            "key2", 2L, null, 3L, "key4", null, 2d, 5L, "key6", true);

    assertTrue(map instanceof TreeMap);
    assertEquals(4, map.size());

    "key2".equals(map.firstKey());

    map = MapUtils2.newMap(TreeMap::new, String.class, Long.class, new Object[0]);

    assertTrue(map instanceof TreeMap);
    assertTrue(map.isEmpty());

    assertException(() -> {
        MapUtils2.newMap(TreeMap::new, null, Long.class, "", "");
    }, NullPointerException.class);

    assertException(() -> {
        MapUtils2.newMap(TreeMap::new, String.class, null, "", "");
    }, NullPointerException.class);

    assertException(() -> {
        MapUtils2.newMap(null, String.class, Long.class, "", "");
    }, NullPointerException.class);

    assertException(() -> {
        MapUtils2.newMap(TreeMap::new, String.class, Long.class, (Object[]) null);
    }, IllegalArgumentException.class,
            "objects cannot be null or empty and has to contain an odd number of elements");

    assertException(() -> {
        MapUtils2.newMap(TreeMap::new, String.class, Long.class, "key");
    }, IllegalArgumentException.class,
            "objects cannot be null or empty and has to contain an odd number of elements");
}

From source file:org.onebusaway.community_transit_gtfs.CommunityTransitGtfsFactory.java

private void processStopTimesForTrip(Map<String, Integer> timepointPositions, PttTrip pttTrip, String tripIdRaw,
        RouteStopSequence stopSequence, Trip trip) throws ParseException {

    SortedMap<Integer, Integer> arrivalTimesByTimepointPosition = computeTimepointPositionToScheduleTimep(
            pttTrip);//from   w w  w  .  ja v  a  2  s.  co m
    List<StopTime> stopTimes = new ArrayList<StopTime>();

    if (arrivalTimesByTimepointPosition.size() < 2) {
        _log.warn("less than two timepoints specified for trip: id=" + trip.getId());
        return;
    }

    int firstTimepointPosition = arrivalTimesByTimepointPosition.firstKey();
    int lastTimepointPosition = arrivalTimesByTimepointPosition.lastKey();

    int firstStopIndex = Integer.MAX_VALUE;
    int lastStopIndex = Integer.MIN_VALUE;

    /**
     * Find the bounds on the set of stops that have stop times defined
     */
    List<RouteStopSequenceItem> items = stopSequence.getItems();

    for (int index = 0; index < items.size(); index++) {
        RouteStopSequenceItem item = items.get(index);
        Integer time = getScheduledTimeForTimepoint(item, timepointPositions, arrivalTimesByTimepointPosition);

        if (time != null) {
            firstStopIndex = Math.min(firstStopIndex, index);
            lastStopIndex = Math.max(lastStopIndex, index);
        }
    }

    StopTime first = null;
    StopTime last = null;

    for (int index = firstStopIndex; index < lastStopIndex + 1; index++) {
        RouteStopSequenceItem item = items.get(index);

        Integer time = getScheduledTimeForTimepoint(item, timepointPositions, arrivalTimesByTimepointPosition);
        Stop stop = _dao.getStopForId(id(Long.toString(item.getStopId())));

        StopTime stopTime = new StopTime();
        stopTime.setStop(stop);
        stopTime.setStopSequence(index - firstStopIndex);
        stopTime.setTrip(trip);
        if ("N".equals(item.getBoarding())) {
            // timepoint -- not for pickup/drop off
            stopTime.setDropOffType(1);
            stopTime.setPickupType(1);
        }

        if (time != null) {
            stopTime.setArrivalTime(time);
            stopTime.setDepartureTime(time);
        }

        _dao.saveEntity(stopTime);
        stopTimes.add(stopTime);

        if (first == null)
            first = stopTime;
        last = stopTime;
    }

    if (this._interpolateStopTimes) {
        List<ShapePoint> shapePoints = findShapes(trip.getShapeId());
        List<StopTimeEntryImpl> stopTimeEntries = ensureStopTimesHaveShapeDistanceTraveledSet(trip.getShapeId(),
                stopTimes, shapePoints);
        ensureStopTimesHaveTimesSet(stopTimes, stopTimeEntries);
        // now copy values back to stopTime models
        int i = 0;
        for (StopTimeEntryImpl e : stopTimeEntries) {
            StopTime m = stopTimes.get(i);
            m.setArrivalTime(e.getArrivalTime());
            m.setDepartureTime(e.getDepartureTime());
            i++;
        }

        if (!first.isDepartureTimeSet()) {
            _log.warn("departure time for first StopTime is not set: stop=" + first.getStop().getId() + " trip="
                    + tripIdRaw + " firstPosition=" + firstTimepointPosition + " lastPosition="
                    + lastTimepointPosition);
            for (RouteStopSequenceItem item : stopSequence)
                _log.warn("  stop=" + item.getStopId() + " timepoint=" + item.getTimePoint() + " pos="
                        + timepointPositions.get(item.getTimePoint()));
        }

        if (!last.isArrivalTimeSet()) {
            _log.warn("arrival time for last StopTime is not set: stop=" + last.getStop().getId() + " trip="
                    + tripIdRaw + " firstPosition=" + firstTimepointPosition + " lastPosition="
                    + lastTimepointPosition);
            for (RouteStopSequenceItem item : stopSequence)
                _log.warn("  stop=" + item.getStopId() + " timepoint=" + item.getTimePoint() + " pos="
                        + timepointPositions.get(item.getTimePoint()));
        }
    }
}

From source file:hudson.model.Job.java

/**
 * Gets the latest build #m that satisfies <tt>m&lt;=n</tt>.
 * /*from w  w w . ja  va  2s  . c o m*/
 * This is useful when you'd like to fetch a build but the exact build might
 * be already gone (deleted, rotated, etc.)
 * @see LazyBuildMixIn#getNearestOldBuild
 */
public RunT getNearestOldBuild(int n) {
    SortedMap<Integer, ? extends RunT> m = _getRuns().tailMap(n);
    if (m.isEmpty())
        return null;
    return m.get(m.firstKey());
}