Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public 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:utilities.itext.Turnover.java

private static Image createPieChart(HashMap<String, BigDecimal> map, String title) throws Exception {
    DefaultPieDataset data = new DefaultPieDataset();

    for (String key : map.keySet()) {
        data.setValue(key, map.get(key).doubleValue());
    }//from  w ww  .j a  v a2s .com

    JFreeChart pieChart = ChartFactory.createPieChart(title, data, true, false, Locale.GERMAN);
    //        PiePlot plot = (PiePlot) pieChart.getPlot();
    //        plot.setLabelGenerator(null);

    BufferedImage pie = pieChart.createBufferedImage(500, 500);
    File tempPie = File.createTempFile("png", null);
    ImageIO.write(pie, "png", tempPie);
    Image img = Image.getInstance(tempPie.getPath());

    return img;
}

From source file:gov.nasa.jpl.analytics.util.CommonUtil.java

public static HashMap<String, Integer> termFrequency(Iterable<String> terms) {
    HashMap<String, Integer> map = new HashMap();
    for (String term : terms) {
        if (!map.containsKey(term)) {
            map.put(term, 1);/*  w  w  w  .  j av  a  2s.co  m*/
        } else {
            map.put(term, map.get(term) + 1);
        }
    }
    return map;
}

From source file:net.dv8tion.jda.handle.GuildMembersChunkHandler.java

public static void setExpectedGuildMembers(JDA jda, String guildId, int count) {
    HashMap<String, Integer> guildMembers = expectedGuildMembers.get(jda);
    if (guildMembers == null) {
        guildMembers = new HashMap<>();
        expectedGuildMembers.put(jda, guildMembers);
    }//from  w  ww  .  jav a  2  s. c  om

    if (guildMembers.get(guildId) != null)
        JDAImpl.LOG.warn(
                "Set the count of expected users from GuildMembersChunk even though a value already exists! GuildId: "
                        + guildId);

    guildMembers.put(guildId, count);

    HashMap<String, List<JSONArray>> memberChunks = memberChunksCache.get(jda);
    if (memberChunks == null) {
        memberChunks = new HashMap<>();
        memberChunksCache.put(jda, memberChunks);
    }

    if (memberChunks.get(guildId) != null)
        JDAImpl.LOG.warn(
                "Set the memberChunks for MemberChunking for a guild that was already setup for chunking! GuildId: "
                        + guildId);

    memberChunks.put(guildId, new LinkedList<>());
}

From source file:com.sec.ose.osi.util.tools.Tools.java

public static ArrayList<String> sortByValue(final HashMap<String, Integer> map) {
    ArrayList<String> key = new ArrayList<String>();
    key.addAll(map.keySet());/*  ww  w  . ja v  a2 s  . co m*/
    Collections.sort(key, new Comparator<Object>() {
        public int compare(Object o1, Object o2) {
            Integer v1 = map.get(o1);
            Integer v2 = map.get(o2);
            return v1.compareTo(v2);
        }
    });
    Collections.reverse(key);
    return key;
}

From source file:com.proctorcam.proctorserv.HashedAuthenticator.java

protected static String hashQuery(String key, HashMap<String, Object> valueHash) {
    StringBuilder query = new StringBuilder();
    for (String k : valueHash.keySet()) {
        String v = String.valueOf(valueHash.get(k));
        query.append(String.format("%s[%s]=%s&", key, k, v));
    }//from   ww w.  j av a 2s  . c om
    return query.toString();
}

From source file:Main.java

private static boolean processSubstituteChars(char currentChar, HashMap<?, ?> substituteChars,
        StringBuffer buffer) {//from  w  w  w .j  a  v a  2 s  .  c o m
    Character character = new Character(currentChar);
    if (substituteChars.containsKey(character)) {
        String value = (String) substituteChars.get(character);
        if (isDefined(value)) {
            // Append the value if defined
            buffer.append(value);
        }
        // If the value was not defined, then we will strip the character
        return true;
    }
    return false;
}

From source file:com.dgtlrepublic.model.test.DataTest.java

@SuppressWarnings("unchecked")
private static void verify(Map entry) throws Exception {
    String fileName = (String) entry.getOrDefault("file_name", "");
    boolean ignore = (Boolean) entry.getOrDefault("ignore", false);
    int id = (Integer) entry.getOrDefault("id", -1);
    HashMap<String, Object> testCases = (HashMap<String, Object>) entry.getOrDefault("results",
            new HashMap<String, Object>());
    if (ignore || StringUtils.isBlank(fileName) || testCases.size() == 0) {
        System.out.println(String.format("Ignoring [%s] : { id: %s | results: %s | explicit: %s }", fileName,
                id, testCases.size(), ignore));
        return;//from www  .jav a2 s.co m
    }

    System.out.println("Parsing: " + fileName);
    HashMap<String, Object> parseResults = (HashMap<String, Object>) DataJsonConverter.toTestCaseMap(fileName)
            .getOrDefault("results", null);

    for (Entry<String, Object> testCase : testCases.entrySet()) {
        Object elValue = parseResults.get(testCase.getKey());
        if (elValue == null) {
            throw new Exception(String.format("%n[%s] Missing Element: %s [%s]", fileName, testCase.getKey(),
                    testCase.getValue()));
        } else if (elValue instanceof String && !elValue.equals(testCase.getValue())) {
            throw new Exception(String.format("%n[%s] Incorrect Value:(%s) [%s] { required: [%s] } ", fileName,
                    testCase.getKey(), elValue, testCase.getValue()));
        } else if (elValue instanceof List
                && !((List) elValue).containsAll((Collection<?>) testCase.getValue())) {
            throw new Exception(String.format("%n[%s] Incorrect List Values:(%s) [%s] { required: [%s] } ",
                    fileName, testCase.getKey(), elValue, testCase.getValue()));
        }
    }
}

From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java

private static List<NameValuePair> createPostData(HashMap<String, String> arguments) throws Exception {
    List<NameValuePair> postdata = new ArrayList<NameValuePair>();
    if (arguments != null) {
        for (String key : arguments.keySet()) {
            postdata.add(new BasicNameValuePair(key, arguments.get(key)));
        }/* w  ww  .  j a  va 2s .  c  om*/
        return postdata;
    }
    throw new Exception("No arguments");
}

From source file:de.tor.tribes.util.AttackToTextWriter.java

public static boolean writeAttacks(Attack[] pAttacks, File pPath, int pAttacksPerFile, boolean pExtendedInfo,
        boolean pZipResults) {

    HashMap<Tribe, List<Attack>> attacks = new HashMap<>();

    for (Attack a : pAttacks) {
        Tribe t = a.getSource().getTribe();
        List<Attack> attsForTribe = attacks.get(t);
        if (attsForTribe == null) {
            attsForTribe = new LinkedList<>();
            attacks.put(t, attsForTribe);
        }/*w ww .  j a va  2 s.c o  m*/
        attsForTribe.add(a);
    }

    Set<Entry<Tribe, List<Attack>>> entries = attacks.entrySet();
    for (Entry<Tribe, List<Attack>> entry : entries) {
        Tribe t = entry.getKey();
        List<Attack> tribeAttacks = entry.getValue();
        List<String> blocks = new LinkedList<>();

        while (!tribeAttacks.isEmpty()) {
            List<Attack> attsForBlock = new LinkedList<>();
            for (int i = 0; i < pAttacksPerFile; i++) {
                if (!tribeAttacks.isEmpty()) {
                    attsForBlock.add(tribeAttacks.remove(0));
                }
            }

            String fileContent = new AttackListFormatter().formatElements(attsForBlock, pExtendedInfo);
            blocks.add(fileContent);
        }
        if (!pZipResults) {
            writeBlocksToFiles(blocks, t, pPath);
        } else {
            writeBlocksToZip(blocks, t, pPath);
        }

    }
    return true;
}

From source file:Main.java

/** substitutes the linearDistributions according to the substitution list */
public static String substitute(String currentQIESL, HashMap<Integer, String> substitutionList) {

    StringBuffer result = new StringBuffer();

    int i = 0;/*w w w .ja va 2 s.c o  m*/
    Matcher m = LINEAR_DISTRIUBTIONS.matcher(currentQIESL);
    while (m.find()) {
        if (substitutionList.containsKey(i)) {
            m.appendReplacement(result, substitutionList.get(i));
        }
        i++;
    }
    m.appendTail(result);

    return result.toString();

}