Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:elw.web.AdminController.java

@RequestMapping(value = "approve", method = RequestMethod.GET)
public ModelAndView do_approve(final HttpServletRequest req, final HttpServletResponse resp)
        throws IOException {
    return wmScore(req, resp, true, false, new WebMethodScore() {
        public ModelAndView handleScore(HttpServletRequest req, HttpServletResponse resp, Ctx ctx,
                FileSlot slot, Solution file, Long stamp, Map<String, Object> model) {
            final SortedMap<Long, Score> allScores = core.getQueries().scores(ctx, slot, file);

            final long stampEff = stamp == null ? allScores.lastKey() : stamp;
            final Score score = allScores.get(stampEff);

            model.put("stamp", stamp);
            model.put("score", score);
            model.put("slot", slot);
            model.put("file", file);

            return new ModelAndView("a/approve", model);
        }//  www.  jav  a  2s.  com
    });
}

From source file:org.opennaas.extensions.genericnetwork.capability.circuitstatistics.CircuitStatisticsCapability.java

private String writeToCSV(SortedMap<Long, List<CircuitStatistics>> circuitStatistics) throws IOException {

    StringBuilder sb = new StringBuilder();
    CSVWriter writer = new CSVWriter(new StringBuilderWriter(sb), CSVWriter.DEFAULT_SEPARATOR,
            CSVWriter.NO_QUOTE_CHARACTER);
    try {//from   w  w  w  . ja  va  2 s .c  om

        for (Long timestamp : circuitStatistics.keySet())

            for (CircuitStatistics currentStatistic : circuitStatistics.get(timestamp)) {

                String[] csvStatistic = new String[7];
                csvStatistic[0] = String.valueOf(timestamp);
                csvStatistic[1] = currentStatistic.getSlaFlowId();
                csvStatistic[2] = currentStatistic.getThroughput();
                csvStatistic[3] = currentStatistic.getPacketLoss();
                csvStatistic[4] = currentStatistic.getDelay();
                csvStatistic[5] = currentStatistic.getJitter();
                csvStatistic[6] = currentStatistic.getFlowData();

                writer.writeNext(csvStatistic);

            }

        return sb.toString();
    } finally {
        writer.close();
    }
}

From source file:com.jnj.b2b.core.search.solrfacetsearch.provider.impl.FirstVariantCategoryNameListValueProvider.java

/**
 * Add first level category from {@code variant} to {@code categoryValues}. If there is already a first level
 * category with higher precedence, nothing is added.
 *
 * @param categoryValues//from  w ww. j ava2s . co m
 *           The map to be populated.
 * @param variant
 *           The variant that contains the categories.
 */
protected void addCategories(
        final SortedMap<VariantValueCategoryModel, GenericVariantProductModel> categoryValues,
        final GenericVariantProductModel variant) {
    final List<VariantValueCategoryModel> currentCategoryValues = getVariantList(variant);
    if (!currentCategoryValues.isEmpty()) {
        boolean addCurrent = false;
        // if there is already a similar entry, check if current variant has higher priority
        final GenericVariantProductModel oldVariant = categoryValues.get(currentCategoryValues.get(0));
        if (oldVariant != null) {
            final List<VariantValueCategoryModel> oldCategoryValues = getVariantList(oldVariant);
            if (!oldCategoryValues.isEmpty()) {
                addCurrent = isCurrentListPrecedent(currentCategoryValues, oldCategoryValues);
            }
        } else {
            addCurrent = true;
        }
        if (addCurrent) {
            categoryValues.put(currentCategoryValues.get(0), variant);
        }
    }
}

From source file:org.apache.hadoop.hive.ql.udf.UDFIpInfo.java

private void putToIpTables(IpRange range) {
    Long range_end = range.getEndip();
    SortedMap<Long, IpRange> subList = ipTables.tailMap(range.getStartip());
    List<IpRange> rangeList = new ArrayList<IpRange>();
    for (Iterator<Long> it = subList.keySet().iterator(); it.hasNext();) {
        Long start = it.next();/*from   w  w  w .j a v  a  2  s .  c o m*/
        IpRange rang1 = subList.get(start);
        if (rang1.getStartip() <= range_end) {
            rangeList.add(rang1);
        }
    }

    for (int i = 0; i < rangeList.size(); i++) {
        IpRange rang1 = rangeList.get(i);
        this.ipTables.remove(rang1.getEndip());
        range = this.subSetRange(rang1, range);
        if (range == null) {
            break;
        }
    }
    if (range != null) {
        this.ipTables.put(range.getEndip(), range);
    }
}

From source file:org.cloudata.core.client.TabletLocationCache.java

private void removeFromCache(TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, TabletInfo removeTablet) {
    if (cache.containsKey(cacheRowKey)) {
        cache.remove(cacheRowKey);/*from   w ww . jav  a2s.  c  o  m*/
    }

    SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey);
    if (tailMap.isEmpty()) {
        return;
    }
    Row.Key tailFirst = tailMap.firstKey();

    TabletInfo tabletInfo = tailMap.get(tailFirst);

    if (tabletInfo.equals(removeTablet)) {
        cache.remove(tailFirst);
    }
}

From source file:jhttpp2.Jhttpp2ClientInputStream.java

/**
 * Parser for the first (!) line from the HTTP request<BR>
 * Sets up the URL, method and remote hostname.
 * //from ww  w .  ja v  a  2  s .  co  m
 * @return an InetAddress for the hostname, null on errors with a
 *         statuscode!=SC_OK
 */
public InetAddress parseRequest(String a, int method_index) {
    log.debug(a);
    String f;
    int pos;
    url = "";
    if (ssl) {
        f = a.substring(8);
    } else {
        method = a.substring(0, a.indexOf(" ")); // first word in the line
        pos = a.indexOf(":"); // locate first :
        if (pos == -1) { // occours with "GET / HTTP/1.1"
            url = a.substring(a.indexOf(" ") + 1, a.lastIndexOf(" "));
            if (method_index == 0) { // method_index==0 --> GET
                if (url.indexOf(server.WEB_CONFIG_FILE) != -1)
                    statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ;
                else
                    statuscode = Jhttpp2HTTPSession.SC_FILE_REQUEST;
            } else {
                if (method_index == 1 && url.indexOf(server.WEB_CONFIG_FILE) != -1) { // allow
                    // "POST"
                    // for
                    // admin
                    // log
                    // in
                    statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ;
                } else {
                    statuscode = Jhttpp2HTTPSession.SC_INTERNAL_SERVER_ERROR;
                    errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver.";
                }
            }
            return null;
        }
        f = a.substring(pos + 3); // removes "http://"
    }
    pos = f.indexOf(" "); // locate space, should be the space before
    // "HTTP/1.1"
    if (pos == -1) { // buggy request
        statuscode = Jhttpp2HTTPSession.SC_CLIENT_ERROR;
        errordescription = "Your browser sent an invalid request: \"" + a + "\"";
        return null;
    }
    f = f.substring(0, pos); // removes all after space
    // if the url contains a space... it's not our mistake...(url's must
    // never contain a space character)
    pos = f.indexOf("/"); // locate the first slash
    if (pos != -1) {
        url = f.substring(pos); // saves path without hostname
        f = f.substring(0, pos); // reduce string to the hostname
    } else
        url = "/"; // occurs with this request:
    // "GET http://localhost HTTP/1.1"
    pos = f.indexOf(":"); // check for the portnumber
    if (pos != -1) {
        String l_port = f.substring(pos + 1);
        l_port = l_port.indexOf(" ") != -1 ? l_port.substring(0, l_port.indexOf(" ")) : l_port;
        int i_port = 80;
        try {
            i_port = Integer.parseInt(l_port);
        } catch (NumberFormatException e_get_host) {
            server.writeLog("get_Host :" + e_get_host + " !!!!");
        }
        f = f.substring(0, pos);
        remote_port = i_port;
    } else
        remote_port = 80;
    remote_host_name = f;

    SortedMap<String, URL> map = server.getHostRedirects();
    for (String redirectHost : map.keySet()) {
        if (redirectHost.equals(remote_host_name)) {
            URL u = map.get(redirectHost);
            f = u.getHost();
            if (u.getPort() != -1) {
                remote_port = u.getPort();
            }
            log.debug("Redirecting host " + redirectHost + " to " + f + " port " + remote_port);
        }
    }
    InetAddress address = null;
    if (server.log_access)
        server.logAccess(connection.getLocalSocket().getInetAddress().getHostAddress() + " " + method + " "
                + getFullURL());
    try {
        address = InetAddress.getByName(f);
        if (remote_port == server.port && address.equals(InetAddress.getLocalHost())) {
            if (url.indexOf(server.WEB_CONFIG_FILE) != -1 && (method_index == 0 || method_index == 1))
                statuscode = Jhttpp2HTTPSession.SC_CONFIG_RQ;
            else if (method_index > 0) {
                statuscode = Jhttpp2HTTPSession.SC_INTERNAL_SERVER_ERROR;
                errordescription = "This WWW proxy supports only the \"GET\" method while acting as webserver.";
            } else
                statuscode = Jhttpp2HTTPSession.SC_FILE_REQUEST;
        }
    } catch (UnknownHostException e_u_host) {
        if (!server.use_proxy)
            statuscode = Jhttpp2HTTPSession.SC_HOST_NOT_FOUND;
    }
    return address;
}

From source file:org.apache.hadoop.hbase.regionserver.tableindexed.IndexedRegion.java

private BatchUpdate createIndexUpdate(IndexSpecification indexSpec, byte[] row,
        SortedMap<byte[], byte[]> columnValues) {
    byte[] indexRow = indexSpec.getKeyGenerator().createIndexKey(row, columnValues);
    BatchUpdate update = new BatchUpdate(indexRow);

    update.put(IndexedTable.INDEX_BASE_ROW_COLUMN, row);

    for (byte[] col : indexSpec.getIndexedColumns()) {
        byte[] val = columnValues.get(col);
        if (val == null) {
            throw new RuntimeException("Unexpected missing column value. [" + Bytes.toString(col) + "]");
        }/*from   ww w  .j  a va  2  s . co  m*/
        update.put(col, val);
    }

    for (byte[] col : indexSpec.getAdditionalColumns()) {
        byte[] val = columnValues.get(col);
        if (val != null) {
            update.put(col, val);
        }
    }

    return update;
}

From source file:org.apache.hadoop.yarn.util.Log4jWarningErrorMetricsAppender.java

private void updateMessageDetails(String message, Long eventTimeSeconds,
        Map<String, SortedMap<Long, Integer>> map, SortedMap<Long, Integer> timestampsCount,
        SortedSet<PurgeElement> purgeInformation) {
    synchronized (lock) {
        if (map.containsKey(message)) {
            SortedMap<Long, Integer> tmp = map.get(message);
            Long lastMessageTime = tmp.lastKey();
            int value = 1;
            if (tmp.containsKey(eventTimeSeconds)) {
                value = tmp.get(eventTimeSeconds) + 1;
            }//from   www .j  a  va 2  s . c  o  m
            tmp.put(eventTimeSeconds, value);
            purgeInformation.remove(new PurgeElement(message, lastMessageTime));
        } else {
            SortedMap<Long, Integer> value = new TreeMap<>();
            value.put(eventTimeSeconds, 1);
            map.put(message, value);
            if (map.size() > maxUniqueMessages * 2) {
                cleanupTimer.cancel();
                cleanupTimer = new Timer();
                cleanupTimer.schedule(new ErrorAndWarningsCleanup(), 0);
            }
        }
        purgeInformation.add(new PurgeElement(message, eventTimeSeconds));
        int newValue = 1;
        if (timestampsCount.containsKey(eventTimeSeconds)) {
            newValue = timestampsCount.get(eventTimeSeconds) + 1;
        }
        timestampsCount.put(eventTimeSeconds, newValue);
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step11GoldDataStatistics.java

/**
 * (1) Plain text with 4 columns: (1) the rank of the document in the list
 * (2) average agreement rate over queries (3) standard deviation of
 * agreement rate over queries. (4) average length of the document in the
 * rank./*  ww  w.  j a v  a 2 s.co  m*/
 */
public static void statistics1(File inputDir, File outputDir) throws Exception {
    SortedMap<Integer, DescriptiveStatistics> mapDocumentRankObservedAgreement = new TreeMap<>();
    SortedMap<Integer, DescriptiveStatistics> mapDocumentRankDocLength = new TreeMap<>();

    // iterate over query containers
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {
            // add new entries
            if (!mapDocumentRankObservedAgreement.containsKey(rankedResult.rank)) {
                mapDocumentRankObservedAgreement.put(rankedResult.rank, new DescriptiveStatistics());
            }
            if (!mapDocumentRankDocLength.containsKey(rankedResult.rank)) {
                mapDocumentRankDocLength.put(rankedResult.rank, new DescriptiveStatistics());
            }

            Double observedAgreement = rankedResult.observedAgreement;

            if (observedAgreement == null) {
                System.err
                        .println("Observed agreement is null; " + f.getName() + ", " + rankedResult.clueWebID);
            } else {
                // update value
                mapDocumentRankObservedAgreement.get(rankedResult.rank).addValue(observedAgreement);
                mapDocumentRankDocLength.get(rankedResult.rank).addValue(rankedResult.plainText.length());
            }
        }
    }

    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats1.csv")));
    for (Map.Entry<Integer, DescriptiveStatistics> entry : mapDocumentRankObservedAgreement.entrySet()) {
        pw.printf(Locale.ENGLISH, "%d\t%.4f\t%.4f\t%.4f\t%.4f%n", entry.getKey(), entry.getValue().getMean(),
                entry.getValue().getStandardDeviation(), mapDocumentRankDocLength.get(entry.getKey()).getMean(),
                mapDocumentRankDocLength.get(entry.getKey()).getStandardDeviation());
    }
    pw.close();
}

From source file:org.xwiki.annotation.internal.renderer.AnnotationGeneratorChainingListener.java

/**
 * Adds an annotation bookmark in this list of bookmarks.
 * /*w  w w .j a  va  2  s.c o  m*/
 * @param renderingEvent the rendering event where the annotation should be bookmarked
 * @param offset the offset of the annotation event inside this rendering event
 * @param annotationEvent the annotation event to bookmark
 */
protected void addBookmark(Event renderingEvent, AnnotationEvent annotationEvent, int offset) {
    SortedMap<Integer, List<AnnotationEvent>> mappings = bookmarks.get(renderingEvent);
    if (mappings == null) {
        mappings = new TreeMap<Integer, List<AnnotationEvent>>();
        bookmarks.put(renderingEvent, mappings);
    }
    List<AnnotationEvent> events = mappings.get(offset);
    if (events == null) {
        events = new LinkedList<AnnotationEvent>();
        mappings.put(offset, events);
    }

    addAnnotationEvent(annotationEvent, events);
}