List of usage examples for java.util HashMap values
public Collection<V> values()
From source file:gov.llnl.lc.smt.command.node.SmtNode.java
/** * Describe the method here//w w w. j a v a2s. c o m * * @see describe related java objects * ***********************************************************/ private void dumpAllNodes() { HashMap<String, OSM_Node> nodes = getOSM_Nodes(); for (OSM_Node n : nodes.values()) System.out.println(n.toVerboseString()); }
From source file:org.openmrs.logic.db.hibernate.HibernateLogicPatientDAO.java
@SuppressWarnings("unchecked") private List<Patient> logicToHibernate(LogicExpression expression, Collection<Integer> patientIds) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Patient.class); criteria.createAlias("identifiers", "identifier"); Date indexDate = Calendar.getInstance().getTime(); Operator transformOperator = null;// w ww. java 2 s .c om LogicTransform transform = expression.getTransform(); Integer numResults = null; if (transform != null) { transformOperator = transform.getTransformOperator(); numResults = transform.getNumResults(); } if (numResults == null) { numResults = 1; } // set the transform and evaluate the right criteria // if there is any if (transformOperator == Operator.DISTINCT) { criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } Criterion c = this.getCriterion(expression, indexDate, criteria); if (c != null) { criteria.add(c); } List<Patient> results = new ArrayList<Patient>(); criteria.add(Restrictions.in("patientId", patientIds)); results.addAll(criteria.list()); //return a single result per patient for these operators //I don't see an easy way to do this in hibernate so I am //doing some post processing if (transformOperator == Operator.FIRST || transformOperator == Operator.LAST) { HashMap<Integer, ArrayList<Patient>> nResultMap = new HashMap<Integer, ArrayList<Patient>>(); for (Patient currResult : results) { Integer currPatientId = currResult.getPatientId(); ArrayList<Patient> prevResults = nResultMap.get(currPatientId); if (prevResults == null) { prevResults = new ArrayList<Patient>(); nResultMap.put(currPatientId, prevResults); } if (prevResults.size() < numResults) { prevResults.add(currResult); } } if (nResultMap.values().size() > 0) { results.clear(); for (ArrayList<Patient> currPatientPatient : nResultMap.values()) { results.addAll(currPatientPatient); } } } return results; }
From source file:org.openmrs.logic.db.hibernate.HibernateLogicPersonDAO.java
@SuppressWarnings("unchecked") private List<Person> logicToHibernate(LogicExpression expression, Collection<Integer> personIds) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Person.class); criteria.createAlias("names", "name"); Date indexDate = Calendar.getInstance().getTime(); Operator transformOperator = null;//from www . ja v a2 s . c o m LogicTransform transform = expression.getTransform(); Integer numResults = null; if (transform != null) { transformOperator = transform.getTransformOperator(); numResults = transform.getNumResults(); } if (numResults == null) { numResults = 1; } // set the transform and evaluate the right criteria // if there is any if (transformOperator == Operator.DISTINCT) { criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } Criterion c = this.getCriterion(expression, indexDate, criteria); if (c != null) { criteria.add(c); } List<Person> results = new ArrayList<Person>(); criteria.add(Restrictions.in("personId", personIds)); results.addAll(criteria.list()); //return a single result per patient for these operators //I don't see an easy way to do this in hibernate so I am //doing some postprocessing if (transformOperator == Operator.FIRST || transformOperator == Operator.LAST) { HashMap<Integer, ArrayList<Person>> nResultMap = new HashMap<Integer, ArrayList<Person>>(); for (Person currResult : results) { Integer currPersonId = currResult.getPersonId(); ArrayList<Person> prevResults = nResultMap.get(currPersonId); if (prevResults == null) { prevResults = new ArrayList<Person>(); nResultMap.put(currPersonId, prevResults); } if (prevResults.size() < numResults) { prevResults.add(currResult); } } if (nResultMap.values().size() > 0) { results.clear(); for (ArrayList<Person> currPatientPerson : nResultMap.values()) { results.addAll(currPatientPerson); } } } return results; }
From source file:de.tudarmstadt.ukp.dkpro.core.io.conll.Conll2000Writer.java
private void convert(JCas aJCas, PrintWriter aOut) { Type chunkType = JCasUtil.getType(aJCas, Chunk.class); Feature chunkValue = chunkType.getFeatureByBaseName("chunkValue"); for (Sentence sentence : select(aJCas, Sentence.class)) { HashMap<Token, Row> ctokens = new LinkedHashMap<Token, Row>(); // Tokens List<Token> tokens = selectCovered(Token.class, sentence); // Chunks IobEncoder encoder = new IobEncoder(aJCas.getCas(), chunkType, chunkValue); for (int i = 0; i < tokens.size(); i++) { Row row = new Row(); row.id = i + 1;/*from w w w . j a v a 2s . c o m*/ row.token = tokens.get(i); row.chunk = encoder.encode(tokens.get(i)); ctokens.put(row.token, row); } // Write sentence in CONLL 2006 format for (Row row : ctokens.values()) { String pos = UNUSED; if (writePos && (row.token.getPos() != null)) { POS posAnno = row.token.getPos(); pos = posAnno.getPosValue(); } String chunk = UNUSED; if (writeChunk && (row.chunk != null)) { chunk = encoder.encode(row.token); } aOut.printf("%s %s %s\n", row.token.getCoveredText(), pos, chunk); } aOut.println(); } }
From source file:com.uber.hoodie.TestHoodieClientOnCopyOnWriteStorage.java
/** * Test to ensure commit metadata points to valid files *//*from w ww . java 2 s .co m*/ @Test public void testCommitWritesRelativePaths() throws Exception { HoodieWriteConfig cfg = getConfigBuilder().withAutoCommit(false).build(); HoodieWriteClient client = new HoodieWriteClient(jsc, cfg); HoodieTableMetaClient metaClient = new HoodieTableMetaClient(jsc.hadoopConfiguration(), basePath); HoodieTable table = HoodieTable.getHoodieTable(metaClient, cfg, jsc); String commitTime = "000"; client.startCommitWithTime(commitTime); List<HoodieRecord> records = dataGen.generateInserts(commitTime, 200); JavaRDD<HoodieRecord> writeRecords = jsc.parallelize(records, 1); JavaRDD<WriteStatus> result = client.bulkInsert(writeRecords, commitTime); assertTrue("Commit should succeed", client.commit(commitTime, result)); assertTrue("After explicit commit, commit file should be created", HoodieTestUtils.doesCommitExist(basePath, commitTime)); // Get parquet file paths from commit metadata String actionType = metaClient.getCommitActionType(); HoodieInstant commitInstant = new HoodieInstant(false, actionType, commitTime); HoodieTimeline commitTimeline = metaClient.getCommitTimeline().filterCompletedInstants(); HoodieCommitMetadata commitMetadata = HoodieCommitMetadata .fromBytes(commitTimeline.getInstantDetails(commitInstant).get()); String basePath = table.getMetaClient().getBasePath(); Collection<String> commitPathNames = commitMetadata.getFileIdAndFullPaths(basePath).values(); // Read from commit file String filename = HoodieTestUtils.getCommitFilePath(basePath, commitTime); FileInputStream inputStream = new FileInputStream(filename); String everything = IOUtils.toString(inputStream); HoodieCommitMetadata metadata = HoodieCommitMetadata.fromJsonString(everything.toString()); HashMap<String, String> paths = metadata.getFileIdAndFullPaths(basePath); inputStream.close(); // Compare values in both to make sure they are equal. for (String pathName : paths.values()) { assertTrue(commitPathNames.contains(pathName)); } }
From source file:gov.utah.dts.sdc.dao.BaseDAO.java
/** * Redmine 4318// w w w. j a va 2s .co m * * @param logEntry * @param formMap * @throws Exception */ @SuppressWarnings("unused") private void almLog_old(String logEntry, HashMap formMap) throws Exception { StringBuffer userComment = new StringBuffer(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); Collection<String> col = formMap.values(); Iterator it = col.iterator(); while (it.hasNext()) { Object val = it.next(); if (val == null) { userComment.append("null | "); } else if (val instanceof Integer[]) { Integer[] vals = (Integer[]) val; for (int i = 0; i < vals.length; i++) { userComment.append(vals[i].intValue() + ", "); } userComment.append(" | "); } else if (val instanceof Date) { userComment.append(sdf.format((Date) val) + " | "); } else { userComment.append(val.toString() + " | "); } } LoggingClient logClient = new LoggingClientImpl(); String logTypeCode = ""; // dummy, it doesn't mean anything in this app. if ("classroomStudentRemove".equals(logEntry)) { // See searchAuditLogs.jsp for use. logTypeCode = "RD"; } else { logTypeCode = "RE"; } WriteLogResponse writeLogResponse = logClient.writeLog(userId, logTypeCode, logEntry, userComment.toString()); log.debug("Write log response: " + writeLogResponse.getResponseMessage().getResponseDescription()); ; }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.action.MafFileProcessor.java
private void insertBiospecimenToFileRelationships(final HashMap<String, BCRID> barcodesOrUuids, final QcContext context, final File mafFile) throws UUIDException { final List<Integer> biospecimenIds; final List<Long> shippedBiospecimenIds; // if center is converted to UUID use the uuids to look up the biospecimen ID if (context.isCenterConvertedToUUID()) { final List<String> uuids = new ArrayList<String>(); for (final BCRID bcrId : barcodesOrUuids.values()) { uuids.add(bcrId.getUUID());// w w w .ja va 2 s.c om } shippedBiospecimenIds = bcrDataService.getShippedBiospecimenIds(uuids); biospecimenIds = new ArrayList<Integer>(); for (final Long shippedBiospecimenId : shippedBiospecimenIds) { biospecimenIds.add(shippedBiospecimenId.intValue()); } } else { biospecimenIds = BiospecimenHelper.getBiospecimenIds(new ArrayList<BCRID>(barcodesOrUuids.values()), bcrDataService); shippedBiospecimenIds = new ArrayList<Long>(); for (final Integer id : biospecimenIds) { shippedBiospecimenIds.add(id.longValue()); } } // add biospecimen to file relationship into common and disease database BiospecimenHelper.insertBiospecimenFileRelationship(biospecimenIds, context.getArchive().getFilenameToIdToMap().get(mafFile.getName()), bcrDataService, context.getArchive().getTheTumor()); // now shipped biospecimen to file... bcrDataService.addShippedBiospecimensFileRelationship(shippedBiospecimenIds, context.getArchive().getFilenameToIdToMap().get(mafFile.getName())); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerMacroTests.java
public void testAllMacros() throws Exception { DummyMacroRequestContext rc = new DummyMacroRequestContext(request); Map msgMap = new HashMap(); msgMap.put("hello", "Howdy"); msgMap.put("world", "Mundo"); rc.setMessageMap(msgMap);//w ww. j av a 2 s. c om Map themeMsgMap = new HashMap(); themeMsgMap.put("hello", "Howdy!"); themeMsgMap.put("world", "Mundo!"); rc.setThemeMessageMap(themeMsgMap); rc.setContextPath("/springtest"); TestBean tb = new TestBean("Darren", 99); tb.setSpouse(new TestBean("Fred")); tb.setJedi(true); request.setAttribute("command", tb); HashMap names = new HashMap(); names.put("Darren", "Darren Davison"); names.put("John", "John Doe"); names.put("Fred", "Fred Bloggs"); names.put("Rob&Harrop", "Rob Harrop"); Configuration config = fc.getConfiguration(); Map model = new HashMap(); model.put("command", tb); model.put("springMacroRequestContext", rc); model.put("msgArgs", new Object[] { "World" }); model.put("nameOptionMap", names); model.put("options", names.values()); FreeMarkerView view = new FreeMarkerView(); view.setBeanName("myView"); view.setUrl("test.ftl"); view.setExposeSpringMacroHelpers(false); view.setConfiguration(config); view.setServletContext(new MockServletContext()); view.render(model, request, response); // tokenize output and ignore whitespace String output = response.getContentAsString(); System.out.println(output); String[] tokens = StringUtils.tokenizeToStringArray(output, "\t\n"); for (int i = 0; i < tokens.length; i++) { if (tokens[i].equals("NAME")) assertEquals("Darren", tokens[i + 1]); if (tokens[i].equals("AGE")) assertEquals("99", tokens[i + 1]); if (tokens[i].equals("MESSAGE")) assertEquals("Howdy Mundo", tokens[i + 1]); if (tokens[i].equals("DEFAULTMESSAGE")) assertEquals("hi planet", tokens[i + 1]); if (tokens[i].equals("MESSAGEARGS")) assertEquals("Howdy[World]", tokens[i + 1]); if (tokens[i].equals("MESSAGEARGSWITHDEFAULTMESSAGE")) assertEquals("Hi", tokens[i + 1]); if (tokens[i].equals("THEME")) assertEquals("Howdy! Mundo!", tokens[i + 1]); if (tokens[i].equals("DEFAULTTHEME")) assertEquals("hi! planet!", tokens[i + 1]); if (tokens[i].equals("THEMEARGS")) assertEquals("Howdy![World]", tokens[i + 1]); if (tokens[i].equals("THEMEARGSWITHDEFAULTMESSAGE")) assertEquals("Hi!", tokens[i + 1]); if (tokens[i].equals("URL")) assertEquals("/springtest/aftercontext.html", tokens[i + 1]); if (tokens[i].equals("FORM1")) assertEquals("<input type=\"text\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]); if (tokens[i].equals("FORM2")) assertEquals( "<input type=\"text\" id=\"name\" name=\"name\" value=\"Darren\" class=\"myCssClass\" >", tokens[i + 1]); if (tokens[i].equals("FORM3")) assertEquals("<textarea id=\"name\" name=\"name\" >Darren</textarea>", tokens[i + 1]); if (tokens[i].equals("FORM4")) assertEquals("<textarea id=\"name\" name=\"name\" rows=10 cols=30>Darren</textarea>", tokens[i + 1]); //TODO verify remaining output (fix whitespace) if (tokens[i].equals("FORM9")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]); if (tokens[i].equals("FORM10")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]); if (tokens[i].equals("FORM11")) assertEquals("<input type=\"text\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]); if (tokens[i].equals("FORM12")) assertEquals("<input type=\"hidden\" id=\"name\" name=\"name\" value=\"Darren\" >", tokens[i + 1]); if (tokens[i].equals("FORM13")) assertEquals("<input type=\"password\" id=\"name\" name=\"name\" value=\"\" >", tokens[i + 1]); if (tokens[i].equals("FORM15")) assertEquals("<input type=\"hidden\" name=\"_name\" value=\"on\"/>", tokens[i + 1]); if (tokens[i].equals("FORM15")) assertEquals("<input type=\"checkbox\" id=\"name\" name=\"name\" />", tokens[i + 2]); if (tokens[i].equals("FORM16")) assertEquals("<input type=\"hidden\" name=\"_jedi\" value=\"on\"/>", tokens[i + 1]); if (tokens[i].equals("FORM16")) assertEquals("<input type=\"checkbox\" id=\"jedi\" name=\"jedi\" checked=\"checked\" />", tokens[i + 2]); } }
From source file:com.redhat.victims.database.VictimsSqlDB.java
public HashSet<String> getVulnerabilities(HashMap<String, String> props) throws VictimsException { try {/*from ww w. j a v a 2 s.c o m*/ HashSet<String> cves = new HashSet<String>(); int requiredMinCount = props.size(); ResultSet rs; PreparedStatement ps; Connection connection = getConnection(); try { ps = setObjects(connection, Query.PROPERTY_MATCH, props.keySet().toArray(), props.values().toArray()); rs = ps.executeQuery(); while (rs.next()) { Integer id = rs.getInt("record"); Integer count = rs.getInt("count"); if (count == requiredMinCount) { cves.addAll(getVulnerabilities(id)); } } rs.close(); ps.close(); } finally { connection.close(); } return cves; } catch (SQLException e) { throw new VictimsException("Failed to search on properties", e); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.conll.Conll2006Writer.java
private void convert(JCas aJCas, PrintWriter aOut) { for (Sentence sentence : select(aJCas, Sentence.class)) { HashMap<Token, Row> ctokens = new LinkedHashMap<Token, Row>(); // Tokens Iterator<Token> tokens = selectCovered(Token.class, sentence).iterator(); for (int i = 1; tokens.hasNext(); i++) { Row row = new Row(); row.id = i;//from w ww. j a v a 2 s . c o m row.token = tokens.next(); ctokens.put(row.token, row); } // Dependencies for (Dependency rel : selectCovered(Dependency.class, sentence)) { ctokens.get(rel.getDependent()).deprel = rel; } // Write sentence in CONLL 2006 format for (Row row : ctokens.values()) { String lemma = (row.token.getLemma() != null) ? row.token.getLemma().getValue() : UNUSED; String pos = UNUSED; String cpos = UNUSED; if (row.token.getPos() != null) { POS posAnno = row.token.getPos(); pos = posAnno.getPosValue(); if (!(posAnno instanceof POS)) { cpos = posAnno.getClass().getSimpleName(); } else { cpos = pos; } } int head = 0; String deprel = UNUSED; if (row.deprel != null) { deprel = row.deprel.getDependencyType(); head = ctokens.get(row.deprel.getGovernor()).id; if (head == row.id) { // ROOT dependencies may be modeled as a loop, ignore these. head = 0; } } aOut.printf("%d\t%s\t%s\t%s\t%s\t_\t%d\t%s\t_\t_\n", row.id, row.token.getCoveredText(), lemma, cpos, pos, head, deprel); } aOut.println(); } }