List of usage examples for java.util Map remove
V remove(Object key);
From source file:Main.java
private static void addEntry(Map<String, Object> value, Entry<String, Object> entry) { String entryKey = entry.getKey(); if (value.get(createMultipleName(entryKey)) != null) { List<Object> orgList = (List) value.get(createMultipleName(entryKey)); orgList.add(entry.getValue());/*from w ww . ja v a2s.co m*/ } else { Object orgValue = value.get(entryKey); if (orgValue == null) { value.put(entryKey, entry.getValue()); } else if (orgValue instanceof List) { ((List) orgValue).add(entry.getValue()); } else { List<Object> newList = new ArrayList<Object>(); newList.add(orgValue); newList.add(entry.getValue()); Map<String, Object> newMap = new HashMap<String, Object>(); newMap.put(createMultipleName(entryKey), newList); value.remove(entryKey); value.put(createMultipleName(entryKey), newList); } } }
From source file:com.zimbra.cs.service.mail.CreateContact.java
static void migrateFromDlist(ParsedContact pc) throws ServiceException { /*// w w w . j a v a 2s . c o m * replace groupMember with dlist data * * Note: if the user had also used new clients to manipulate group members * all ref members will be lost, since all dlist members will be * migrated as INLINE members. * if dlist is an empty string, the group will become an empty group. * * This is the expected behavior. */ Map<String, String> fields = pc.getFields(); String dlist = fields.get(ContactConstants.A_dlist); if (dlist != null) { try { ContactGroup contactGroup = ContactGroup.init(); contactGroup.migrateFromDlist(dlist); fields.put(ContactConstants.A_groupMember, contactGroup.encode()); fields.remove(ContactConstants.A_dlist); } catch (Exception e) { ZimbraLog.contact.info("skipped migrating contact group, dlist=[%s]", dlist, e); } } }
From source file:com.screenslicer.webapp.ScreenSlicerClient.java
@Path("create") @POST/* w w w. ja v a 2 s . c om*/ @Consumes("application/json") @Produces("application/json") public static final Response create(String reqString) { if (reqString != null) { final String reqDecoded = Crypto.decode(reqString, CommonUtil.ip()); if (reqDecoded != null) { final Map<String, Object> args = CommonUtil.gson.fromJson(reqDecoded, CommonUtil.objectType); final Request request = CommonUtil.gson.fromJson(reqDecoded, Request.class); Field[] fields = request.getClass().getFields(); for (Field field : fields) { args.remove(field.getName()); } new Thread(new Runnable() { @Override public void run() { String myInstance = null; AtomicBoolean myDone = null; try { CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-meta" + request.appId), request.jobId + "\n" + request.jobGuid + "\n" + Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTimeInMillis(), false); CommonFile.writeStringToFile(new File("./data/" + request.runGuid + "-context"), Crypto.encode(reqDecoded), false); Map<String, AtomicBoolean> myDoneMap = new HashMap<String, AtomicBoolean>(); synchronized (doneMapLock) { for (int i = 0; i < request.instances.length; i++) { if (!doneMap.containsKey(request.instances[i])) { doneMap.put(request.instances[i], new AtomicBoolean(true)); } } myDoneMap.putAll(doneMap); } long myThread = latestThread.incrementAndGet(); while (true) { if (isCancelled(request.runGuid)) { curThread.incrementAndGet(); throw new CancellationException(); } if (myThread == curThread.get() + 1) { for (Map.Entry<String, AtomicBoolean> done : myDoneMap.entrySet()) { if (done.getValue().compareAndSet(true, false)) { if (ScreenSlicer.isBusy(done.getKey())) { done.getValue().set(true); } else { myInstance = done.getKey(); myDone = done.getValue(); break; } } } if (myInstance != null) { break; } } try { Thread.sleep(WAIT); } catch (Exception e) { Log.exception(e); } } curThread.incrementAndGet(); int outputNumber = 0; request.instances = new String[] { myInstance }; Map<String, List<List<String>>> tables = customApp.tableData(request, args); Map<String, Map<String, Object>> jsons = customApp.jsonData(request, args); Map<String, byte[]> binaries = customApp.binaryData(request, args); request.emailExport.attachments = new LinkedHashMap<String, byte[]>(); if (tables != null) { for (Map.Entry<String, List<List<String>>> table : tables.entrySet()) { if (table.getKey().toLowerCase().endsWith(".xls")) { byte[] result = Spreadsheet.xls(table.getValue()); CommonFile.writeByteArrayToFile( new File("./data/" + request.runGuid + "-result" + outputNumber), result, false); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(table.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(table.getKey(), result); } } else if (table.getKey().toLowerCase().endsWith(".csv")) { String result = Spreadsheet.csv(table.getValue()); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result" + outputNumber), result, false); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(table.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(table.getKey(), result.getBytes("utf-8")); } } else if (table.getKey().toLowerCase().endsWith(".xcsv")) { String result = Spreadsheet.csv(table.getValue()); CommonUtil.internalHttpCall(CommonUtil.ip(), "https://" + CommonUtil.ip() + ":8000/_/" + Crypto.fastHash(table.getKey() + ":" + request.runGuid), "PUT", CommonUtil.asMap("Content-Type", "text/csv; charset=utf-8"), result.getBytes("utf-8"), null); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(table.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(table.getKey(), result.getBytes("utf-8")); } } else { String result = CommonUtil.gson.toJson(table.getValue(), table.getValue().getClass()); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result" + outputNumber), result, false); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(table.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(table.getKey(), result.getBytes("utf-8")); } } } } if (jsons != null) { for (Map.Entry<String, Map<String, Object>> json : jsons.entrySet()) { String result = CommonUtil.gson.toJson(json.getValue(), CommonUtil.objectType); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result" + outputNumber), result, false); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(json.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(json.getKey(), result.getBytes("utf-8")); } } } if (binaries != null) { for (Map.Entry<String, byte[]> binary : binaries.entrySet()) { CommonFile.writeByteArrayToFile( new File("./data/" + request.runGuid + "-result" + outputNumber), binary.getValue(), false); CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-result-names"), escapeName(binary.getKey()) + "\n", true); ++outputNumber; if (request.emailResults) { request.emailExport.attachments.put(binary.getKey(), binary.getValue()); } } } if (request.emailResults) { ScreenSlicer.export(request, request.emailExport); } } catch (Throwable t) { Log.exception(t); } finally { try { CommonFile.writeStringToFile( new File("./data/" + request.runGuid + "-meta" + request.appId), "\n" + Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTimeInMillis(), true); } catch (Throwable t) { Log.exception(t); } myDone.set(true); synchronized (cancelledLock) { cancelledJobs.remove(request.runGuid); } } } }).start(); return Response.ok(Crypto.encode(request.runGuid, CommonUtil.ip())).build(); } } return null; }
From source file:net.shopxx.plugin.unionpayPayment.UnionpayPaymentPlugin.java
/** * ???/* w w w . ja v a 2 s .com*/ * * @param request * @return */ public static Map<String, String> getAllRequestParam(final HttpServletRequest request) { Map<String, String> res = new HashMap<String, String>(); Enumeration<?> temp = request.getParameterNames(); if (null != temp) { while (temp.hasMoreElements()) { String en = (String) temp.nextElement(); String value = request.getParameter(en); res.put(en, value); // ???<?????> if (res.get(en) == null || "".equals(res.get(en))) { // System.out.println("======??===="+en); res.remove(en); } } } return res; }
From source file:com.eucalyptus.objectstorage.pipeline.handlers.S3Authentication.java
static String buildStringToSignFromQueryParams(MappingHttpRequest httpRequest) throws Exception { // Standard S3 query string authentication Map<String, String> parameters = httpRequest.getParameters(); String verb = httpRequest.getMethod().getName(); String content_md5 = httpRequest.getHeader("Content-MD5"); content_md5 = content_md5 == null ? "" : content_md5; String content_type = httpRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE); content_type = content_type == null ? "" : content_type; String addrString = getS3AddressString(httpRequest, true); String accesskeyid = parameters.remove(SecurityParameter.AWSAccessKeyId.toString()); String expires = parameters.remove(SecurityParameter.Expires.toString()); if (expires == null) { throw new InvalidSecurityException("Expiration parameter must be specified."); }/*from w ww . j a v a 2 s. c om*/ String canonicalizedAmzHeaders = getCanonicalizedAmzHeaders(httpRequest, true); return verb + "\n" + content_md5 + "\n" + content_type + "\n" + Long.parseLong(expires) + "\n" + canonicalizedAmzHeaders + addrString; }
From source file:org.openremote.server.route.SubflowRoute.java
public static String peekCorrelationStack(Map<String, Object> headers, boolean root, boolean removeHeader) { String instanceId = null;//from w w w . j a v a 2s . co m if (hasCorrelationStack(headers)) { @SuppressWarnings("unchecked") Stack<String> correlationStack = (Stack<String>) headers.get(SUBFLOW_CORRELATION_STACK); if (correlationStack.size() > 0) { if (root) { instanceId = correlationStack.get(0); LOG.debug("Got correlation stack root element: " + instanceId); } else { instanceId = correlationStack.peek(); LOG.debug("Got correlation stack current element: " + instanceId); } } if (removeHeader) headers.remove(SUBFLOW_CORRELATION_STACK); } return instanceId; }
From source file:com.sunchenbin.store.feilong.core.net.ParamUtil.java
/** * parameter list.//w w w . ja v a 2 s . c o m * * @param uriString * the uri string * @param queryString * the query string * @param paramNameList * the param name list * @param charsetType * ??, {@link CharsetType}<br> * <span style="color:green">null empty,?,?</span><br> * ??,??,ie?chrome? url ,? * @return the string * @since 1.4.0 */ private static String removeParameterList(String uriString, String queryString, List<String> paramNameList, String charsetType) { if (Validator.isNullOrEmpty(uriString)) { return StringUtils.EMPTY; } if (Validator.isNullOrEmpty(queryString)) { return uriString;// ?? } Map<String, String[]> singleValueMap = toSafeArrayValueMap(queryString, null); for (String paramName : paramNameList) { singleValueMap.remove(paramName); } return combineUrl(URIUtil.getFullPathWithoutQueryString(uriString), singleValueMap, charsetType); }
From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java
/** * Same algorithm as the LCOV genhtml tool so it should always yield the same result. * @param indexPages//from w w w . j a v a 2 s. c om * @return The prefix to remove or null. */ public static String getPrefix(Collection<TestCaseSourceFile> indexPages) { Map<String, Integer> prefix = new HashMap<String, Integer>(); for (CoveragePage page : indexPages) { String current = page.getPath(); while ((current = shortenPrefix(current)) != null) { String next = current + '/'; if (!prefix.containsKey(next)) { prefix.put(next, 0); } } } for (CoveragePage page : indexPages) { String dir = page.getPath(); for (int i = 0; i < MIN_DIRECTORIES; i++) { prefix.remove(dir + '/'); dir = shortenPrefix(dir); } } Set<String> keys = prefix.keySet(); for (String current : keys) { for (CoveragePage page : indexPages) { String path = page.getPath(); prefix.put(current, prefix.get(current) + path.length()); if (path.startsWith(current)) { prefix.put(current, prefix.get(current) - current.length()); } } } String result = null; //Find and return prefix with minimal sum for (String current : keys) { if (result == null) { result = current; } else if (prefix.get(current) < prefix.get(result)) { result = current; } } return result; }
From source file:com.kylinolap.query.routing.QueryRouter.java
private static void adjustOLAPContext(Collection<TblColRef> dimensionColumns, Collection<FunctionDesc> aggregations, // Collection<TblColRef> metricColumns, CubeInstance cube, Map<String, RelDataType> rewriteFields, OLAPContext olapContext) {/*from w w w .j ava 2 s . co m*/ CubeDesc cubeDesc = cube.getDescriptor(); Collection<FunctionDesc> cubeFuncs = cubeDesc.listAllFunctions(); Iterator<FunctionDesc> it = aggregations.iterator(); while (it.hasNext()) { FunctionDesc functionDesc = it.next(); if (!cubeFuncs.contains(functionDesc)) { // try to convert the metric to dimension to see if it works TblColRef col = findTblColByColumnName(metricColumns, functionDesc.getParameter().getValue()); functionDesc.setAppliedOnDimension(true); rewriteFields.remove(functionDesc.getRewriteFieldName()); if (col != null) { metricColumns.remove(col); dimensionColumns.add(col); olapContext.storageContext.addOtherMandatoryColumns(col); } logger.info("Adjust OLAPContext for " + functionDesc); } } }
From source file:com.eucalyptus.objectstorage.pipeline.handlers.S3Authentication.java
private static void processHeaderValue(String name, String value, Map<String, String> aggregatingMap) { String headerNameString = name.toLowerCase().trim(); if (headerNameString.startsWith("x-amz-")) { value = value.trim();//from w w w .j a v a 2 s . c o m String[] parts = value.split("\n"); value = ""; for (String part : parts) { part = part.trim(); value += part + " "; } value = value.trim(); if (aggregatingMap.containsKey(headerNameString)) { String oldValue = (String) aggregatingMap.remove(headerNameString); oldValue += "," + value; aggregatingMap.put(headerNameString, oldValue); } else { aggregatingMap.put(headerNameString, value); } } }