Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

From source file:bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation.java

private static String printInfo(HashSet<Identify> theBestAndromedaResults,
        HashSet<Identify> theBestSEQUESTResults) {
    ///    bw.write("Score" + "\t" + "LevenshteinDistance" + "\t" + "Sequence" + "\t" + "Charge" + "\t" + "Correct" + "\t" + "Spec" + "\n");
    String result = "";
    HashMap<String, Integer> results_and_levDist = new HashMap<String, Integer>();
    for (Identify andromeda : theBestAndromedaResults) {
        for (Identify sequest : theBestSEQUESTResults) {
            double observedMass = CalculateObservedMass.calculateMass(andromeda.getSpectrum());
            int levenshteinDistance = StringUtils.getLevenshteinDistance(andromeda.getPeptide().getSequence(),
                    sequest.getPeptide().getSequence());
            result = andromeda.getSpectrum().getSpectrumTitle() + "\t"
                    + andromeda.getSpectrum().getPrecursor().getMz() + "\t"
                    + andromeda.getSpectrum().getPrecursor().getPossibleChargesAsString() + "\t" + observedMass
                    + "\t" + andromeda.getScore() + "\t" + sequest.getScore() + "\t"
                    + andromeda.getPeptide().getSequence() + "\t" + sequest.getPeptide().getSequence() + "\t"
                    + levenshteinDistance + "\t" + sequest.getTotalScoredPeps() + "\t"
                    + andromeda.isIsCorrectMatch() + "\t" + sequest.isIsCorrectMatch() + "\n";
            results_and_levDist.put(result, levenshteinDistance);
        }/*from   www  .ja v  a 2s  . c om*/
    }
    int maxDist = Integer.MAX_VALUE, dist = 0;
    for (String res : results_and_levDist.keySet()) {
        dist = results_and_levDist.get(res);
        if (dist < maxDist) {
            result = res;
            maxDist = dist;
        }
    }
    return result;
}

From source file:jsentvar.SubstitutionTest.java

/**
 * Test of oneTerm method, of class Substitution.
 *///from   www  .j a v  a 2s .c o m
@Test
public void testOneTerm() throws IOException {
    System.out.println("Substitution.oneTerm() Test");
    RDFReader lector = new RDFReader();
    String filename;
    //filename = "resources/test/miniReasoner.owl";
    filename = "resources/IEEE_reasoner20022016.owl";
    Model model;
    //String term_value = term_value0.substring(0, 1).toUpperCase() +term_value0.substring(1);

    model = lector.reader(filename);

    //Read positions, a json file
    String possFile = "resources/test/text_doc0.json";
    JsonReader jreader = new JsonReader();
    HashMap<String, HashMap<Integer, Integer>> poss = jreader.reader(possFile);
    /*
    try {
    System.out.println(poss.toString());
    } catch (NullPointerException e) {
    System.out.println("ERROR showing results " + e);
    }
    */
    ArrayList<String> terms1 = new ArrayList<>();

    Set originS = poss.keySet();
    terms1.addAll(originS);

    //Get all the terms for substitution
    /*
    ArrayList<String> terms0 = new ArrayList<>();
            terms0.add("military satellites");
            terms0.add("intelligent_systems");
    */
    Surrogate sur = new Surrogate(model);
    HashMap<String, ArrayList<String>> alternatives;
    Utils utils = new Utils();
    ArrayList<String> terms = utils.firstUpperForeach(terms1);
    alternatives = sur.surrogatesForeach(terms);
    //System.out.println(alternatives.toString());

    String docFile = "resources/test/tex_doc0.txt";
    String doc = FileUtils.readFileToString(new File(docFile), "utf8");
    Substitution gen = new Substitution();
    HashSet newDocs = new HashSet();
    for (String term : terms) {
        System.out.println(term);
        HashSet newDocs0 = gen.oneTerm(doc, term, alternatives.get(term));
        newDocs.addAll(newDocs0);
    }

    String expResult = FileUtils.readFileToString(new File("resources/test/substitutionOneTermResult.txt"),
            "utf8");
    assertEquals(expResult, newDocs.toString());

}

From source file:luceneGazateer.EntryData.java

/**
 * Select the best match for each location name extracted from a document,
 * choosing from among a list of lists of candidate matches. Filter uses the
 * following features: 1) edit distance between name and the resolved name,
 * choose smallest one 2) content (haven't implemented)
 * //from w w w .j a  v a 2  s  .  c  om
 * @param resolvedEntities
 *            final result for the input stream
 * @param allCandidates
 *            each location name may hits several documents, this is the
 *            collection for all hitted documents
 * @throws IOException
 * @throws RuntimeException
 */

private void pickBestCandidates(ArrayList<EntryData> resolvedEntities,
        HashMap<String, ArrayList<ArrayList<String>>> allCandidates) {
    //System.out.println("all candidates:"+ allCandidates.size());
    for (String extractedName : allCandidates.keySet()) {
        ArrayList<ArrayList<String>> cur = allCandidates.get(extractedName);
        int minDistance = Integer.MAX_VALUE, minIndex = -1;
        for (ArrayList<String> entry : cur) {
            resolvedEntities
                    .add(EntryData.getInstance(entry.get(0), entry.get(1), Double.parseDouble(entry.get(2))));
        }

    }
}

From source file:MSUmpire.PSMDataStructure.FragmentSelection.java

public void GenerateTopFragMap(int topNFrag) {
    for (String PepKey : PepFragScore.keySet()) {
        HashMap<String, Float> Frags = PepFragScore.get(PepKey);
        ArrayList<String> frags = new ArrayList<>();
        for (int i = 0; i < topNFrag; i++) {
            float bestscore = 0f;
            String bestfrag = "";
            for (String frag : Frags.keySet()) {
                if (!frags.contains(frag) && Frags.get(frag) > bestscore) {
                    bestscore = Frags.get(frag);
                    bestfrag = frag;/*from w w w . j  a  v  a  2  s. co  m*/
                }
            }
            if (!"".equals(bestfrag)) {
                frags.add(bestfrag);
            }
        }
        TopFrags.put(PepKey, frags);
    }
}

From source file:MSUmpire.PSMDataStructure.FragmentSelection.java

public void GenerateTopPepMap(int topNPep) {
    for (String ProteinKey : ProtPepScore.keySet()) {
        HashMap<String, Float> Peptides = ProtPepScore.get(ProteinKey);
        ArrayList<String> peps = new ArrayList<>();
        for (int i = 0; i < topNPep; i++) {
            float bestscore = 0f;
            String bestpep = "";
            for (String pep : Peptides.keySet()) {
                if (!peps.contains(pep) && Peptides.get(pep) > bestscore) {
                    bestscore = Peptides.get(pep);
                    bestpep = pep;//  w ww  .  j  a  v  a  2 s  . c o  m
                }
            }
            if (!"".equals(bestpep)) {
                peps.add(bestpep);
            }
        }
        TopPeps.put(ProteinKey, peps);
    }
}

From source file:de.hbz.lobid.helper.CompareJsonMaps.java

public boolean writeFileAndTestJson(final JsonNode actual, final JsonNode expected) {
    // generated data to map
    final HashMap<String, String> actualMap = new HashMap<>();
    extractFlatMapFromJsonNode(actual, actualMap);
    // expected data to map
    final HashMap<String, String> expectedMap = new HashMap<>();
    extractFlatMapFromJsonNode(expected, expectedMap);
    CompareJsonMaps.logger.debug("\n##### remove good entries ###");
    Iterator<String> it = actualMap.keySet().iterator();
    removeContext(it);/*from w w w  .  java  2  s .c  om*/
    it = expectedMap.keySet().iterator();
    removeContext(it);
    for (final Entry<String, String> e : expectedMap.entrySet()) {
        CompareJsonMaps.logger.debug("Trying to remove " + e.getKey() + "...");
        if (!actualMap.containsKey(e.getKey())) {
            CompareJsonMaps.logger.warn("At least this element is missing in actual: " + e.getKey());
            return false;
        }
        if (e.getKey().endsWith("Order]")) {
            handleOrderedValues(actualMap, e);
        } else {
            handleUnorderedValues(actualMap, e);
        }
    }
    if (!actualMap.isEmpty()) {
        CompareJsonMaps.logger.warn("Fail - no Equality! These keys/values were NOT expected:");
        actualMap.forEach((key, val) -> CompareJsonMaps.logger.warn("KEY=" + key + " VALUE=" + val));
    } else
        CompareJsonMaps.logger.info("Succeeded - resources are equal");
    return actualMap.size() == 0;
}

From source file:NaraePreference.java

public void put(String key, HashMap<String, String> value) {
    for (String s : value.keySet()) {
        editor.putString(s, value.get(s));
    }//from w w w .  ja  va2 s  .c  o  m
    editor.commit();
    keylist.add(key);
}

From source file:eu.planets_project.tb.impl.AdminManagerImpl.java

private String getKeyFromHashMap(String expTypeName, HashMap<String, String> experimentTypes) {
    Iterator<String> itKeys = experimentTypes.keySet().iterator();
    while (itKeys.hasNext()) {
        String sKey = itKeys.next();
        if (experimentTypes.get(sKey).equals(expTypeName)) {
            return sKey;
        }//from ww w.  j  ava2  s.  c o  m
    }
    return null;
}

From source file:cachedataanalysis.FlowCache.java

public XYSeries exportReportChart() throws IOException {

    File outputHitRate = new File("report/" + name + "_" + policy + "_hitrate.txt");

    FileWriter fw = new FileWriter(outputHitRate);

    XYSeries hitRateCount = new XYSeries(name + "(" + size + " entries)");

    for (int i = 0; i < hitRateRecord.size(); i++) {
        hitRateCount.add(i, hitRateRecord.get(i));
        fw.write(i + "," + hitRateRecord.get(i) + "\n");
        fw.flush();//from w ww .  j a  va 2 s.  com
    }
    fw.close();

    XYSeriesCollection HitRateData = new XYSeriesCollection();
    HitRateData.addSeries(hitRateCount);
    JFreeChart hitRateStat = ChartFactory.createXYLineChart(
            "Hit Rate variatoion throughout recording in " + name, "Seconds", "HitRate", HitRateData,
            PlotOrientation.VERTICAL, true, true, false);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitRate" + size + ".jpg"), hitRateStat, 1500,
            900);

    //-------------------------------

    if (!fullReport) {
        return hitRateCount;
    }

    DefaultPieDataset hitProtoData = new DefaultPieDataset();
    DefaultPieDataset missProtoData = new DefaultPieDataset();

    CategoryTableXYDataset hitProtoDataRec = new CategoryTableXYDataset();
    for (int i = 0; i < hitProtoRec.size(); i++) {
        if (i % 120 != 0) {
            continue;
        }
        HashMap<String, Integer> _map = hitProtoRec.get(i);
        for (String _str : _map.keySet()) {
            hitProtoDataRec.add(i, _map.get(_str), _str);
        }

    }

    CategoryTableXYDataset missProtoDataRec = new CategoryTableXYDataset();
    for (int i = 0; i < missProtoRec.size(); i++) {
        if (i % 120 != 0) {
            continue;
        }
        HashMap<String, Integer> _map = missProtoRec.get(i);
        for (String _str : _map.keySet()) {
            missProtoDataRec.add(i, _map.get(_str), _str);
        }

    }

    XYSeries hitCountData = new XYSeries("Hit");
    XYSeries allCountData = new XYSeries("All");

    for (int i = 0; i < hitCount.size(); i++) {
        hitCountData.add(i, hitCount.get(i));
        //hitRateCount.add(i,(float)hitCount.get(i)/(hitCount.get(i)+allCount.get(i)));
    }

    for (int i = 0; i < allCount.size(); i++) {
        allCountData.add(i, allCount.get(i));

    }

    XYSeriesCollection CountStatData = new XYSeriesCollection();

    CountStatData.addSeries(hitCountData);
    CountStatData.addSeries(allCountData);

    for (String protocol : hitProto.keySet()) {
        hitProtoData.setValue(protocol, hitProto.get(protocol));
    }

    for (String protocol : missProto.keySet()) {
        missProtoData.setValue(protocol, missProto.get(protocol));
    }

    JFreeChart hitStatRec = ChartFactory.createStackedXYAreaChart(
            "Hit Protocol Fraction throughout record in " + name, "Seconds", "Count", hitProtoDataRec);

    JFreeChart missStatRec = ChartFactory.createStackedXYAreaChart(
            "Miss Protocol Fraction throughout record in " + name, "Seconds", "Count", missProtoDataRec);

    JFreeChart hitStat = ChartFactory.createPieChart3D("Protocal Fraction of Hit Flows in " + name,
            hitProtoData, true, true, false);
    JFreeChart missStat = ChartFactory.createPieChart3D("Protocal Fraction of Miss Flows in " + name,
            missProtoData, true, true, false);
    JFreeChart countStat = ChartFactory.createXYAreaChart("Hit Count to All Packet lookup in " + name,
            "Seconds", "Count", CountStatData, PlotOrientation.VERTICAL, true, true, false);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProto" + size + ".jpg"), hitStat, 1500,
            900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProto" + size + ".jpg"), missStat, 1500,
            900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitCount" + size + ".jpg"), countStat, 1500,
            900);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProtoRecord" + size + ".jpg"), hitStatRec,
            1500, 900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProtoRecord" + size + ".jpg"), missStatRec,
            1500, 900);

    return hitRateCount;
}

From source file:eu.scape_project.archiventory.identifiers.Identification.java

/**
 * File list identification. Processing a bi-directional map of records
 * where each record has one temporary file and each temporary file has one
 * record key (strict 1:1 relationship).
 *
 * @param fileRecidBidiMap Input { "recordkey" <-> "tempfilename" }
 * @return Output { "recordkey": [ "tool/property/value" ] }
 * @throws IOException//from  w w w .  j  a  v  a2s .c  o  m
 */
public HashMap<String, List<String>> identifyFileList(DualHashBidiMap fileRecidBidiMap) throws IOException {
    HashMap<String, List<String>> resultMap = new HashMap<String, List<String>>();
    Iterator iter = fileRecidBidiMap.keySet().iterator();
    while (iter.hasNext()) {
        String recordKey = (String) iter.next();
        String tmpFileName = (String) fileRecidBidiMap.get(recordKey);
        File file = new File(tmpFileName);
        HashMap idRes = this.identify(file);
        String containerFileName = recordKey.substring(0, recordKey.indexOf("/"));
        String containerIdentifier = recordKey.substring(recordKey.indexOf("/") + 1);
        String outputKey = String.format(outputKeyFormat, containerFileName, containerIdentifier);
        List<String> valueLineList = new ArrayList<String>();
        for (Object k : idRes.keySet()) {
            String property = (String) k;
            String value = (String) idRes.get(k);
            String outputValue = String.format(outputValueFormat, tool, property, value);
            valueLineList.add(outputValue);

        }
        resultMap.put(outputKey, valueLineList);
    }
    return resultMap;
}