Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

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

public static String makeSignature(String viewerId, String appSecret, List<NameValuePair> params) {
    SortedMap<String, String> map = new TreeMap<String, String>();
    for (NameValuePair pair : params) {
        map.put(pair.getName(), pair.getValue());
    }//  w w  w .  j a  v  a2 s  .co m
    return makeSignature(viewerId, appSecret, map);
}

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

private static <T> SortedMap<String, T> namedAttributesToMap(Enumeration<String> names,
        AttributeAccessor<T> accessor) {
    SortedMap<String, T> map = new TreeMap<String, T>();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        map.put(name, accessor.getAttribute(name));
    }//from ww w.j  a va  2 s . com
    return Collections.unmodifiableSortedMap(map);
}

From source file:Main.java

private static void putKeyValue(Class<?> clazz, String buildField, SortedMap<String, String> keysToValues) {
    try {/*  ww w  .  jav a  2 s .co  m*/
        Field field = clazz.getField(buildField);
        Object value = field.get(null);
        String key = clazz.getSimpleName().toLowerCase() + "." + buildField.toLowerCase();
        keysToValues.put(key, String.valueOf(value));
    } catch (SecurityException | NoSuchFieldException | IllegalAccessException e) {
        // ignore
    }
}

From source file:Main.java

private static void putKeyValue(Class<?> clazz, String buildField, SortedMap<String, String> keysToValues) {
    try {//from  ww  w .ja  va 2  s.  c  om
        Field field = clazz.getField(buildField);
        Object value = field.get(null);
        String key = clazz.getSimpleName().toLowerCase() + "." + buildField.toLowerCase();
        keysToValues.put(key, String.valueOf(value));
    } catch (SecurityException e) {
        // ignore
    } catch (NoSuchFieldException e) {
        // ignore
    } catch (IllegalAccessException e) {
        // ignore
    }
}

From source file:net.myrrix.online.candidate.LocationSensitiveHashTest.java

private static List<Long> findTopRecommendations(FastByIDMap<float[]> Y, float[] userVec) {
    SortedMap<Double, Long> allScores = Maps.newTreeMap(Collections.reverseOrder());
    for (FastByIDMap.MapEntry<float[]> entry : Y.entrySet()) {
        double dot = SimpleVectorMath.dot(entry.getValue(), userVec);
        allScores.put(dot, entry.getKey());
    }/*  w w  w .j a  va 2  s  .c o m*/
    List<Long> topRecommendations = Lists.newArrayList();
    for (Map.Entry<Double, Long> entry : allScores.entrySet()) {
        topRecommendations.add(entry.getValue());
        if (topRecommendations.size() == NUM_RECS) {
            return topRecommendations;
        }
    }
    return topRecommendations;
}

From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java

private static <K, V> SortedMap<K, Set<V>> listSortedMapToSetSortedMap(SortedMap<K, List<V>> map) {
    SortedMap<K, Set<V>> result = Maps.newTreeMap(map.comparator());
    for (Entry<K, List<V>> e : map.entrySet()) {
        result.put(e.getKey(), Sets.<V>newHashSet(e.getValue()));
    }//w  ww .  j  av  a2 s  . c om
    return result;
}

From source file:bigbluej.ReflectionUtils.java

public static SortedMap<String, Object> getFieldsAndValuesInSortedMap(Object object)
        throws IllegalAccessException {
    Validate.notNull(object);/*from  w w  w .  j  a  v  a 2 s.  c  o  m*/
    SortedMap<String, Object> fieldAndValues = new TreeMap<>();
    for (Field field : object.getClass().getDeclaredFields()) {
        field.setAccessible(true);
        String name = field.getName();
        Object value = field.get(object);
        if (!field.isSynthetic() && value != null) {
            fieldAndValues.put(name, value);
        }
    }
    return fieldAndValues;
}

From source file:com.cloudera.oryx.als.common.candidate.LocationSensitiveHashIT.java

private static List<Long> findTopRecommendations(LongObjectMap<float[]> Y, float[] userVec) {
    SortedMap<Double, Long> allScores = new TreeMap<>(Collections.reverseOrder());
    for (LongObjectMap.MapEntry<float[]> entry : Y.entrySet()) {
        double dot = SimpleVectorMath.dot(entry.getValue(), userVec);
        allScores.put(dot, entry.getKey());
    }/*from  w  w w . ja  va 2s .c o m*/
    List<Long> topRecommendations = new ArrayList<>();
    for (Map.Entry<Double, Long> entry : allScores.entrySet()) {
        topRecommendations.add(entry.getValue());
        if (topRecommendations.size() == NUM_RECS) {
            return topRecommendations;
        }
    }
    return topRecommendations;
}

From source file:com.cloudera.oryx.als.common.lsh.LocationSensitiveHashIT.java

private static List<Long> findTopRecommendations(LongObjectMap<float[]> Y, float[] userVec) {
    SortedMap<Double, Long> allScores = Maps.newTreeMap(Collections.reverseOrder());
    for (LongObjectMap.MapEntry<float[]> entry : Y.entrySet()) {
        double dot = SimpleVectorMath.dot(entry.getValue(), userVec);
        allScores.put(dot, entry.getKey());
    }//from   ww w. j a v a2s.  c  om
    List<Long> topRecommendations = Lists.newArrayList();
    for (Map.Entry<Double, Long> entry : allScores.entrySet()) {
        topRecommendations.add(entry.getValue());
        if (topRecommendations.size() == NUM_RECS) {
            return topRecommendations;
        }
    }
    return topRecommendations;
}

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

/**
 * Relevant sentences per document (per query)
 *//*from   w ww . j  ava2 s .c  o m*/
public static void statistics6(File inputDir, File outputDir) throws IOException {
    PrintWriter pw = new PrintWriter(new FileWriter(new File(outputDir, "stats6.csv")));

    SortedMap<String, DescriptiveStatistics> result = new TreeMap<>();
    result.put("relevantSentencesDocumentPercent", new DescriptiveStatistics());

    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%s\t%sStdDev\t", mapKey, mapKey);
    }
    pw.println();

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

        for (QueryResultContainer.SingleRankedResult rankedResult : queryResultContainer.rankedResults) {

            if (rankedResult.plainText != null && !rankedResult.plainText.isEmpty()) {

                int relevantSentences = 0;
                int totalSentences = 0;

                if (rankedResult.goldEstimatedLabels != null) {
                    for (QueryResultContainer.SingleSentenceRelevanceVote sentenceRelevanceVote : rankedResult.goldEstimatedLabels) {
                        totalSentences++;

                        if (Boolean.valueOf(sentenceRelevanceVote.relevant)) {
                            relevantSentences++;
                        }
                    }

                    // percent relevant

                    result.get("relevantSentencesDocumentPercent")
                            .addValue((double) relevantSentences / (double) totalSentences);
                }
            }
        }
    }

    // print results
    // print header
    for (String mapKey : result.keySet()) {
        pw.printf(Locale.ENGLISH, "%.3f\t%.3f\t", result.get(mapKey).getMean(),
                result.get(mapKey).getStandardDeviation());
    }

    pw.close();

}