Example usage for java.util SortedMap entrySet

List of usage examples for java.util SortedMap entrySet

Introduction

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

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.geowebcache.filter.parameters.ParametersUtils.java

/**
 * //www.  j  av a2  s  . com
 * This should be treated as an opaque Identifier and should not be parsed, it is used to 
 * to maintain compatibility with old caches.  For any other uses, {@link getKVP} is preferred
 * as it uses safe escaping of values.
 * 
 * @param parameters
 * @return
 */
public static String getLegacyParametersKvp(Map<String, String> parameters) {
    StringBuilder sb = new StringBuilder();
    SortedMap<String, String> sorted = new TreeMap<String, String>(parameters);
    for (Map.Entry<String, String> e : sorted.entrySet()) {
        if (sb.length() == 0) {
            sb.append("?");
        } else {
            sb.append("&");
        }
        sb.append(e.getKey()).append('=').append(e.getValue());
    }
    String paramtersKvp = sb.toString();
    return paramtersKvp;
}

From source file:playground.johannes.gsv.synPop.analysis.ProxyAnalyzer.java

public static void writeStatistics(Map<String, DescriptiveStatistics> statsMap, String filename)
        throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filename, append));

    writer.write("property\tmean\tmin\tmax\tmedian\tN\tvar");
    writer.newLine();//  w w w  .j a  v a2  s.  com
    SortedMap<String, DescriptiveStatistics> sortedMap = new TreeMap<String, DescriptiveStatistics>(statsMap);
    for (Entry<String, DescriptiveStatistics> entry : sortedMap.entrySet()) {
        writer.write(entry.getKey());
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMean()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMin()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMax()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getPercentile(50)));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getN()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getVariance()));
        writer.newLine();
    }

    writer.close();
}

From source file:com.roncoo.pay.trade.utils.MerchantApiUtil.java

/**
 * ??//ww w  .  j a v  a 2 s  .com
 * @param paramMap
 * @return
 */
public static String getParamStr(Map<String, Object> paramMap) {
    SortedMap<String, Object> smap = new TreeMap<String, Object>(paramMap);
    StringBuffer stringBuffer = new StringBuffer();
    for (Map.Entry<String, Object> m : smap.entrySet()) {
        Object value = m.getValue();
        if (value != null && StringUtils.isNotBlank(String.valueOf(value))) {
            stringBuffer.append(m.getKey()).append("=").append(value).append("&");
        }
    }
    stringBuffer.delete(stringBuffer.length() - 1, stringBuffer.length());

    return stringBuffer.toString();
}

From source file:org.geowebcache.storage.blobstore.file.FilePathGenerator.java

/**
 * Turns the parameter list into a sorted KVP string
 * /*from ww  w  . j  a  v a2  s.  c om*/
 * @param parameters
 * @return
 */
public static String getParametersKvp(Map<String, String> parameters) {
    StringBuilder sb = new StringBuilder();
    SortedMap<String, String> sorted = new TreeMap<String, String>(parameters);
    for (Map.Entry<String, String> e : sorted.entrySet()) {
        if (sb.length() == 0) {
            sb.append("?");
        } else {
            sb.append("&");
        }
        sb.append(e.getKey()).append('=').append(e.getValue());
    }
    String paramtersKvp = sb.toString();
    return paramtersKvp;
}

From source file:com.roncoo.pay.trade.utils.MerchantApiUtil.java

/**
 * ????/*  www .j  a v a 2 s.  c o m*/
 * @param paramMap  ???
 * @param paySecret ??
 * @return
 */
public static String getSign(Map<String, Object> paramMap, String paySecret) {
    SortedMap<String, Object> smap = new TreeMap<String, Object>(paramMap);
    StringBuffer stringBuffer = new StringBuffer();
    for (Map.Entry<String, Object> m : smap.entrySet()) {
        Object value = m.getValue();
        if (value != null && StringUtils.isNotBlank(String.valueOf(value))) {
            stringBuffer.append(m.getKey()).append("=").append(value).append("&");
        }
    }
    stringBuffer.delete(stringBuffer.length() - 1, stringBuffer.length());

    String argPreSign = stringBuffer.append("&paySecret=").append(paySecret).toString();
    String signStr = MD5Util.encode(argPreSign).toUpperCase();

    return signStr;
}

From source file:playground.johannes.coopsim.analysis.TrajectoryAnalyzer.java

public static void writeStatistics(Map<String, DescriptiveStatistics> statsMap, String filename)
        throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filename, append));

    //      writer.write("property\tmean\tmin\tmax\tmedian\tN\tvar");
    writer.write("property\tmean\tmin\tmax\tN\tvar");
    writer.newLine();//from ww  w . j  a v  a2s.  c o  m
    SortedMap<String, DescriptiveStatistics> sortedMap = new TreeMap<String, DescriptiveStatistics>(statsMap);
    for (Entry<String, DescriptiveStatistics> entry : sortedMap.entrySet()) {
        writer.write(entry.getKey());
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMean()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMin()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getMax()));
        //         Recently i faced situations where this methods appears to never return with large data sets. joh 11/2014
        //         writer.write("\t");
        //         writer.write(String.valueOf(entry.getValue().getPercentile(50)));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getN()));
        writer.write("\t");
        writer.write(String.valueOf(entry.getValue().getVariance()));
        writer.newLine();
    }

    writer.close();
}

From source file:net.emphased.vkclient.VkApi.java

public static String makeSignature(String viewerId, String appSecret, SortedMap<String, String> params) {
    StringBuilder str = new StringBuilder();
    str.append(viewerId);//  ww  w  . j av a 2  s . co  m
    for (Entry<String, String> param : params.entrySet()) {
        str.append(param.getKey()).append('=').append(param.getValue());
    }
    str.append(appSecret);
    try {
        return DigestUtils.md5Hex(str.toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:com.roncoo.utils.MerchantApiUtil.java

/**
 * ????//from w w  w. jav a2 s.  c  o  m
 * @param paramMap  ???
 * @param paySecret ??
 * @return
 */
public static String getSign(Map<String, Object> paramMap, String paySecret) {
    SortedMap<String, Object> smap = new TreeMap<String, Object>(paramMap);
    StringBuffer stringBuffer = new StringBuffer();
    for (Map.Entry<String, Object> m : smap.entrySet()) {
        Object value = m.getValue();
        if (value != null && StringUtils.isNotBlank(String.valueOf(value))) {
            stringBuffer.append(m.getKey()).append("=").append(m.getValue()).append("&");
        }
    }
    stringBuffer.delete(stringBuffer.length() - 1, stringBuffer.length());

    String argPreSign = stringBuffer.append("&paySecret=").append(paySecret).toString();
    String signStr = MD5Util.encode(argPreSign).toUpperCase();

    return signStr;
}

From source file:io.wcm.devops.conga.generator.util.VariableStringResolver.java

@SuppressWarnings("unchecked")
private static String valueToString(Object value) {
    if (value == null) {
        return "";
    } else if (value instanceof List) {
        StringBuilder sb = new StringBuilder();
        for (Object item : ((List) value)) {
            if (sb.length() > 0) {
                sb.append(",");
            }/*from w w  w.  j  a va  2s  .  c o m*/
            sb.append(valueToString(item));
        }
        return sb.toString();
    } else if (value instanceof Map) {
        StringBuilder sb = new StringBuilder();
        // use sorted map to ensure consistent order of keys
        SortedMap<Object, Object> sortedMap = new TreeMap<>((Map<Object, Object>) value);
        for (Map.Entry<Object, Object> entry : sortedMap.entrySet()) {
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(valueToString(entry.getKey()));
            sb.append("=");
            sb.append(valueToString(entry.getValue()));
        }
        return sb.toString();
    } else {
        return value.toString();
    }
}

From source file:com.kku.apps.pricesearch.util.SignedHelper.java

private static String canonicalize(SortedMap<String, String> sortedParamMap) {
    if (sortedParamMap.isEmpty()) {
        return "";
    }//from w w w .  j ava2 s  .c o  m

    StringBuffer buffer = new StringBuffer();
    Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> kvpair = iter.next();
        buffer.append(percentEncodeRfc3986(kvpair.getKey()));
        buffer.append("=");
        buffer.append(percentEncodeRfc3986(kvpair.getValue()));
        if (iter.hasNext()) {
            buffer.append("&");
        }
    }
    String cannoical = buffer.toString();
    return cannoical;
}