List of usage examples for java.util Map values
Collection<V> values();
From source file:org.orbeon.oxf.xforms.submission.XFormsSubmissionUtils.java
/** * Annotate the DOM with information about file name and mediatype provided by uploads if available. * * @param containingDocument current XFormsContainingDocument * @param currentInstance instance containing the nodes to check *///w w w.jav a 2 s.c om public static void annotateBoundRelevantUploadControls(XFormsContainingDocument containingDocument, XFormsInstance currentInstance) { final XFormsControls xformsControls = containingDocument.getControls(); final Map<String, XFormsControl> uploadControls = xformsControls.getCurrentControlTree() .getUploadControls(); if (uploadControls != null) { for (Object o : uploadControls.values()) { final XFormsUploadControl currentControl = (XFormsUploadControl) o; if (currentControl.isRelevant()) { final Item controlBoundItem = currentControl.getBoundItem(); if (controlBoundItem instanceof NodeInfo) { final NodeInfo controlBoundNodeInfo = (NodeInfo) controlBoundItem; if (currentInstance == currentInstance.model().getInstanceForNode(controlBoundNodeInfo)) { // Found one relevant upload control bound to the instance we are submitting // NOTE: special MIP-like annotations were added just before re-rooting/pruning element. Those // will be removed during the next recalculate. final String fileName = currentControl.boundFilename(); if (fileName != null) { InstanceData.setTransientAnnotation(controlBoundNodeInfo, "xxforms-filename", fileName); } final String mediatype = currentControl.boundFileMediatype(); if (mediatype != null) { InstanceData.setTransientAnnotation(controlBoundNodeInfo, "xxforms-mediatype", mediatype); } } } } } } }
From source file:com.github.nmorel.gwtjackson.rebind.property.PropertyParser.java
public static ImmutableMap<String, PropertyAccessors> findPropertyAccessors( final RebindConfiguration configuration, TreeLogger logger, BeanInfo beanInfo) { Map<String, PropertyAccessorsBuilder> fieldsAndMethodsMap = new LinkedHashMap<String, PropertyAccessorsBuilder>(); parse(configuration, logger, beanInfo.getType(), fieldsAndMethodsMap, false); Map<String, PropertyAccessorsBuilder> propertyAccessors = new LinkedHashMap<String, PropertyAccessorsBuilder>(); for (PropertyAccessorsBuilder fieldAccessors : fieldsAndMethodsMap.values()) { propertyAccessors.put(fieldAccessors.computePropertyName(), fieldAccessors); }/*www .ja v a 2 s . c o m*/ if (!beanInfo.getCreatorParameters().isEmpty()) { for (Entry<String, JParameter> entry : beanInfo.getCreatorParameters().entrySet()) { // If there is a constructor parameter referencing this property, we add it to the accessors PropertyAccessorsBuilder fieldAccessors = propertyAccessors.get(entry.getKey()); if (null == fieldAccessors) { fieldAccessors = new PropertyAccessorsBuilder(entry.getKey()); fieldAccessors.setParameter(entry.getValue()); propertyAccessors.put(fieldAccessors.computePropertyName(), fieldAccessors); } else { fieldAccessors.setParameter(entry.getValue()); } } } return ImmutableMap.copyOf(Maps.transformValues(propertyAccessors, new Function<PropertyAccessorsBuilder, PropertyAccessors>() { @Override public PropertyAccessors apply(PropertyAccessorsBuilder propertyAccessorsBuilder) { return null == propertyAccessorsBuilder ? null : propertyAccessorsBuilder.build(); } })); }
From source file:com.firewallid.util.FISQL.java
public static void updateRowInsertIfNotExist(Connection conn, String tableName, Map<String, String> updateConditions, Map<String, String> fields) throws SQLException { /* Query *//* ww w. j a va2 s . c om*/ String query = "SELECT " + Joiner.on(", ").join(updateConditions.keySet()) + " FROM " + tableName + " WHERE " + Joiner.on(" = ? AND ").join(updateConditions.keySet()) + " = ?"; /* Execute */ PreparedStatement pst = conn.prepareStatement(query); int i = 1; for (String value : updateConditions.values()) { pst.setString(i, value); i++; } ResultSet executeQuery = pst.executeQuery(); if (executeQuery.next()) { /* Update */ query = "UPDATE " + tableName + " SET " + Joiner.on(" = ?, ").join(fields.keySet()) + " = ? WHERE " + Joiner.on(" = ? AND ").join(updateConditions.keySet()) + " = ?"; pst = conn.prepareStatement(query); i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } for (String value : updateConditions.values()) { pst.setString(i, value); i++; } pst.executeUpdate(); return; } /* Row is not exists. Insert */ query = "INSERT INTO " + tableName + " (" + Joiner.on(", ").join(fields.keySet()) + ", " + Joiner.on(", ").join(updateConditions.keySet()) + ") VALUES (" + StringUtils.repeat("?, ", fields.size() + updateConditions.size() - 1) + "?)"; pst = conn.prepareStatement(query); i = 1; for (String value : fields.values()) { pst.setString(i, value); i++; } for (String value : updateConditions.values()) { pst.setString(i, value); i++; } pst.execute(); }
From source file:com.github.ipaas.ideploy.agent.util.SVNUtil.java
/** * ?svn//from w w w . j a v a2 s . c o m * @param repository repos * @param path svn(repos) * @param datumRevision * @param expectRevision * @return ? * @throws Exception */ private static Collection<SVNLog> getLog(SVNRepository repository, String path, long datumRevision, long expectRevision) throws Exception { Collection<SVNLogEntry> coll = new LinkedList<SVNLogEntry>(); repository.log(new String[] { path }, coll, datumRevision + 1, expectRevision, true, true); Map<String, SVNLog> logMap = new HashMap<String, SVNLog>(); for (SVNLogEntry e : coll) { Map<String, SVNLogEntryPath> map = e.getChangedPaths(); if (map != null) { for (SVNLogEntryPath p : map.values()) { String sPath = p.getPath(); if (sPath.startsWith(path)) { sPath = sPath.substring(path.length()); } //? String opt = null; if (p.getType() == SVNLogEntryPath.TYPE_DELETED) { opt = "-"; } if (p.getType() == SVNLogEntryPath.TYPE_ADDED || p.getType() == SVNLogEntryPath.TYPE_MODIFIED || p.getType() == SVNLogEntryPath.TYPE_REPLACED) { opt = "+"; } int entryKind = 0; if (p.getKind() == SVNNodeKind.DIR) { entryKind = SVNLog.ENTRY_DIR; } if (p.getKind() == SVNNodeKind.FILE) { entryKind = SVNLog.ENTRY_FILE; } logMap.put(sPath, new SVNLog(e.getRevision(), sPath, opt, entryKind)); } } } return logMap.values(); }
From source file:br.bireme.tb.RIPSA.java
/** * Given a cell, uses its info tho fill the holes of the template String. * @param cell a cell having the data to fill the holes * @return a String with holes replaced/*from ww w.j av a 2s . c o m*/ * @throws IOException */ static String cell2html(final Cell cell) throws IOException { assert cell != null; if (TEMPLATE == null) { throw new IOException("TEMPLATE is null"); } final String qualifRec = cell.getElem().qualifRec.toString(); final Matcher mat = EDITION_PAT.matcher(qualifRec); if (!mat.find()) { throw new IOException("out of pattern url [" + qualifRec + "]"); } final String edition = mat.group(2); final String father = cell.getElem().father.toString(); final Matcher matf = Pattern.compile("idb(\\d{4})").matcher(father); if (!matf.find()) { throw new IOException("out of pattern url [" + father + "]"); } final String year = matf.group(1); String str = TEMPLATE; final StringBuilder builder = new StringBuilder(); boolean first; final String title = cell.getTitle(); final String title2 = (title == null) ? "" : title; str = str.replace("$$title$$", title2); final String subtitle = cell.getSubtitle(); if ((subtitle != null) && (!subtitle.isEmpty())) { str = str.replace("$$subtitle$$", "<h2>" + subtitle + "</h2>"); } else { str = str.replace("$$subtitle$$", ""); } str = str.replace("$$description$$", "Clulas IDB - " + edition + " - " + year + " - " + title2 + " - " + subtitle); final StringBuilder aux = new StringBuilder(title); final Map<String, String> tableOptions = cell.getElem().tableOptions; if ((tableOptions != null) && (!tableOptions.isEmpty())) { for (String opt : tableOptions.values()) { if ((!opt.equals("No ativa")) && (!opt.equals("Todas as categorias"))) { aux.append(", "); aux.append(StringEscapeUtils.unescapeHtml4(opt)); } } } str = str.replace("$$keywords$$", aux.toString()); final List<String> scope = cell.getScope(); builder.setLength(0); first = true; if ((scope != null) && (!scope.isEmpty())) { builder.append("<h3>"); for (String scp : scope) { if (first) { first = false; } else { builder.append("<br/>\n"); } builder.append(scp); } builder.append("</h3>"); str = str.replace("$$scope$$", builder.toString()); } else { str = str.replace("$$scope$$", ""); } final List<String> header = cell.getHeader(); builder.setLength(0); first = true; if ((header != null) && (!header.isEmpty())) { for (String hdr : header) { if (first) { first = false; } else { builder.append("<br/>\n"); } builder.append(hdr); } str = str.replace("$$celheader$$", builder.toString()); } else { str = str.replace("$$celheader$$", ""); } final String row = cell.getRow(); if ((row != null) && (!row.isEmpty())) { str = str.replace("$$celrow$$", row); } else { str = str.replace("$$celrow$$", ""); } final String value = cell.getValue(); if ((value != null) && (!value.isEmpty())) { String celVal; try { celVal = NFMT.format(NFMT.parse(value).floatValue()); } catch (ParseException ex) { celVal = value; } str = str.replace("$$celval$$", celVal); } else { str = str.replace("$$celval$$", ""); } final List<String> sources = cell.getSources(); builder.setLength(0); if ((sources != null) && (!sources.isEmpty())) { builder.append("<div class=\"note\">\n"); builder.append("\t\t\t\t\t\t\t<label>Fonte(s):</label>\n"); for (String source : sources) { builder.append("\t\t\t\t\t\t\t<p>"); builder.append(source); builder.append("</p>\n"); } builder.append("\t\t\t\t\t\t</div>\n"); str = str.replace("$$sources$$", builder.toString()); } else { str = str.replace("$$sources$$", ""); } final List<String> labels = cell.getLabels(); builder.setLength(0); if ((labels != null) && (!labels.isEmpty())) { builder.append("<div class=\"note\">\n"); builder.append("\t\t\t\t\t\t\t<label>Legenda(s):</label>\n"); for (String label : labels) { builder.append("\t\t\t\t\t\t\t<p>"); builder.append(label); builder.append("</p>\n"); } builder.append("\t\t\t\t\t\t</div>\n"); str = str.replace("$$labels$$", builder.toString()); } else { str = str.replace("$$labels$$", ""); } final List<String> notes = cell.getNotes(); builder.setLength(0); if ((notes != null) && (!notes.isEmpty())) { builder.append("<div class=\"note\">\n"); builder.append("\t\t\t\t\t\t\t<label>Nota(s):</label>\n"); for (String note : notes) { builder.append("\t\t\t\t\t\t\t<p>"); builder.append(note); builder.append("</p>\n"); } builder.append("\t\t\t\t\t\t</div>\n"); str = str.replace("$$notes$$", builder.toString()); } else { str = str.replace("$$notes$$", ""); } str = str.replace("$$father$$", cell.getElem().father.toString()); str = str.replace("$$qualifRec$$", cell.getElem().qualifRec.toString()); builder.setLength(0); if ((tableOptions != null) && (!tableOptions.isEmpty())) { str = str.replace("$$tableHeader$$", "<strong>Filtros usados para a" + " gerao da tabela de dados do TabNet</strong>\n<ul>\n"); /*str = str.replace("$$tableHeader$$", "<strong>Tabela de dados do " + "TabNet gerada com os seguintes filtros:</strong><br/><br/>");*/ for (Map.Entry<String, String> option : tableOptions.entrySet()) { builder.append("\t\t\t\t\t\t<li><label>"); builder.append(option.getKey()); builder.append(":</label> "); builder.append(option.getValue()); builder.append("</li>\n"); } str = str.replace("$$tableOptions$$", builder.toString() + "\n</ul>"); } else { str = str.replace("$$tableHeader$$", ""); str = str.replace("$$tableOptions$$", ""); } return str; }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find test case bean./*from w w w . j a va 2s . c o m*/ * * @param appCtx * the app ctx * @return the xml test case * @throws NoSuchBeanDefinitionException * the no such bean definition exception */ public static TestCase findTestCaseBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, TestCase> testcases = appCtx.getBeansOfType(TestCase.class); if (testcases.isEmpty()) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { TestCase retVal = testcases.values().iterator().next(); if (null == retVal) { throw new NoSuchBeanDefinitionException(TestCase.class); } else { return retVal; } } }
From source file:io.lavagna.model.ProjectMetadata.java
private static String hash(SortedMap<Integer, CardLabel> labels, SortedMap<Integer, LabelListValueWithMetadata> labelListValues, Map<ColumnDefinition, BoardColumnDefinition> columnsDefinition) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream daos = new DataOutputStream(baos); try {// www . j a v a 2 s.c om for (CardLabel cl : labels.values()) { hash(daos, cl); } for (LabelListValueWithMetadata l : labelListValues.values()) { hash(daos, l); } for (BoardColumnDefinition b : columnsDefinition.values()) { hash(daos, b); } daos.flush(); return DigestUtils.sha256Hex(new ByteArrayInputStream(baos.toByteArray())); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:edu.umn.cs.spatialHadoop.operations.FileMBR.java
public static Partition fileMBRLocal(Path[] inFiles, final OperationsParams params) throws IOException, InterruptedException { // 1- Split the input path/file to get splits that can be processed independently final SpatialInputFormat3<Rectangle, Shape> inputFormat = new SpatialInputFormat3<Rectangle, Shape>(); Job job = Job.getInstance(params);//from ww w . ja v a2s . c o m SpatialInputFormat3.setInputPaths(job, inFiles); final List<org.apache.hadoop.mapreduce.InputSplit> splits = inputFormat.getSplits(job); int parallelism = params.getInt("parallel", Runtime.getRuntime().availableProcessors()); // 2- Process splits in parallel List<Map<String, Partition>> allMbrs = Parallel.forEach(splits.size(), new RunnableRange<Map<String, Partition>>() { @Override public Map<String, Partition> run(int i1, int i2) { Map<String, Partition> mbrs = new HashMap<String, Partition>(); for (int i = i1; i < i2; i++) { try { org.apache.hadoop.mapreduce.lib.input.FileSplit fsplit = (org.apache.hadoop.mapreduce.lib.input.FileSplit) splits .get(i); final RecordReader<Rectangle, Iterable<Shape>> reader = inputFormat .createRecordReader(fsplit, null); if (reader instanceof SpatialRecordReader3) { ((SpatialRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof RTreeRecordReader3) { ((RTreeRecordReader3) reader).initialize(fsplit, params); } else if (reader instanceof HDFRecordReader) { ((HDFRecordReader) reader).initialize(fsplit, params); } else { throw new RuntimeException("Unknown record reader"); } Partition p = mbrs.get(fsplit.getPath().getName()); if (p == null) { p = new Partition(); p.filename = fsplit.getPath().getName(); p.cellId = p.filename.hashCode(); p.size = 0; p.recordCount = 0; p.set(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); mbrs.put(p.filename, p); } Text temp = new Text2(); while (reader.nextKeyValue()) { Iterable<Shape> shapes = reader.getCurrentValue(); for (Shape s : shapes) { Rectangle mbr = s.getMBR(); if (mbr != null) p.expand(mbr); p.recordCount++; temp.clear(); s.toText(temp); p.size += temp.getLength() + 1; } } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } return mbrs; } }, parallelism); Map<String, Partition> mbrs = allMbrs.remove(allMbrs.size() - 1); for (Map<String, Partition> list : allMbrs) { for (Partition p1 : list.values()) { Partition p2 = mbrs.get(p1.filename); if (p2 != null) { p2.expand(p1); } else { mbrs.put(p1.filename, p1); } } } // Cache the final result, if needed for (Path inFile : inFiles) { FileSystem inFs = inFile.getFileSystem(params); if (!inFs.getFileStatus(inFile).isDir()) continue; Path gindex_path = new Path(inFile, "_master.heap"); // Answer has been already cached (may be by another job) if (inFs.exists(gindex_path)) continue; FileStatus[] files = inFs.listStatus(inFile, SpatialSite.NonHiddenFileFilter); PrintStream wktout = new PrintStream(inFs.create(new Path(inFile, "_heap.wkt"), false)); PrintStream gout = new PrintStream(inFs.create(gindex_path, false)); Text text = new Text2(); for (FileStatus file : files) { text.clear(); Partition p = mbrs.get(file.getPath().getName()); gout.println(p.toText(text).toString()); wktout.println(p.toWKT()); } wktout.close(); gout.close(); } // Return the final answer Partition finalResult = new Partition(); finalResult.size = finalResult.recordCount = 0; finalResult.x1 = finalResult.y1 = Double.MAX_VALUE; finalResult.x2 = finalResult.y2 = -Double.MAX_VALUE; for (Partition p2 : mbrs.values()) finalResult.expand(p2); return finalResult; }
From source file:de.micromata.genome.gwiki.page.GWikiContextUtils.java
/** * Find a wiki artefakt from given element. * * @param el the el//from w w w. j a va 2 s .c o m * @param ctx the ctx * @return null if non found. */ public static GWikiWikiPageArtefakt getWikiFromElement(GWikiElement el, GWikiContext ctx) { if (el == null) { return null; } GWikiArtefakt<?> ma = el.getMainPart(); if (ma instanceof GWikiWikiPageArtefakt) { return (GWikiWikiPageArtefakt) ma; } Map<String, GWikiArtefakt<?>> map = new HashMap<String, GWikiArtefakt<?>>(); el.collectParts(map); ma = map.get("MainPage"); if (ma instanceof GWikiWikiPageArtefakt) { return (GWikiWikiPageArtefakt) ma; } for (GWikiArtefakt<?> a : map.values()) { if (a instanceof GWikiWikiPageArtefakt) { return (GWikiWikiPageArtefakt) a; } } return null; }
From source file:org.bigtester.ate.GlobalUtils.java
/** * Find data source bean./* w ww. ja v a 2s . c o m*/ * * @param appCtx * the app ctx * @return the data source * @throws NoSuchBeanDefinitionException * the no such bean definition exception */ public static DataSource findDataSourceBean(ApplicationContext appCtx) throws NoSuchBeanDefinitionException { Map<String, DataSource> testcases = appCtx.getBeansOfType(DataSource.class); if (testcases.isEmpty()) { throw new NoSuchBeanDefinitionException(DataSource.class); } else { DataSource dataSource = testcases.values().iterator().next(); if (null == dataSource) { throw new NoSuchBeanDefinitionException(DataSource.class); } else { return dataSource; } } }