Example usage for java.util HashMap size

List of usage examples for java.util HashMap size

Introduction

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

Prototype

int size

To view the source code for java.util HashMap size.

Click Source Link

Document

The number of key-value mappings contained in this map.

Usage

From source file:com.glluch.ecf2xmlmaven.Writer.java

protected static void writePart2Solr(String path, String txt, String solrType, String id, String solrComment)
        throws IOException {

    HashMap<String, Integer> terms;
    terms = ieee.findTerms(txt);// ww  w . j  a v  a 2 s . c o m
    if (terms.size() > 0) {
        String xml = "<add><doc>" + System.lineSeparator();
        //Mandatory params
        xml += "<field name=\"id\"";
        xml += ">";
        xml += id;

        xml += "</field>" + System.lineSeparator();
        xml += "<field name=\"type\">" + solrType;
        xml += "</field>" + System.lineSeparator();

        //terms
        xml += terms2xml("ieee_term", terms) + System.lineSeparator();
        //optional elements
        if (StringUtils.isNotEmpty(solrComment)) {

            xml += "<field name=\"comment\">" + solrComment;
            xml += "</field>" + System.lineSeparator();
        }

        //end of xml
        xml += "</doc></add>";
        //competencesXMLsolr
        String fileTitle = path + id + ".xml";
        FileUtils.writeStringToFile(new File(fileTitle), xml);
    } else {
        show(id + " has no ieee terms");
    }

}

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 ww w  .  ja v  a2s  .  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:com.hangum.tadpole.commons.sql.util.SQLUtil.java

/**
 * INSERT ? ?./*from  w  w  w . j  a  v a2 s  .co m*/
 * 
 * @param tableName
 * @param rs
 * @return
 * @throws Exception
 */
public static String makeInsertStatment(String tableName, ResultSet rs) throws Exception {
    StringBuffer result = new StringBuffer("INSERT INTO " + tableName + "(");

    HashMap<Integer, String> mapTable = mataDataToMap(rs);
    for (int i = 0; i < mapTable.size(); i++) {
        if (i != (mapTable.size() - 1))
            result.append(mapTable.get(i) + ",");
        else
            result.append(mapTable.get(i));
    }

    result.append(") VALUES(");

    for (int i = 0; i < mapTable.size(); i++) {
        if (i != (mapTable.size() - 1))
            result.append("?,");
        else
            result.append('?');
    }

    result.append(')');

    if (logger.isDebugEnabled())
        logger.debug("[make insert statment is " + result.toString());

    return result.toString();
}

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

/**
 * @param zip1/*ww w  .j a  v a 2 s. com*/
 * @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  ava 2s  .  c om
 * @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:eu.digitisation.idiomaident.utils.CorpusFilter.java

private static void eliminateNames(HashSet<String> posibleNames, HashMap<String, String> actualFile) {
    for (String name : posibleNames) {
        //Check if the name is in allmost the others languages
        double totalLenguages = actualFile.size();

        int goal = (int) (totalLenguages * 0.8); //80% of the lenguages

        int contains = 0;

        for (String lang : actualFile.keySet()) {
            if (actualFile.get(lang).contains(name)) {
                contains++;//from w w w . j av a2 s. c  om
            }
        }

        if (contains >= goal) //Eliminate the name
        {
            //System.out.println(name);

            for (String lang : actualFile.keySet()) {
                String text = actualFile.get(lang);

                String replacement = "(\\p{Space}|\\p{Punct})+" + name + "(\\p{Space}|\\p{Punct})+";

                text = text.replaceAll(replacement, " ");

                actualFile.put(lang, text);
            }
        }

    }
}

From source file:com.clustercontrol.maintenance.factory.HinemosPropertyInfoCache.java

/**
 * /* w  w w  .j a v  a 2s.c o  m*/
 */
public static synchronized void refresh() {
    try {
        _lock.writeLock();

        long startTime = HinemosTime.currentTimeMillis();

        new JpaTransactionManager().getEntityManager().clear();
        HashMap<String, HinemosPropertyInfo> cache = createHinemosPropertyInfoMap();
        storeCache(cache);

        log.info(String.format("refresh: %dms size=%d", HinemosTime.currentTimeMillis() - startTime,
                cache.size()));
    } finally {
        _lock.writeUnlock();
    }
}

From source file:Main.java

public static HashMap<Integer, ArrayList<Double>> transposeHashMap(HashMap<Integer, ArrayList<Double>> data) {
    HashMap<Integer, ArrayList<Double>> dataT = new HashMap<Integer, ArrayList<Double>>();
    //transpose data to get data for each sensor channel
    for (int i = 0; i < data.get(0).size(); i++) {
        ArrayList<Double> tmp = new ArrayList<Double>();
        for (int j = 0; j < data.size(); j++) {
            tmp.add(data.get(j).get(i));
        }/*from w  w w  . ja  v  a 2  s.c  o m*/
        dataT.put(i, tmp);
    }
    return dataT;
}

From source file:bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation.java

private static String result(MSnSpectrum msms, double precursorTolerance, HashSet<DBEntry> peptideAndMass,
        double fragmentTolerance, int correctionFactor, boolean hasAllPossCharge)
        throws IllegalArgumentException, IOException, MzMLUnmarshallerException {
    String res = "";
    HashMap<Peptide, Boolean> allSelectedPeps = getSelectedTheoPeps(msms, precursorTolerance, peptideAndMass); // select peptides within a given precursor tolerance
    int scoredPeps = allSelectedPeps.size();
    ArrayList<Identify> sequestResults = new ArrayList<Identify>(),
            andromedaResults = new ArrayList<Identify>();
    // for every peptide... calculate each score...
    for (Peptide selectedPep : allSelectedPeps.keySet()) {
        Identify toCalculateSequest = new Identify(msms, selectedPep, fragmentTolerance, true,
                allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge),
                toCalculateAndromeda = new Identify(msms, selectedPep, fragmentTolerance, false,
                        allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge);
        if (toCalculateSequest.getScore() != Double.NEGATIVE_INFINITY) {
            sequestResults.add(toCalculateSequest);
            andromedaResults.add(toCalculateAndromeda);
        }/*  ww w  . ja  v  a 2 s .co  m*/
    }
    if (!sequestResults.isEmpty()) {
        HashSet<Identify> theBestSEQUESTResults = getBestResult(sequestResults),
                theBestAndromedaResults = getBestResult(andromedaResults);
        res = printInfo(theBestAndromedaResults, theBestSEQUESTResults);
    }
    return res;
}

From source file:Main.java

public static String decodeLZW(int[] encodedText, HashMap<Integer, String> dict, int dictSize) {
    String decodedText = "";

    for (int i = 0; i < encodedText.length; i++) {
        String nextString = "";
        String currentEntry = dict.get(encodedText[i]);

        decodedText = decodedText.concat(currentEntry);

        if (i + 1 < encodedText.length && dict.size() < dictSize) {
            if (encodedText[i + 1] < dict.size())
                nextString = dict.get(encodedText[i + 1]);
            else/*from   ww w  .  ja  va 2 s  .  c om*/
                nextString = currentEntry;

            String nextChar = String.valueOf(nextString.charAt(0));

            if (!dict.containsValue(currentEntry.concat(nextChar))) {
                dict.put(dict.size(), currentEntry.concat(nextChar));
            }
        }
    }
    return decodedText;
}