List of usage examples for java.util Map size
int size();
From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java
public static String addQueryParamsToUri(String uri, Map<String, String> queryParams) { if (queryParams.size() == 0) { return uri; }//ww w . j a v a2s .c o m StringBuilder query = new StringBuilder(); for (Map.Entry<String, String> params : queryParams.entrySet()) { try { if (query.length() > 0) { query.append("&"); } query.append(params.getKey()).append("=").append(URLEncoder.encode(params.getValue(), "utf-8")); } catch (Exception e) { throw new RuntimeException( "Failed to encode query params: " + params.getKey() + "=" + params.getValue()); } } return uri + (uri.indexOf("?") == -1 ? "?" : "&") + query; }
From source file:mesquite.tol.lib.BaseHttpRequestMaker.java
public static byte[] doMultipartPost(String url, Map stringParams, Map fileParams) { PostMethod filePost = new PostMethod(url); Part[] parts = new Part[stringParams.size() + fileParams.size()]; int i = 0;// w w w .java 2s .c om if (stringParams != null) { for (Iterator iter = stringParams.keySet().iterator(); iter.hasNext();) { String nextKey = (String) iter.next(); String nextValue = stringParams.get(nextKey).toString(); parts[i++] = new StringPart(nextKey, nextValue); } } if (fileParams != null) { for (Iterator iter = fileParams.keySet().iterator(); iter.hasNext();) { String nextKey = (String) iter.next(); File nextValue = (File) fileParams.get(nextKey); try { parts[i++] = new FilePart(nextKey, nextValue); } catch (FileNotFoundException e) { e.printStackTrace(); } } } /*System.out.println("going to post multipart to url: " + url + " with parts: " + parts); for (int j = 0; j < parts.length; j++) { Part part = parts[j]; System.out.println("current part is: " + part); }*/ filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); //System.out.println("just set request entity"); return executePost(filePost); }
From source file:eu.squadd.reflections.mapper.ServiceModelTranslator.java
private static void assignMapValue(Method getter, Object sourceValue, Method setter, Object destInstance) { System.out.println("*** Map found, resolving its payload types..."); if (sourceValue == null || ((Map) sourceValue).isEmpty()) return;//from ww w. ja v a 2 s .c o m Map<Integer, Class> sourceMapTypes = detectSourceMapPayload(getter); if (sourceMapTypes.isEmpty() || sourceMapTypes.size() != 2) { System.err.println("Failed to determine source Map payload types, operation aborted !!!"); return; } Class firstSourceArgClass = sourceMapTypes.get(0); Class secondSourceArgClass = sourceMapTypes.get(1); Map<Integer, Class> destMapTypes = detectDestMapPayload(setter); if (destMapTypes.isEmpty() || destMapTypes.size() != 2) { System.err.println("Failed to determine destination Map payload types, operation aborted !!!"); return; } Class firstDestArgClass = destMapTypes.get(0); Class secordDestArgsClass = destMapTypes.get(1); if (!firstSourceArgClass.equals(firstDestArgClass)) { System.err.println("Map key types are different, can't translate values !!!"); return; } System.out.println("*** Map types sorted, populating values..."); Map sourceItems = (Map) sourceValue; Map destItems = createMapOfTypes(firstDestArgClass, secordDestArgsClass); for (Object key : sourceItems.entrySet()) { Entry entry = (Entry) destItems.get(key); Object destValue = transposeModel(secondSourceArgClass, secordDestArgsClass, entry.getValue()); destItems.put(entry.getKey(), destValue); } try { setter.invoke(destInstance, destItems); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(ServiceModelTranslator.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("*** done"); }
From source file:eu.openanalytics.rsb.Util.java
/** * Rename well known meta properties to their canonical names. * /*from w ww .j av a 2 s . com*/ * @param meta * @return */ public static Map<String, Serializable> normalizeJobMeta(final Map<String, Serializable> meta) { final Map<String, Serializable> normalized = new HashMap<String, Serializable>(meta.size()); for (final Entry<String, Serializable> entry : meta.entrySet()) { final String normalizedName = Constants.WELL_KNOWN_CONFIGURATION_KEYS.get(entry.getKey().toLowerCase()); if (normalizedName != null) { normalized.put(normalizedName, entry.getValue()); } else { normalized.put(entry.getKey(), entry.getValue()); } } return normalized; }
From source file:edu.coeia.charts.PieChartPanel.java
private static PieDataset createSampleDataset(final Map<String, Double> map, int factor) { final DefaultPieDataset result = new DefaultPieDataset(); Set set = map.entrySet();/*from w w w. j a v a2 s .c o m*/ Iterator itr = set.iterator(); while (itr.hasNext()) { Map.Entry me = (Map.Entry) itr.next(); String str = me.getValue().toString(); double counts = Double.valueOf(str).doubleValue(); if (counts < factor) continue; double per = (counts / map.size()) * 100; result.setValue((String) me.getKey(), per); } return result; }
From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java
private static String getRequestUrl(HttpServletRequest request) { String base = ControllerUtil.getFullServletUrl(request); String queryStringParameters = request.getQueryString(); Map postParameters = request.getParameterMap(); StringBuilder out = new StringBuilder(); out.append(base);/*from w ww . j ava 2 s. c om*/ String queryString; if (queryStringParameters != null) { out.append("?").append(queryStringParameters); queryString = out.toString(); } else if (postParameters.size() > 0) { out.append("?"); for (Object entryKey : postParameters.entrySet()) { Map.Entry entry = (Map.Entry) entryKey; String key = entry.getKey().toString(); String[] values = (String[]) entry.getValue(); for (String value : values) { out.append(key).append("=").append(value).append("&"); } } queryString = out.toString().substring(0, out.toString().length() - 1); } else { queryString = out.toString(); } return queryString; }
From source file:at.orz.arangodb.http.HttpManager.java
private static List<NameValuePair> toList(Map<String, Object> parameters) { ArrayList<NameValuePair> paramList = new ArrayList<NameValuePair>(parameters.size()); for (Entry<String, Object> param : parameters.entrySet()) { if (param.getValue() != null) { paramList.add(new BasicNameValuePair(param.getKey(), param.getValue().toString())); }// w w w. j a v a 2s .c o m } return paramList; }
From source file:com.taobao.android.builder.tools.bundleinfo.BundleGraphExecutor.java
public static void execute(List<BundleInfo> bundleInfos, int parableCount, BundleItemRunner bundleItemRunner) throws IOException, InterruptedException { Map<String, BundleInfo> bundleInfoMap = new HashMap<>(); bundleInfos.forEach(new Consumer<BundleInfo>() { @Override/*from w ww . ja v a 2 s . co m*/ public void accept(BundleInfo bundleInfo) { bundleInfoMap.put(bundleInfo.getPkgName(), bundleInfo); } }); Map<String, BundleItem> bundleItemMap = getBundleItemMap(bundleInfoMap); handleCircleDependency(bundleItemMap); int size = bundleItemMap.size(); ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("bundleGraph", logger, parableCount); int index = 0; int j = 0; while (index <= size) { List<String> keys = new ArrayList<>(); List<Runnable> runnables = new ArrayList<>(); for (String key : bundleItemMap.keySet()) { //System.out.println("test" + key); BundleItem bundleItem = bundleItemMap.get(key); if (bundleItem.canResolve()) { index++; //bundleItem.resolve(); keys.add(key); final String name = index + bundleItem.bundleInfo.getPkgName(); runnables.add(new Runnable() { @Override public void run() { logger.warn("start to do bundle proguard for " + name); bundleItemRunner.execute(bundleItem); logger.warn("end do bundle proguard for " + name); } }); } } Profiler.enter("execute stage " + j++ + " runnables " + runnables.size()); executorServicesHelper.execute(runnables); Profiler.release(); if (keys.isEmpty()) { break; } for (String key : keys) { bundleItemMap.get(key).resolve(); bundleItemMap.remove(key); } } if (index != size) { throw new GradleException("bundleGraph is some thing wrong"); } }
From source file:io.apiman.gateway.engine.vertx.polling.URILoadingRegistry.java
public static void reloadData(IAsyncHandler<Void> doneHandler) { synchronized (URILoadingRegistry.class) { if (instance == null) { doneHandler.handle((Void) null); return; }/*from w w w .java 2 s.c o m*/ Map<URILoadingRegistry, IAsyncResultHandler<Void>> regs = instance.handlers; Vertx vertx = instance.vertx; URI uri = instance.uri; Map<String, String> config = instance.config; AtomicInteger ctr = new AtomicInteger(regs.size()); OneShotURILoader newLoader = new OneShotURILoader(vertx, uri, config); regs.entrySet().stream().forEach(pair -> { // Clear the registrys' internal maps to prepare for reload. // NB: If we add production hot reloading, we'll need to work around this (e.g. clone?). pair.getKey().getMap().clear(); // Re-subscribe the registry. newLoader.subscribe(pair.getKey(), result -> { checkAndFlip(ctr.decrementAndGet(), newLoader, doneHandler); }); }); checkAndFlip(ctr.get(), newLoader, doneHandler); } }
From source file:com.hangum.tadpole.engine.sql.util.export.SQLExporter.java
public static String makeFileBatchInsertStatment(String tableName, QueryExecuteResultDTO rsDAO, int intLimitCount, int commit) throws Exception { String strTmpDir = PublicTadpoleDefine.TEMP_DIR + tableName + System.currentTimeMillis() + PublicTadpoleDefine.DIR_SEPARATOR; String strFile = tableName + ".sql"; String strFullPath = strTmpDir + strFile; boolean isFirst = true; final String INSERT_INTO_STMT = "INSERT INTO " + tableName + " (%s) VALUES (%S)"; final String NEXT_INSERT_INTO_STMT = ", (%S)"; // ?./*from w ww.j a va 2 s. c om*/ String strColumns = ""; Map<Integer, String> mapTable = rsDAO.getColumnLabelName(); for (int i = 1; i < mapTable.size(); i++) { if (i != (mapTable.size() - 1)) strColumns += mapTable.get(i) + ","; else strColumns += mapTable.get(i); } // ?? . StringBuffer sbInsertInto = new StringBuffer(); int DATA_COUNT = 1000; List<Map<Integer, Object>> dataList = rsDAO.getDataList().getData(); Map<Integer, Integer> mapColumnType = rsDAO.getColumnType(); String strResult = new String(); for (int i = 0; i < dataList.size(); i++) { Map<Integer, Object> mapColumns = dataList.get(i); strResult = ""; for (int j = 1; j < mapColumnType.size(); j++) { Object strValue = mapColumns.get(j); strValue = strValue == null ? "" : strValue; if (!RDBTypeToJavaTypeUtils.isNumberType(mapColumnType.get(j))) { strValue = StringEscapeUtils.escapeSql(strValue.toString()); strValue = StringHelper.escapeSQL(strValue.toString()); strValue = SQLUtil.makeQuote(strValue.toString()); } if (j != (mapTable.size() - 1)) strResult += strValue + ","; else strResult += strValue; } if (isFirst) { isFirst = false; sbInsertInto.append(String.format(INSERT_INTO_STMT, strColumns, strResult)); } else { sbInsertInto.append(String.format(NEXT_INSERT_INTO_STMT, strResult)); } if (dataList.size() > 1 && i > 1 && (i % DATA_COUNT) == 0) { isFirst = true; sbInsertInto.append(PublicTadpoleDefine.SQL_DELIMITER); sbInsertInto.append(PublicTadpoleDefine.LINE_SEPARATOR); if (commit > 0) { sbInsertInto.append( "COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); sbInsertInto.setLength(0); } if (intLimitCount == i) { return sbInsertInto.toString(); } } if (sbInsertInto.length() > 0) { sbInsertInto.append(PublicTadpoleDefine.SQL_DELIMITER); sbInsertInto.append(PublicTadpoleDefine.LINE_SEPARATOR); if (commit > 0) { sbInsertInto .append("COMMIT" + PublicTadpoleDefine.SQL_DELIMITER + PublicTadpoleDefine.LINE_SEPARATOR); } FileUtils.writeStringToFile(new File(strFullPath), sbInsertInto.toString(), true); } return strFullPath; }