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:de.steilerdev.myVerein.server.controller.user.EventController.java

@RequestMapping(produces = "application/json", params = { "id", "response" }, method = RequestMethod.GET)
public ResponseEntity<List<String>> getResponsesOfEvent(@RequestParam(value = "response") String responseString,
        @RequestParam(value = "id") String eventID, @CurrentUser User currentUser) {
    logger.debug("[{}] Finding all responses of type {} to event {}", currentUser, responseString, eventID);
    Event event;//from   w w w  .  jav  a  2  s .  c om
    if (eventID.isEmpty()) {
        logger.warn("[{}] The event id is not allowed to be empty", currentUser);
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    } else if ((event = eventRepository.findEventById(eventID)) == null) {
        logger.warn("[{}] Unable to gather the specified event with id {}", currentUser, eventID);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        EventStatus response;
        try {
            response = EventStatus.valueOf(responseString.toUpperCase());
        } catch (IllegalArgumentException e) {
            logger.warn("[{}] Unable to parse response: {}", currentUser, e.getLocalizedMessage());
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }

        if (!event.getInvitedUser().containsKey(currentUser.getId())) {
            logger.warn("[{}] User is not invited to the event");
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        } else {
            // Filtering invited user matching the response
            HashMap<String, EventStatus> invitedUser = new HashMap<>(event.getInvitedUser());
            List<String> matchingUser = invitedUser.keySet().stream()
                    .filter(userID -> invitedUser.get(userID) == response).collect(Collectors.toList());

            logger.info("[{}] Successfully gathered all user matching the response {} for event {}",
                    currentUser, response, event);
            return new ResponseEntity<>(matchingUser, HttpStatus.OK);
        }
    }
}

From source file:jsentvar.GenerateTestsResults.java

public void substitutionOneTermResult() throws IOException {
    RDFReader lector = new RDFReader();
    String filename;/* w w  w .java 2  s.  c o  m*/
    //filename = "resources/test/miniReasoner.owl";
    filename = "resources/IEEE_reasoner20022016.owl";
    //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);
    ArrayList<String> terms1 = new ArrayList<>();

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

    //Get all the terms for substitution
    Surrogate sur = new Surrogate(model);
    HashMap<String, ArrayList<String>> alternatives;
    Utils utils = new Utils();
    ArrayList<String> terms = utils.firstUpperForeach(terms1);
    alternatives = sur.surrogatesForeach(terms);
    String docFile = "resources/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);
    }
    FileUtils.writeStringToFile(new File("resources/test/substitutionOneTermResult.txt"), newDocs.toString(),
            "utf8");

}

From source file:br.unicamp.ic.recod.gpsi.ml.gpsi1NNToMomentScalarClassificationAlgorithm.java

@Override
public void fit(HashMap<Byte, ArrayList<double[]>> x) {

    int i;//from w w  w .  java2  s. c o  m
    double[] centroid;
    RealMatrix entities;

    this.centroids = new HashMap<>();
    this.nClasses = x.size();
    this.dimensionality = 0;
    for (byte label : x.keySet()) {
        if (this.dimensionality <= 0)
            this.dimensionality = x.get(label).get(0).length;
        entities = MatrixUtils.createRealMatrix(x.get(label).toArray(new double[0][]));
        centroid = new double[this.dimensionality];
        for (i = 0; i < this.dimensionality; i++)
            centroid[i] = this.moment.evaluate(entities.getColumn(i));
        this.centroids.put(label, centroid);
    }

}

From source file:couchdb.CouchdbClient.java

private StringToStringMap updateFields(StringToStringMap toUpdate, HashMap<String, ByteIterator> newValues) {
    for (String updateField : newValues.keySet()) {
        ByteIterator newValue = newValues.get(updateField);
        toUpdate.put(updateField, newValue);
    }//from   ww w.j ava2  s .  com
    return toUpdate;
}

From source file:GUI.ResponseStatistics.java

private PieDataset createDatasetTrueOrFalse(HashMap<String, Double> hm) {
    DefaultPieDataset result = new DefaultPieDataset();

    Set<String> set = hm.keySet();

    for (String s : set) {
        /*//from  w w  w  . j  av a2  s.c om
        Convert into %
        */

        result.setValue(s, hm.get(s));
    }

    return result;

}

From source file:Javafile.java

long findMatchedWords(String s, HashMap words, HashMap matchedWords, JSONArray matchedArrayJSON, int count) {
    String s1;//from  w  ww  . j ava 2 s. c o  m
    int i = 0;
    long totalFind = 0;
    for (Iterator it = words.keySet().iterator(); it.hasNext();) {

        Object key = it.next();
        s1 = key.toString();
        if (s1.contains(s)) {
            totalFind++;
            i++;
            if (i >= count - 10 && i < count) {
                JSONObject matchedWordJSON = new JSONObject();
                matchedWordJSON.put("id", s1);
                matchedWordJSON.put("text", s1);
                matchedArrayJSON.add(matchedWordJSON);
            }
        }
    }
    return totalFind;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetTermsListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".words.tmp");
    try {/*from  w w w .j  av a2 s . co m*/
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write("Filename\tColumn Number\tOriginal Data Value\tNew Data Value\n");
        //  
        HashMap<String, Vector<String>> oldValues = this.setTermsUI.getOldValues();
        HashMap<String, Vector<String>> newValues = this.setTermsUI.getNewValues();

        for (String fullName : oldValues.keySet()) {
            File rawFile = new File(this.dataType.getPath() + File.separator + fullName.split(" - ", -1)[0]);
            String header = fullName.split(" - ", -1)[1];
            int columnNumber = FileHandler.getHeaderNumber(rawFile, header);
            for (int i = 0; i < oldValues.get(fullName).size(); i++) {
                if (newValues.get(fullName).elementAt(i).compareTo("") != 0) {
                    out.write(rawFile.getName() + "\t" + columnNumber + "\t"
                            + oldValues.get(fullName).elementAt(i) + "\t" + newValues.get(fullName).elementAt(i)
                            + "\n");
                }
            }
        }

        out.close();
        try {
            File fileDest;
            if (((ClinicalData) this.dataType).getWMF() != null) {
                String fileName = ((ClinicalData) this.dataType).getWMF().getName();
                ((ClinicalData) this.dataType).getWMF().delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".words");
            }
            FileUtils.moveFile(file, fileDest);
            ((ClinicalData) this.dataType).setWMF(fileDest);
        } catch (IOException ioe) {
            this.setTermsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setTermsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setTermsUI.displayMessage("Word mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
}

From source file:it.iit.genomics.cru.structures.bridges.bridges.UniprotkbUtilsTest.java

public void testGetGenesFromUniprotAcs() throws BridgesRemoteAccessException {

    String[] uniprotAcs = { "Q9NUR3", "P52803", "P02765", "Q9BX66", "P29074", "Q9ULD4" };

    ArrayList<String> uniprotAcsCollection = new ArrayList<>();
    uniprotAcsCollection.addAll(Arrays.asList(uniprotAcs));

    HashMap<String, MoleculeEntry> entries = UniprotkbUtils.getInstance("9606")
            .getUniprotEntriesFromUniprotAccessions(uniprotAcsCollection);

    Assert.assertEquals(uniprotAcs.length, entries.keySet().size());
}

From source file:com.mycompany.frogsssa.testDD.java

@Command(description = "List subscriptions and their status")
public String subscriptions() {
    if (client == null) {
        return "Not started";
    }//w  ww. j a v  a 2s  .  c  om
    StringBuilder sb = new StringBuilder();
    HashMap<List<String>, Boolean> list = client.sublistGet();
    for (List<String> l : list.keySet()) {
        System.out.println("Subscriptions: " + l);
        sb.append("Sub: " + l.get(0) + " " + l.get(1) + "\tActive: " + list.get(l) + "\n");
    }
    return sb.toString();
}

From source file:com.perceptive.epm.perkolcentral.bl.LicensesBL.java

public String getLicenseSummaryChartData() throws ExceptionWrapper {
    String chartData = "";
    try {/* w ww  .j  ava 2 s .c om*/
        HashMap<String, ArrayList<String>> licenseInfoKeyedByLicenseName = getLicenseRelatedInfo();
        String categories = "";
        for (String licenseTypeName : licenseInfoKeyedByLicenseName.keySet()) {
            categories = categories + "<category name='" + StringUtils.abbreviate(licenseTypeName, 15)
                    + "' hoverText='" + licenseTypeName + "'/>";
        }
        String licensePurchased = "";
        String licenseUsedUp = "";
        /*for (Object obj : licenseInfoKeyedByLicenseName.values()) {
        ArrayList<String> values = (ArrayList<String>) obj;
        licensePurchased = licensePurchased + "<set value='" + values.get(0) + "'/>";
        licenseUsedUp = licenseUsedUp + "<set value='" + values.get(1) + "' link='JavaScript: isJavaScriptCall=true;$('#id_selectedLicenseTypeId').val('');'/>";
        } */
        for (Map.Entry<String, ArrayList<String>> obj : licenseInfoKeyedByLicenseName.entrySet()) {
            ArrayList<String> values = obj.getValue();
            licensePurchased = licensePurchased + "<set value='" + values.get(0) + "'/>";
            licenseUsedUp = licenseUsedUp + "<set value='" + values.get(1)
                    + "' link='JavaScript:populateTheDetails(%26apos;" + obj.getKey() + "%26apos;)'/>";
        }
        chartData = "<graph xaxisname='License Type' yaxisname='Number Of Licenses' hovercapbg='DEDEBE' hovercapborder='889E6D' rotateNames='0' yAxisMaxValue='100' numdivlines='9' divLineColor='CCCCCC' divLineAlpha='80' decimalPrecision='0' showAlternateHGridColor='1' AlternateHGridAlpha='30' AlternateHGridColor='CCCCCC' caption='Perceptive Software Kolkata' subcaption='License purchase/distribution summary'>"
                + "<categories font='Arial' fontSize='11' fontColor='000000'>" + categories + "</categories>"
                + "<dataset seriesname='Total License Purchased' color='FDC12E'>" + licensePurchased
                + "</dataset>" + "<dataset seriesname='Total License Used Up' color='56B9F9'>" + licenseUsedUp
                + "</dataset>" + "</graph>";

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return chartData;
}