Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.mycsense.carbondb.domain.SourceRelation.java

public static HashMap<String, ArrayList<Dimension>> createGroupHashTable(Group group, Dimension commonKeywords,
        Integer alpha) {/*w  ww  .  jav  a  2 s.co m*/
    HashMap<String, ArrayList<Dimension>> elements = new HashMap<>();
    for (Dimension element : group.getCoordinates().dimensions) {
        String hashKey = getHashKey(element, commonKeywords, alpha);
        if (!hashKey.equals("#nullHashKey#")) {
            if (!elements.containsKey(hashKey)) {
                elements.put(hashKey, new ArrayList<Dimension>());
            }
            elements.get(hashKey).add(element);
        }
    }
    return elements;
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEAppHandler.java

public static HashMap<String, List<TrackerFieldSoapDO>> loadTrackerFieldsInHashMap(
        TrackerFieldSoapDO[] flexFields) {
    HashMap<String, List<TrackerFieldSoapDO>> fieldsMap = new HashMap<String, List<TrackerFieldSoapDO>>();
    for (TrackerFieldSoapDO field : flexFields) {
        String fieldName = field.getName();
        // FIXME Will we ever get two field with same name in method?
        if (fieldsMap.containsKey(fieldName)) {
            List<TrackerFieldSoapDO> fieldsList = fieldsMap.get(fieldName);
            fieldsList.add(field);//from   w ww . j  a  v  a2  s. co  m
        } else {
            List<TrackerFieldSoapDO> fieldsList = new ArrayList<TrackerFieldSoapDO>();
            fieldsList.add(field);
            fieldsMap.put(fieldName, fieldsList);
        }
    }
    return fieldsMap;
}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.RemoteParForUtils.java

/**
 * //from  www . j av  a  2  s  . c o m
 * @param out
 * @return
 * @throws DMLRuntimeException
 * @throws IOException
 */
public static LocalVariableMap[] getResults(List<Tuple2<Long, String>> out, Log LOG)
        throws DMLRuntimeException {
    HashMap<Long, LocalVariableMap> tmp = new HashMap<Long, LocalVariableMap>();

    int countAll = 0;
    for (Tuple2<Long, String> entry : out) {
        Long key = entry._1();
        String val = entry._2();
        if (!tmp.containsKey(key))
            tmp.put(key, new LocalVariableMap());
        Object[] dat = ProgramConverter.parseDataObject(val);
        tmp.get(key).put((String) dat[0], (Data) dat[1]);
        countAll++;
    }

    if (LOG != null) {
        LOG.debug("Num remote worker results (before deduplication): " + countAll);
        LOG.debug("Num remote worker results: " + tmp.size());
    }

    //create return array
    return tmp.values().toArray(new LocalVariableMap[0]);
}

From source file:fshp.FSHP.java

/**
 * Returns the hash of <tt>passwd</tt> 
 *
 * @param passwd Byte representation of clear text password.
 * @param salt Byte representation of salt to be used in hashing.
 * @param saltlen Length of the salt. Should be 0 if a salt is already
 *        provided. If salt is null, saltlen bytes of salt will be
 *        auto generated.// ww w.  j a  v a 2 s  .com
 * @param rounds Number of hashing rounds.
 * @param variant FSHP variant indicating the behaviour and/or
 * <ul>
 *        <li><tt>0: SHA-1</tt> <em>(not recommended)</em></li>
 *        <li><tt>1: SHA-256</tt></li>
 *        <li><tt>2: SHA-384</tt></li>
 *        <li><tt>3: SHA-512</tt></li>
 * </ul>
 *
 * @return       FSHP hash of <tt>passwd</tt>
 */
public static String crypt(byte[] passwd, byte[] salt, int saltlen, int rounds, int variant) throws Exception {
    // Ensure we have sane values for salt length and rounds.
    if (saltlen < 0)
        saltlen = 0;
    if (rounds < 1)
        rounds = 1;

    if (salt == null) {
        salt = new byte[saltlen];
        new SecureRandom().nextBytes(salt);
    } else
        saltlen = salt.length;

    HashMap<Integer, String> algoMap = new HashMap<Integer, String>();
    algoMap.put(0, "SHA-1");
    algoMap.put(1, "SHA-256");
    algoMap.put(2, "SHA-384");
    algoMap.put(3, "SHA-512");

    MessageDigest md;
    try {
        if (!algoMap.containsKey(variant))
            throw new NoSuchAlgorithmException();

        md = MessageDigest.getInstance(algoMap.get(variant));
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("Unsupported FSHP variant " + variant);
    }

    md.update(salt);
    md.update(passwd);
    byte[] digest = md.digest();

    for (int i = 1; i < rounds; i++) {
        md.reset();
        md.update(digest);
        digest = md.digest();
    }

    String meta = "{FSHP" + variant + "|" + saltlen + "|" + rounds + "}";

    byte[] saltdigest = new byte[salt.length + digest.length];
    System.arraycopy(salt, 0, saltdigest, 0, salt.length);
    System.arraycopy(digest, 0, saltdigest, salt.length, digest.length);

    byte[] b64saltdigest = Base64.encodeBase64(saltdigest);

    return meta + new String(b64saltdigest, "US-ASCII");
}

From source file:com.ibm.util.merge.CompareArchives.java

/**
 * @param zip1//w ww.  j  a  v  a 2 s . c o  m
 * @param files1
 * @param zip2
 * @param files2
 * @throws IOException
 */
private static final void assertMembersEqual(ZipFile zip1, HashMap<String, ZipEntry> files1, ZipFile zip2,
        HashMap<String, ZipEntry> files2) throws IOException {
    if (files1.size() != files2.size()) {
        fail("Different Sizes, expected " + Integer.toString(files1.size()) + " found "
                + Integer.toString(files2.size()));
    }

    for (String key : files1.keySet()) {
        if (!files2.containsKey(key)) {
            fail("Expected file not in target " + key);
        }
        String file1 = IOUtils.toString(zip1.getInputStream(files1.get(key)));
        String file2 = IOUtils.toString(zip2.getInputStream(files2.get(key)));
        assertEquals(file1, file2);
    }
}

From source file:com.ibm.util.merge.CompareArchives.java

/**
 * @param tar1//from w  ww .  j a  v  a 2 s. c  o m
 * @param files1
 * @param tar2
 * @param files2
 * @throws IOException
 */
private static final void assertMembersEqual(String tar1, HashMap<String, TarArchiveEntry> files1, String tar2,
        HashMap<String, TarArchiveEntry> files2) throws IOException {
    if (files1.size() != files2.size()) {
        fail("Different Sizes, expected " + Integer.toString(files1.size()) + " found "
                + Integer.toString(files2.size()));
    }

    for (String key : files1.keySet()) {
        if (!files2.containsKey(key)) {
            fail("Expected file not in target " + key);
        }
    }

    for (String key : files1.keySet()) {
        if (!files2.containsKey(key)) {
            fail("Expected file not in target " + key);
        }
    }
    for (String key : files1.keySet()) {
        String file1 = getTarFile(tar1, key);
        String file2 = getTarFile(tar2, key);
        assertEquals(file1, file2);
    }
}

From source file:org.samjoey.graphing.GraphUtility.java

public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) {
    HashMap<String, XYSeriesCollection> datasets = new HashMap<>();
    for (int j = 0; j < games.size(); j++) {
        Game game = games.get(j);/* ww w . j a v  a2s . com*/
        if (game == null) {
            continue;
        }
        for (String key : game.getVarData().keySet()) {
            if (datasets.containsKey(key)) {
                try {
                    datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
                } catch (Exception e) {
                }
            } else {
                datasets.put(key, new XYSeriesCollection());
                datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId()));
            }
        }
    }
    HashMap<String, ChartPanel> chartPanels = new HashMap<>();
    for (String key : datasets.keySet()) {
        JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
                "X", // x axis label
                "Y", // y axis label
                datasets.get(key), // data
                PlotOrientation.VERTICAL, false, // include legend
                true, // tooltips
                false // urls
        );
        XYPlot plot = chart.getXYPlot();
        XYItemRenderer rend = plot.getRenderer();
        for (int i = 0; i < games.size(); i++) {
            Game g = games.get(i);
            if (g.getWinner() == 1) {
                rend.setSeriesPaint(i, Color.RED);
            }
            if (g.getWinner() == 2) {
                rend.setSeriesPaint(i, Color.BLACK);
            }
            if (g.getWinner() == 0) {
                rend.setSeriesPaint(i, Color.PINK);
            }
        }
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanels.put(key, chartPanel);
    }
    return chartPanels;
}

From source file:com.scaniatv.LangFileUpdater.java

/**
 * Method that gets the ID from the custom and default lang file, and adds 
 * missing lang IDs to the custom one, plus returns the lang ID and matches in a HashMap.
 * /* w  ww  .j  a v a2 s .c  o  m*/
 * @param defaultLang
 * @param customLang
 * @return 
 */
private static HashMap<String, String> getCustomAndDefaultLangMap(String defaultLang, String customLang) {
    // Create a new patter that will match if the default lang ID is also in the custom one.
    final Pattern pattern = Pattern.compile(
            "^\\$\\.lang\\.register\\((\\'|\\\")([a-zA-Z0-9,.-]+)(\\'|\\\")\\,\\s(\\'|\\\")(.*)(\\'|\\\")\\);",
            Pattern.MULTILINE);

    // Get all matches for the default lang.
    final Matcher m1 = pattern.matcher(defaultLang);
    final HashMap<String, String> defaultMatches = new HashMap<>();
    while (m1.find()) {
        defaultMatches.put(m1.group(2), m1.group(5));
    }

    // Get all matches for the custom lang.
    final Matcher m2 = pattern.matcher(customLang);
    final HashMap<String, String> customMatches = new HashMap<>();
    while (m2.find()) {
        customMatches.put(m2.group(2), m2.group(5));
    }

    // Check if any is missing in the custom one.
    defaultMatches.forEach((String key, String value) -> {
        if (!customMatches.containsKey(key)) {
            customMatches.put(key, value);
        }
    });

    return customMatches;
}

From source file:eu.europa.ec.fisheries.uvms.exchange.search.SearchFieldMapper.java

/**
 * Takes all the search values and categorizes them in lists to a key
 * according to the SearchField/*  www .j  a va 2 s  .com*/
 *
 * @param searchValues
 * @return
 */
public static HashMap<ExchangeSearchField, List<SearchValue>> combineSearchFields(
        List<SearchValue> searchValues) {
    HashMap<ExchangeSearchField, List<SearchValue>> values = new HashMap<>();
    for (SearchValue search : searchValues) {
        if (values.containsKey(search.getField())) {
            values.get(search.getField()).add(search);
        } else {
            values.put(search.getField(), new ArrayList<SearchValue>(Arrays.asList(search)));
        }

    }
    return values;
}

From source file:com.ciphertool.sentencebuilder.dao.IndexedWordMapDao.java

/**
 * @param allWords//from   w w w  .j  a v  a 2s . c  o  m
 *            the List of all Words pulled in from the constructor
 * @return a Map of all Words keyed by their length
 */
protected static Map<Integer, ArrayList<Word>> mapByWordLength(List<Word> allWords) {
    if (allWords == null || allWords.isEmpty()) {
        throw new IllegalArgumentException(
                "Error mapping Words by length.  The supplied List of Words cannot be null or empty.");
    }

    HashMap<Integer, ArrayList<Word>> byLength = new HashMap<Integer, ArrayList<Word>>();

    for (Word w : allWords) {
        Integer wordLength = w.getId().getWord().length();

        // Add the part of speech to the map if it doesn't exist
        if (!byLength.containsKey(wordLength)) {
            byLength.put(wordLength, new ArrayList<Word>());
        }

        byLength.get(wordLength).add(w);
    }

    return byLength;
}