List of usage examples for java.util Map size
int size();
From source file:jp.co.opentone.bsol.framework.web.view.util.PageNavigationUtil.java
/** * ?viewId?url????./* w w w . j a va2s .c o m*/ * @param contextPath ?ContextPath * @param viewId redirect?viewId * @param paramMap map * @param enc Character Encoding * @return redirect?url */ public static String createRedirectUrlFromViewId(String contextPath, String viewId, Map<String, String> paramMap, String enc) { StringBuffer url = new StringBuffer(contextPath); url.append(viewId.replace(".xhtml", ".jsf")); try { if (null != paramMap && 0 < paramMap.size()) { for (String key : paramMap.keySet()) { if (-1 == url.indexOf("?")) { url.append('?'); } else { url.append('&'); } String value = URLEncoder.encode(paramMap.get(key), enc); url.append(String.format("%s=%s", key, value)); } } } catch (UnsupportedEncodingException e) { // ???????? throw new AbortProcessingException(e); } return url.toString(); }
From source file:com.glaf.jbpm.util.ExpressionUtils.java
public static Map<String, Object> getParameters(ExecutionContext ctx, Element elements) { Map<String, Object> values = new java.util.HashMap<String, Object>(); ContextInstance contextInstance = ctx.getContextInstance(); Object rowId = contextInstance.getVariable(Constant.PROCESS_ROWID); if (elements != null) { Map<String, Object> dataMap = (Map<String, Object>) CustomFieldInstantiator.getValue(Map.class, elements);/*ww w. j a va 2s . c o m*/ java.util.Date now = new java.util.Date(); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } if (value instanceof String && StringUtils.isNotEmpty(value.toString())) { String tmp = (String) value; if (tmp.equals("#{processInstanceId}")) { value = contextInstance.getProcessInstance().getId(); } else if (tmp.equals("#{taskInstanceId}")) { TaskInstance taskInstance = ctx.getTaskInstance(); if (taskInstance != null) { value = taskInstance.getId(); } } else if (tmp.equals("#{taskName}")) { Task task = ctx.getTask(); if (task != null) { value = task.getName(); } else { if (ctx.getTaskInstance() != null) { value = ctx.getTaskInstance().getName(); } } } else if (tmp.equals("now()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("date()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("time()")) { value = new java.sql.Time(now.getTime()); } else if (tmp.equals("timestamp()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("dateTime()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("currentTimeMillis()")) { value = System.currentTimeMillis(); } else if (tmp.equals("#{rowId}")) { value = rowId; } else if (tmp.equals("#{uuid}")) { value = UUID32.getUUID(); } else if (tmp.equals("#{actorId}")) { value = ctx.getJbpmContext().getActorId(); } else if (tmp.startsWith("#P{") && tmp.endsWith("}")) { tmp = StringTools.replaceIgnoreCase(tmp, "#P{", ""); tmp = StringTools.replaceIgnoreCase(tmp, "}", ""); value = contextInstance.getVariable(tmp); } else if (tmp.startsWith("#{") && tmp.endsWith("}")) { Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> vars = contextInstance.getVariables(); if (vars != null && vars.size() > 0) { Iterator<String> it = vars.keySet().iterator(); while (it.hasNext()) { String variableName = it.next(); if (params.get(variableName) == null) { Object object = contextInstance.getVariable(variableName); params.put(variableName, object); } } } value = DefaultExpressionEvaluator.evaluate(tmp, params); } } values.put(key.toString(), value); } } return values; }
From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.application.SQLToRealGridConvert.java
/** * sql to string// w w w.j av a2s . c o m * * @param name * @param sql * @return */ public static String sqlToString(UserDBDAO userDB, String name, String sql) { String retHtml = ""; try { String STR_TEMPLATE = IOUtils.toString(SQLToRealGridConvert.class.getResource("realgrid.js.template")); QueryExecuteResultDTO queryResult = QueryUtils.executeQuery(userDB, sql, 0, 4); Map<Integer, String> columnLabel = queryResult.getColumnLabelName(); Map<Integer, Integer> columnType = queryResult.getColumnType(); String strField = ""; StringBuffer sbField = new StringBuffer(); for (int i = 0; i < columnLabel.size(); i++) { String strColumnLabel = columnLabel.get(i); boolean isNumber = RDBTypeToJavaTypeUtils.isNumberType(columnType.get(i)); sbField.append(String.format(GROUP_TEMPLATE, strColumnLabel, isNumber ? "number" : "text")); } strField = StringUtils.removeEnd(sbField.toString(), ","); String strColumn = ""; StringBuffer sbColumn = new StringBuffer(); for (int i = 0; i < columnLabel.size(); i++) { String strColumnLabel = columnLabel.get(i); sbColumn.append(String.format(GROUP_DATA_TEMPLATE, strColumnLabel, strColumnLabel)); } strColumn = StringUtils.removeEnd(sbColumn.toString(), ","); retHtml = StringUtils.replaceOnce(STR_TEMPLATE, "_TDB_TEMPLATE_FIELD_", strField); retHtml = StringUtils.replaceOnce(retHtml, "_TDB_TEMPLATE_COLUMN_", strColumn); } catch (Exception e) { logger.error("SQL template exception", e); } return retHtml; }
From source file:com.glaf.jbpm.util.ExpressionUtils.java
public static List<Object> getValues(ExecutionContext ctx, Element elements) { List<Object> values = new java.util.ArrayList<Object>(); ContextInstance contextInstance = ctx.getContextInstance(); Object rowId = contextInstance.getVariable(Constant.PROCESS_ROWID); if (elements != null) { Map<String, Object> dataMap = (Map<String, Object>) CustomFieldInstantiator.getValue(Map.class, elements);//from w w w.j av a 2 s . c om java.util.Date now = new java.util.Date(); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } if (value instanceof String && StringUtils.isNotEmpty(value.toString())) { String tmp = (String) value; if ("#{processInstanceId}".equals(tmp)) { value = contextInstance.getProcessInstance().getId(); } else if ("#{taskInstanceId}".equals(tmp)) { TaskInstance taskInstance = ctx.getTaskInstance(); if (taskInstance != null) { value = taskInstance.getId(); } } else if ("#{taskName}".equals(tmp)) { Task task = ctx.getTask(); if (task != null) { value = task.getName(); } else { if (ctx.getTaskInstance() != null) { value = ctx.getTaskInstance().getName(); } } } else if (tmp.equals("now()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("date()")) { value = new java.sql.Date(now.getTime()); } else if (tmp.equals("time()")) { value = new java.sql.Time(now.getTime()); } else if (tmp.equals("timestamp()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("dateTime()")) { value = new java.sql.Timestamp(now.getTime()); } else if (tmp.equals("currentTimeMillis()")) { value = System.currentTimeMillis(); } else if (tmp.equals("#{rowId}")) { value = rowId; } else if (tmp.equals("#{uuid}")) { value = UUID32.getUUID(); } else if (tmp.equals("#{actorId}")) { value = ctx.getJbpmContext().getActorId(); } else if (tmp.equals("#{status}")) { value = contextInstance.getVariable("status"); } else if (tmp.startsWith("#P{") && tmp.endsWith("}")) { tmp = StringTools.replaceIgnoreCase(tmp, "#P{", ""); tmp = StringTools.replaceIgnoreCase(tmp, "}", ""); value = contextInstance.getVariable(tmp); } else if (tmp.startsWith("#{") && tmp.endsWith("}")) { Map<String, Object> params = new java.util.HashMap<String, Object>(); Map<String, Object> vars = contextInstance.getVariables(); if (vars != null && vars.size() > 0) { Iterator<String> it = vars.keySet().iterator(); while (it.hasNext()) { String variableName = it.next(); if (params.get(variableName) == null) { Object object = contextInstance.getVariable(variableName); params.put(variableName, object); } } } value = DefaultExpressionEvaluator.evaluate(tmp, params); } } values.add(value); } } return values; }
From source file:com.hangum.tadpole.engine.sql.util.export.XMLExporter.java
/** * make content// w w w .j a v a 2 s.c o m * * @param tableName * @param rsDAO * @return */ public static String makeContent(String tableName, QueryExecuteResultDTO rsDAO, int intLimitCnt) throws Exception { final StringWriter stWriter = new StringWriter(); final List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); final Document doc = builder.newDocument(); final Element results = doc.createElement(tableName); doc.appendChild(results); Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); Element row = doc.createElement("Row"); results.appendChild(row); for (int j = 1; j < mapColumns.size(); j++) { String columnName = mapLabelName.get(j); String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); Element node = doc.createElement(columnName); node.appendChild(doc.createTextNode(strValue)); row.appendChild(node); } if (i == intLimitCnt) break; } DOMSource domSource = new DOMSource(doc); TransformerFactory tf = TransformerFactory.newInstance(); tf.setAttribute("indent-number", 4); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//"ISO-8859-1"); StreamResult sr = new StreamResult(stWriter); transformer.transform(domSource, sr); return stWriter.toString(); }
From source file:com.amazonaws.auth.profile.ProfilesConfigFileWriterTest.java
/** * Loads the given credentials file and checks that it contains the same * set of profiles as expected.//from w w w.j a v a 2s . com */ private static void checkCredentialsFile(File file, Profile... expectedProfiles) { ProfilesConfigFile parsedFile = new ProfilesConfigFile(file); Map<String, Profile> loadedProfiles = parsedFile.getAllProfiles(); assertTrue(expectedProfiles.length == loadedProfiles.size()); for (Profile expectedProfile : expectedProfiles) { Profile loadedProfile = loadedProfiles.get(expectedProfile.getProfileName()); assertEqualProfiles(expectedProfile, loadedProfile); } }
From source file:com.hangum.tadpole.engine.sql.util.export.XMLExporter.java
/** * make content file//w w w. j av a2s . c o m * * @param tableName * @param rsDAO * @return * @throws Exception */ public static String makeContentFile(String tableName, QueryExecuteResultDTO rsDAO) throws Exception { String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".xml"; String strFullPath = strTmpDir + strFile; final StringWriter stWriter = new StringWriter(); final List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); final Document doc = builder.newDocument(); final Element results = doc.createElement(tableName); doc.appendChild(results); Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); Element row = doc.createElement("Row"); results.appendChild(row); for (int j = 1; j < mapColumns.size(); j++) { String columnName = mapLabelName.get(j); String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); Element node = doc.createElement(columnName); node.appendChild(doc.createTextNode(strValue)); row.appendChild(node); } } DOMSource domSource = new DOMSource(doc); TransformerFactory tf = TransformerFactory.newInstance(); tf.setAttribute("indent-number", 4); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//"ISO-8859-1"); StreamResult sr = new StreamResult(stWriter); transformer.transform(domSource, sr); FileUtils.writeStringToFile(new File(strFullPath), stWriter.toString(), true); return strFullPath; }
From source file:Main.java
static String getColumnSql(Map<String, String> columns) { StringBuilder sb = new StringBuilder(); int i = 0;//w w w. ja v a 2s. co m for (Map.Entry<String, String> entry : columns.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); sb.append(key + " " + value); i++; if (i != columns.size()) { sb.append(", "); } } return sb.toString(); }
From source file:com.hangum.tadpole.engine.sql.util.export.HTMLExporter.java
/** * make content file/* ww w .j a v a 2 s .co m*/ * * @param tableName * @param rsDAO * @return * @throws Exception */ public static String makeContentFile(String tableName, QueryExecuteResultDTO rsDAO) throws Exception { // full text String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".html"; String strFullPath = strTmpDir + strFile; FileUtils.writeStringToFile(new File(strFullPath), HTMLDefine.sbHtml, true); FileUtils.writeStringToFile(new File(strFullPath), "<table class='tg'>", true); // make content List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); // column . Map<Integer, String> mapLabelName = rsDAO.getColumnLabelName(); StringBuffer sbHead = new StringBuffer(); sbHead.append(String.format(strHead, "#")); for (int i = 1; i < mapLabelName.size(); i++) { sbHead.append(String.format(strHead, mapLabelName.get(i))); } String strLastColumnName = String.format(strGroup, sbHead.toString()); // header FileUtils.writeStringToFile(new File(strFullPath), strLastColumnName, true); // body start StringBuffer sbBody = new StringBuffer(""); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); StringBuffer sbTmp = new StringBuffer(); sbTmp.append(String.format(strHead, "" + (i + 1))); //$NON-NLS-1$ for (int j = 1; j < mapColumns.size(); j++) { String strValue = mapColumns.get(j) == null ? "" : "" + mapColumns.get(j); sbTmp.append(String.format(strContent, StringEscapeUtils.unescapeHtml(strValue))); //$NON-NLS-1$ } sbBody.append(String.format(strGroup, sbTmp.toString())); if ((i % DATA_COUNT) == 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); sbBody.delete(0, sbBody.length()); } } if (sbBody.length() > 0) { FileUtils.writeStringToFile(new File(strFullPath), sbBody.toString(), true); } FileUtils.writeStringToFile(new File(strFullPath), "</table>", true); return strFullPath; }
From source file:edu.uci.ics.jung.algorithms.matrix.GraphMatrixOperations.java
/** * Converts a Map of (Vertex, Double) pairs to a DoubleMatrix1D. * //from ww w. ja v a2s . co m * <p>Note: the vertices will appear in the output array in the order given * by {@code map}'s iterator. If you want a particular ordering, use a {@code Map} * implementation that provides such an ordering ({@code SortedMap, LinkedHashMap}, etc.). */ public static <V> DoubleMatrix1D mapTo1DMatrix(Map<V, Number> map) { int numVertices = map.size(); DoubleMatrix1D vector = new DenseDoubleMatrix1D(numVertices); int i = 0; for (V v : map.keySet()) { vector.set(i, map.get(v).doubleValue()); i++; } return vector; }