List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:com.itemanalysis.jmetrik.data.JmetrikFileReaderTest.java
@Test public void headerTest() { System.out.println("JmetrikFileReader: header test"); File f = FileUtils.toFile(this.getClass().getResource("/data/example-import-file.jmetrik")); HashMap<VariableName, VariableAttributes> variableAttributeMap = null; try (JmetrikFileReader reader = new JmetrikFileReader(f)) { reader.openConnection();/*w w w. j a v a 2s . co m*/ variableAttributeMap = reader.getVariableAttributes(); for (VariableName v : variableAttributeMap.keySet()) { System.out.println(variableAttributeMap.get(v).toString()); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:it.uniud.ailab.dcore.annotation.annotators.TagMeTokenAnnotator.java
/** * Annotates a single sentence with the Wikipedia flag. Used as base case * for recursion.//from w w w .ja va 2s. c o m * * @param sentence the sentence to annotate. */ private void annotateSentence(Sentence sentence) { String text = sentence.getText(); // Retrieve the tagMe annotations using the internal TagMe wrapper HashMap<String, String> taggedSentence = tagSentence(text, sentence.getLanguage().getLanguage()); // Put the annotations in the appropriate token for (String surface : taggedSentence.keySet()) { String matchedSurface = surface; List<Token> matchedTokens = new ArrayList<>(); for (Token t : sentence.getTokens()) { String part = t.getText(); if (!matchedSurface.startsWith(part)) continue; matchedTokens.add(t); matchedSurface = matchedSurface.substring(part.length()); while (matchedSurface.startsWith(" ")) matchedSurface = matchedSurface.substring(1); } if (!matchedTokens.isEmpty()) { TextAnnotation ann = new TextAnnotation(WIKIFLAG, matchedTokens.toArray(new Token[matchedTokens.size()]), taggedSentence.get(surface)); matchedTokens.stream().forEach(t -> { t.addAnnotation(ann); }); } } /* for (Token t : sentence.getTokens()) { String part = t.getText(); boolean match = false; List<Token> matchedTokens = new ArrayList<>(); for (String surface : taggedSentence.keySet()) { if (surface.contains(part)) { ; } } TextAnnotation ann = new TextAnnotation(WIKIFLAG, matchedTokens, taggedSentence.get(surface)); t.addAnnotation(ann); }*/ }
From source file:communicator.doMove.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www.ja v a2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = null; JSONObject outputObject = new JSONObject(); try { HashMap<String, String> bigItemIds = new HashMap<>(); Iterator mIterator = bigItemIds.keySet().iterator(); out = response.getWriter(); // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Configure a repository (to ensure a secure temp location is used) ServletContext servletContext = this.getServletConfig().getServletContext(); File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir"); factory.setRepository(repository); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> items = upload.parseRequest(request); final String moveId = UUID.randomUUID().toString(); final MovesDb movesDb = new MovesDb(); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) { System.out.println("Form field" + item.getString()); bigItemIds = processFormField(new JSONObject(item.getString()), out, moveId, movesDb); mIterator = bigItemIds.keySet().iterator(); System.out.println("ITEM ID SIZE " + bigItemIds.size()); } else { //processUploadedFile(item); System.out.print("Photo Field"); String key = (String) mIterator.next(); File mFile = new File(bigItemIds.get(key)); item.write(mFile); } } new Thread() { public void run() { pushMovetoMailQueue moveToMailQueue = new pushMovetoMailQueue(); moveToMailQueue.pushMoveToMailQueue(movesDb); } }.start(); outputObject = new JSONObject(); try { outputObject.put(Constants.JSON_STATUS, Constants.JSON_SUCCESS); outputObject.put(Constants.JSON_MSG, Constants.JSON_GET_QUOTE); } catch (JSONException ex1) { Logger.getLogger(doSignUp.class.getName()).log(Level.SEVERE, null, ex1); } out.println(outputObject.toString()); } catch (Exception ex) { outputObject = new JSONObject(); try { outputObject.put(Constants.JSON_STATUS, Constants.JSON_FAILURE); outputObject.put(Constants.JSON_MSG, Constants.JSON_EXCEPTION); } catch (JSONException ex1) { Logger.getLogger(doSignUp.class.getName()).log(Level.SEVERE, null, ex1); } out.println(outputObject.toString()); Logger.getLogger(doSignUp.class.getName()).log(Level.SEVERE, null, ex); } finally { out.close(); } }
From source file:view.ViewReportUI.java
private PieDataset createDataset() { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. DefaultPieDataset result = new DefaultPieDataset(); InvoiceDAO dao = null;/*from w ww.j a v a 2 s . c o m*/ try { HashMap<String, Double> value = new InvoiceDAO().getTotalTillNow(); FileManager manager = new FileManager(); String[] categories = manager.getFileContent("Database/category.txt"); for (String key : value.keySet()) { result.setValue(key + "$ " + value.get(key), value.get(key)); } } catch (SQLException ex) { Logger.getLogger(ViewReportUI.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(ViewReportUI.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.linuxbox.enkive.imap.mailbox.mongo.MongoEnkiveImapMailboxMapper.java
@Override public List<Mailbox<String>> findMailboxWithPathLike(MailboxPath mailboxPath) { String mailboxSearchPath = mailboxPath.getName(); ArrayList<Mailbox<String>> mailboxes = new ArrayList<Mailbox<String>>(); if (mailboxSearchPath.equals("%")) try {/* w w w . ja va2s . c o m*/ return list(); } catch (MailboxException e) { LOGGER.error("Error retrieving list of mailboxes for user " + session.getUser().getUserName(), e); } else if (mailboxPath.getName().matches(MailboxConstants.INBOX)) { MailboxPath inboxPath = new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), MailboxConstants.INBOX); mailboxes.add(new EnkiveImapMailbox(inboxPath, 1)); } else if (mailboxPath.getName().matches("Trash")) { MailboxPath trashPath = new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), "Trash"); mailboxes.add(new EnkiveImapMailbox(trashPath, 1)); } else { DBObject mailboxListObject = getMailboxList(); if (mailboxListObject != null) { @SuppressWarnings("unchecked") HashMap<String, String> mailboxTable = (HashMap<String, String>) mailboxListObject .get(MongoEnkiveImapConstants.MAILBOXES); for (String mailboxKey : mailboxTable.keySet()) { String updatedMailboxKey = mailboxKey.replace('/', '.'); String regex = mailboxSearchPath.replace(".", "+\\.+"); regex = regex.replace('%', '.') + "*"; if (updatedMailboxKey.matches(regex)) { MailboxPath matchingMailboxPath = new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), updatedMailboxKey); EnkiveImapMailbox mailbox = new EnkiveImapMailbox(matchingMailboxPath, 1); mailbox.setMailboxId(mailboxTable.get(mailboxKey)); mailboxes.add(mailbox); } } } } return mailboxes; }
From source file:kmi.taa.core.SmallSetAnalyser.java
protected void detect(double threshold, String pptytype) { if (hm.isEmpty()) { return;//from w ww . jav a2 s . c om } for (Integer k : hm.keySet()) { HashMap<Integer, Double> totalset = hm.get(k); if (totalset.size() > 2 && totalset.size() <= 4) { double mean = mean(totalset); double std = std(totalset); for (Integer tid : totalset.keySet()) { if (tid == 0) continue; double data = totalset.get(tid); if (Math.abs(data - mean) <= threshold * std) { notol.add(tid); } } } else { for (Integer tid : totalset.keySet()) { if (tid == 0) continue; notol.add(tid); } } } }
From source file:com.thoughtworks.go.domain.scm.SCMs.java
private void validateNameUniqueness() { HashMap<String, SCMs> map = new HashMap<>(); for (SCM scm : this) { String name = scm.getName().toLowerCase(); if (!map.containsKey(name)) { map.put(name, new SCMs()); }/*from www .ja v a 2 s .c om*/ map.get(name).add(scm); } for (String name : map.keySet()) { SCMs scmsWithSameName = map.get(name); if (scmsWithSameName.size() > 1) { for (SCM scm : scmsWithSameName) { scm.addError(SCM.NAME, String.format( "Cannot save SCM, found multiple SCMs called '%s'. SCM names are case-insensitive and must be unique.", scm.getName())); } } } }
From source file:io.fabric8.elasticsearch.plugin.acl.SearchGuardRoles.java
@SuppressWarnings("unchecked") public SearchGuardRoles load(Map<String, Object> source) { RolesBuilder builder = new RolesBuilder(); for (String key : source.keySet()) { RoleBuilder roleBuilder = new RoleBuilder(key); // get out cluster and indices HashMap<String, Object> role = (HashMap<String, Object>) source.get(key); List<String> cluster = (ArrayList<String>) role.get(CLUSTER_HEADER); roleBuilder.setClusters(cluster); HashMap<String, HashMap<String, ArrayList<String>>> indices = (HashMap<String, HashMap<String, ArrayList<String>>>) role .get(INDICES_HEADER);/* w ww .j a v a2 s. c om*/ for (String index : indices.keySet()) { for (String type : indices.get(index).keySet()) { List<String> actions = indices.get(index).get(type); roleBuilder.setActions(index, type, actions); } } builder.addRole(roleBuilder.build()); } roles = builder.build(); return this; }
From source file:org.shareok.data.plosdata.PlosDoiDataImpl.java
@Override public void convertHashMapDataToDoi(HashMap mapData) throws Exception { Set keys = mapData.keySet(); Iterator it = keys.iterator(); ArrayList<String> doiList = new ArrayList<>(); while (it.hasNext()) { String key = (String) it.next(); String value = (String) mapData.get(key); // the values is composed of "val--datatype": for example, Tom--Str or 0.50--num String[] values = value.split("--"); if (null == values || values.length != 2) continue; String type = values[1];/*from w w w . j a va2 s. c o m*/ value = values[0]; String[] rowCol = key.split("-"); if (null == rowCol || rowCol.length != 2) throw new Exception("The row and column are not specifid!"); int row = Integer.parseInt(rowCol[0]); int col = Integer.parseInt(rowCol[1]); if (col == 3 && value.contains("/journal.p")) { int index = value.toLowerCase().indexOf("plos "); if (index == -1) continue; String doiVal = value.substring(index); Pattern pattern = Pattern.compile("(e)(\\d{1,10})(.)(\\s*)(doi:)"); Matcher matcher = pattern.matcher(doiVal); if (matcher.find()) { String[] doiInfo = doiVal.split(":"); if (doiInfo.length != 3) continue; String isPartOfSeries = doiInfo[0] + ":" + matcher.group(1) + matcher.group(2); doiVal = isPartOfSeries + "---" + doiInfo[2]; doiList.add(doiVal); //System.out.println("Matcher find the string for "+doiInfo[0]+"!!! \n");//System.out.println(matcher.group(1) + " - " + matcher.group(2)); } else { System.out.println("Matcher cannot find the string for " + doiVal + "!!! \n"); } } } setDoiData(doiList); }
From source file:com.sfs.whichdoctor.importer.ExamImporter.java
/** * Commit./*from w w w.j av a 2 s . co m*/ * * @param user the user * @param privileges the privileges * @param examDAO the exam dao * * @return the int */ public final int commit(final UserBean user, final PrivilegesBean privileges, final ExamDAO examDAO) { int newEntries = 0; HashMap<Object, List<Object>> beanMap = this.getBeanMap(); if (beanMap != null) { for (Object objPerson : beanMap.keySet()) { PersonBean person = (PersonBean) objPerson; List<Object> exams = beanMap.get(person); for (Object objExam : exams) { ExamBean exam = (ExamBean) objExam; importLogger.info("Creating exam: " + exam.getReferenceGUID() + ": " + exam.getType() + ": " + exam.getDateSat()); try { int examId = examDAO.create(exam, user, privileges); if (examId > 0) { // Successfully created, add to success map setSuccess(getIndexDescription(person), getValueDescription(exam)); newEntries++; } else { // Failed to create, add to failed map setFailure(getIndexDescription(person), getValueDescription(exam)); } } catch (Exception e) { importLogger.error("Error creating exam: " + e.getMessage()); // Add to failed map setFailure(getIndexDescription(person), getValueDescription(exam)); } } } } return newEntries; }