Example usage for java.util TreeMap put

List of usage examples for java.util TreeMap put

Introduction

In this page you can find the example usage for java.util TreeMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:com.eucalyptus.objectstorage.pipeline.handlers.S3Authentication.java

/**
 * Query params are included in cases of Query-String/Presigned-url auth where they are considered just like headers
 * //www . j a v a2s .  c  o  m
 * @param httpRequest
 * @param includeQueryParams
 * @return
 */
private static String getCanonicalizedAmzHeaders(MappingHttpRequest httpRequest, boolean includeQueryParams) {
    String result = "";
    Set<String> headerNames = httpRequest.getHeaderNames();
    TreeMap<String, String> amzHeaders = new TreeMap<String, String>();
    for (String headerName : headerNames) {
        String headerNameString = headerName.toLowerCase().trim();
        if (headerNameString.startsWith("x-amz-")) {
            String value = httpRequest.getHeader(headerName).trim();
            String[] parts = value.split("\n");
            value = "";
            for (String part : parts) {
                part = part.trim();
                value += part + " ";
            }
            value = value.trim();
            if (amzHeaders.containsKey(headerNameString)) {
                String oldValue = (String) amzHeaders.remove(headerNameString);
                oldValue += "," + value;
                amzHeaders.put(headerNameString, oldValue);
            } else {
                amzHeaders.put(headerNameString, value);
            }
        }
    }

    if (includeQueryParams) {
        // For query-string auth, header values may include 'x-amz-*' that need to be signed
        for (String paramName : httpRequest.getParameters().keySet()) {
            processHeaderValue(paramName, httpRequest.getParameters().get(paramName), amzHeaders);
        }
    }

    // Build the canonical string
    Iterator<String> iterator = amzHeaders.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = (String) amzHeaders.get(key);
        result += key + ":" + value + "\n";
    }
    return result;
}

From source file:org.wso2.carbon.metrics.impl.JDBCCleanupTest.java

private <T> SortedMap<String, T> map(String name, T metric) {
    final TreeMap<String, T> map = new TreeMap<String, T>();
    map.put(name, metric);
    return map;//w w w .j av a 2s  .c  o m
}

From source file:com.turn.splicer.Config.java

public void writeAsJson(JsonGenerator jgen) throws IOException {
    if (properties == null) {
        jgen.writeStartObject();/*  w  ww. ja  v a2s  .c  o  m*/
        jgen.writeEndObject();
        return;
    }

    TreeMap<String, String> map = new TreeMap<>();
    for (Map.Entry<Object, Object> e : properties.entrySet()) {
        map.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
    }

    InputStream is = getClass().getClassLoader().getResourceAsStream(VERSION_FILE);
    if (is != null) {
        LOG.debug("Loaded {} bytes of version file configuration", is.available());
        Properties versionProps = new Properties();
        versionProps.load(is);
        for (Map.Entry<Object, Object> e : versionProps.entrySet()) {
            map.put(String.valueOf(e.getKey()), String.valueOf(e.getValue()));
        }
    } else {
        LOG.error("No version file found on classpath. VERSION_FILE={}", VERSION_FILE);
    }

    jgen.writeStartObject();
    for (Map.Entry<String, String> e : map.entrySet()) {
        if (e.getValue().indexOf(',') > 0) {
            splitList(e.getKey(), e.getValue(), jgen);
        } else {
            jgen.writeStringField(e.getKey(), e.getValue());
        }
    }
    jgen.writeEndObject();
}

From source file:org.powertac.customer.coldstorage.ColdStorageTest.java

@Test
public void testConfig() {
    TreeMap<String, String> map = new TreeMap<String, String>();
    map.put("customer.coldstorage.coldStorage.minTemp", "-30");
    map.put("customer.coldstorage.coldStorage.maxTemp", "-5");
    Configuration mapConfig = new MapConfiguration(map);
    config.setConfiguration(mapConfig);//from   ww w.  j a v  a 2  s.  c  o m
    serverConfig.configureMe(uut);
    assertEquals("correct min temp", -30.0, uut.getMinTemp(), 1e-6);
    assertEquals("correct max temp", -5.0, uut.getMaxTemp(), 1e-6);
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitCompletedConsultationBody() throws SQLException {
    TreeMap<Integer, String> cons_compl_desc = new TreeMap<>();
    String sql = "SELECT id, completed_text " + "FROM consultation "
            + "WHERE completed = 1 AND id NOT IN (SELECT consultations_ner.id FROM consultations_ner);";
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    while (rs.next()) {
        int consID = rs.getInt("id");
        String cons_compl_text = rs.getString("completed_text");
        //            String cons_compl = rs.getString("completed_text");
        //            if (cons_compl != null) {
        //                String cons_text = cons_compl + "\n" + cons_desc;
        //                cons_body.put(consID, cons_text);
        //            } else {
        cons_compl_desc.put(consID, cons_compl_text);
        //            }
    }/*from  w  ww .jav  a 2 s.c o  m*/
    return cons_compl_desc;
}

From source file:com.enitalk.configs.BotConfig.java

@Bean(name = "offsetMap")
public TreeMap<Long, String> timezones() throws IOException {
    ObjectMapper j = new ObjectMapper();
    JsonNode o = j.readTree(new ClassPathResource("dates/treeTz.json").getInputStream());
    TreeMap<Long, String> offsets = new TreeMap<>();
    Iterator<JsonNode> it = o.elements();
    while (it.hasNext()) {
        JsonNode el = it.next();/*  w w  w  .  j a  v  a2s  .  c  om*/
        String key = el.fieldNames().next();
        offsets.put(Long.valueOf(key), el.path(key).iterator().next().toString());
    }

    return offsets;

}

From source file:jenkins.plugins.publish_over.BPBuildEnv.java

public TreeMap<String, String> getEnvVarsWithPrefix(final String prefix) {
    final TreeMap<String, String> prefixed = new TreeMap<String, String>();
    for (Map.Entry<String, String> entry : envVars.entrySet()) {
        prefixed.put(prefix + entry.getKey(), entry.getValue());
    }/* www. j a  v  a2 s  .  co  m*/
    return prefixed;
}

From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java

/**
 * Converts an {@link EnumMap} of//from   w w  w  . java2 s  .  c  om
 * {@link org.fourthline.cling.support.model.dlna.DLNAAttribute}s to a
 * {@link TreeMap} of {@link ProtocolInfoAttribute}s.
 *
 * @param dlnaAttributes the {@link EnumMap} of
 *            {@link org.fourthline.cling.support.model.dlna.DLNAAttribute}s
 *            to convert.
 * @return A {@link TreeMap} containing the converted
 *         {@link ProtocolInfoAttribute}s.
 */
public static TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> dlnaAttributesToAttributes(
        EnumMap<DLNAAttribute.Type, DLNAAttribute<?>> dlnaAttributes) {
    TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> attributes = createEmptyAttributesMap();
    for (Entry<DLNAAttribute.Type, DLNAAttribute<?>> entry : dlnaAttributes.entrySet()) {
        try {
            ProtocolInfoAttribute attribute = ProtocolInfoAttribute.FACTORY.createAttribute(
                    entry.getKey().getAttributeName(), entry.getValue().getString(), Protocol.HTTP_GET);
            if (attribute != null) {
                attributes.put(attribute.getName(), attribute);
            }
        } catch (ParseException e) {
            LOGGER.debug("Couldn't parse DLNAAttribute \"{}\" = \"{}\": {}", entry.getKey().getAttributeName(),
                    entry.getValue().getString(), e.getMessage());
            LOGGER.trace("", e);
        }
    }
    return attributes;
}

From source file:org.londonsburning.proxy.ProxyPrinter.java

/**
 * <p>/*from www . j  av a2s  .  c  o m*/
 * writeDeck.
 * </p>
 *
 * @param deck           a String
 * @param file           a File
 * @param skipBasicLands Skip Basic Lands
 */
private void generateHtml(final Deck deck, final File file, final boolean skipBasicLands) {
    try {
        final BufferedWriter htmlOutput = new BufferedWriter(new FileWriter(file));

        Template template;

        final Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(deck.getClass(), "/");
        cfg.setObjectWrapper(new DefaultObjectWrapper());
        template = cfg.getTemplate(this.proxyConfiguration.getOutputTemplate());

        final TreeMap<String, Object> root = new TreeMap<String, Object>();
        root.put("title", deck.getDeckName());
        final List<String> list = new ArrayList<String>();
        for (final String cardName : deck.getCardList().keySet()) {
            for (int i = 0; i <= (deck.getCardList().get(cardName) - 1); i++) {
                if (!this.proxyConfiguration.getBasicLandNames().contains(cardName) || !skipBasicLands) {
                    list.add(getURL(cardName));
                }
            }
        }

        final LinkedHashMap<String, Integer> map = deck.getCardList();
        root.put("urls", list);
        root.put("cardBorder", this.proxyConfiguration.getCard().getCardBorder());
        root.put("cardHeight", Math.round(this.proxyConfiguration.getCard().getCardHeight()
                * this.proxyConfiguration.getCard().getCardScale()));
        root.put("cardWidth", Math.round(this.proxyConfiguration.getCard().getCardWidth()
                * this.proxyConfiguration.getCard().getCardScale()));
        root.put("cardListWidth",
                this.proxyConfiguration.getCard().getCardWidth() - this.proxyConfiguration.getCardListWidth());
        root.put("cardList", map);
        root.put("numberOfCards", deck.getNumberOfCards());

        /* Merge data-model with template */
        template.process(root, htmlOutput);
        htmlOutput.flush();
        htmlOutput.close();
    } catch (final IOException e) {
        logger.debug(e.toString());
    } catch (final TemplateException e) {
        logger.debug(e.toString());
    } catch (final URISyntaxException e) {
        logger.debug(e.toString());
    } catch (final InterruptedException e) {
        logger.debug(e.toString());
    }
}

From source file:org.waarp.gateway.kernel.rest.RestArgument.java

/**
 * The encoder is completed with extra necessary URI part containing ARG_X_AUTH_TIMESTAMP & ARG_X_AUTH_KEY
 * /*ww  w. j  av  a2  s.  c  om*/
 * @param hmacSha256
 *            SHA-256 key to create the signature
 * @param encoder
 * @param user
 *            might be null
 * @param extraKey
 *            might be null
 * @return an array of 2 value in order ARG_X_AUTH_TIMESTAMP and ARG_X_AUTH_KEY
 * @throws HttpInvalidAuthenticationException
 *             if the computation of the authentication failed
 */
public static String[] getBaseAuthent(HmacSha256 hmacSha256, QueryStringEncoder encoder, String user,
        String extraKey) throws HttpInvalidAuthenticationException {
    QueryStringDecoder decoderQuery = new QueryStringDecoder(encoder.toString());
    Map<String, List<String>> map = decoderQuery.parameters();
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    for (Entry<String, List<String>> entry : map.entrySet()) {
        String keylower = entry.getKey().toLowerCase();
        List<String> values = entry.getValue();
        if (values != null && !values.isEmpty()) {
            String last = values.get(values.size() - 1);
            treeMap.put(keylower, last);
        }
    }
    DateTime date = new DateTime();
    treeMap.put(REST_ROOT_FIELD.ARG_X_AUTH_TIMESTAMP.field.toLowerCase(), date.toString());
    if (user != null) {
        treeMap.put(REST_ROOT_FIELD.ARG_X_AUTH_USER.field.toLowerCase(), user);
    }
    try {
        String key = computeKey(hmacSha256, extraKey, treeMap, decoderQuery.path());
        String[] result = { date.toString(), key };
        return result;
        /* encoder.addParam(REST_ROOT_FIELD.ARG_X_AUTH_TIMESTAMP.field, date.toString());
        encoder.addParam(REST_ROOT_FIELD.ARG_X_AUTH_KEY.field, key); */
    } catch (Exception e) {
        throw new HttpInvalidAuthenticationException(e);
    }

}