List of usage examples for java.util Map remove
V remove(Object key);
From source file:edu.isi.misd.scanner.network.registry.web.controller.BaseController.java
public static Map<String, String> validateParameterMap(Map<String, String> paramMap, String... paramNames) throws BadRequestException { HashMap<String, String> validParams = new HashMap<String, String>(); if (!paramMap.isEmpty()) { String paramValue;//from w w w . ja v a 2 s .c om for (String paramName : paramNames) { paramValue = paramMap.remove(paramName); if (paramValue != null) { validParams.put(paramName, paramValue); } } if (!paramMap.isEmpty()) { throw new BadRequestException(paramMap.keySet()); } } return validParams; }
From source file:controllers.oer.Application.java
private static String withoutLocation(String sourceAsString) { try {/*from w w w .ja v a2 s. co m*/ // JSON-LD compact, always an object (resulting in a map) @SuppressWarnings("unchecked") Map<String, Object> json = (Map<String, Object>) JSONUtils.fromString(sourceAsString); json.remove("location"); return JSONUtils.toString(json); } catch (JsonParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return sourceAsString; }
From source file:org.craftercms.studio.impl.v1.web.http.MultiReadHttpServletRequestWrapper.java
public static void toMap(Iterable<NameValuePair> inputParams, Map<String, String[]> toMap) { for (NameValuePair e : inputParams) { String key = e.getName(); String value = e.getValue(); if (toMap.containsKey(key)) { String[] newValue = ArrayUtils.addAll(toMap.get(key), value); toMap.remove(key); toMap.put(key, newValue);//ww w.j av a2 s.c o m } else { toMap.put(key, new String[] { value }); } } }
From source file:org.elasticsearch.client.sniff.ElasticsearchNodesSniffer.java
/** * Returns {@code defaultValue} if the attribute didn't come back, * {@code true} or {@code false} if it did come back as * either of those, or throws an IOException if the attribute * came back in a strange way./*from w w w . ja va 2 s . com*/ */ private static Boolean v2RoleAttributeValue(Map<String, List<String>> attributes, String name, Boolean defaultValue) throws IOException { List<String> valueList = attributes.remove(name); if (valueList == null) { return defaultValue; } if (valueList.size() != 1) { throw new IOException("expected only a single attribute value for [" + name + "] but got " + valueList); } switch (valueList.get(0)) { case "true": return true; case "false": return false; default: throw new IOException( "expected [" + name + "] to be either [true] or [false] but was [" + valueList.get(0) + "]"); } }
From source file:azkaban.server.HttpRequestUtils.java
/** * <pre>/*from w ww . j a v a2 s. c o m*/ * Remove following flow param if submitting user is not an Azkaban admin * FLOW_PRIORITY * USE_EXECUTOR * @param userManager * @param options * @param user * </pre> */ public static void filterAdminOnlyFlowParams(UserManager userManager, ExecutionOptions options, User user) throws ExecutorManagerException { if (options == null || options.getFlowParameters() == null) return; Map<String, String> params = options.getFlowParameters(); // is azkaban Admin if (!hasPermission(userManager, user, Type.ADMIN)) { params.remove(ExecutionOptions.FLOW_PRIORITY); params.remove(ExecutionOptions.USE_EXECUTOR); } else { validateIntegerParam(params, ExecutionOptions.FLOW_PRIORITY); validateIntegerParam(params, ExecutionOptions.USE_EXECUTOR); } }
From source file:au.org.ala.layers.util.BatchProducer.java
public static void logUpdateEntry(String batchId, String newStatus, String infoKey, String infoValue, Integer newProgress) {/* ww w . j a v a 2s . c o m*/ Map m = (Map) log.get(batchId); if (m == null) { //cannot update status for a missing entry return; } if (newStatus != null) { //remove keys that can become irrelevent with status updates m.remove("waiting"); m.put("status", newStatus); } if (infoKey != null) { m.put(infoKey, infoValue); } if (newProgress != null) { //progress cannot get smaller if (m.containsKey("progress")) { Integer oldProgress = (Integer) m.get("progress"); if (oldProgress < newProgress) { m.put("progress", newProgress); } } else { m.put("progress", newProgress); } } }
From source file:Main.java
/** * Sets the value of the entry in the map for the given key, though if the * map already contains a value for the given key then the value is appended * to a list of values.//from w w w. ja v a2s . c o m * * @param map the map to add the entry to * @param key the key in the map * @param value the value to put in the map */ @SuppressWarnings("unchecked") public static void appendValue(Map<String, Object> map, String key, Object value) { Object oldValue = map.get(key); if (oldValue != null) { List<Object> list; if (oldValue instanceof List) { list = (List<Object>) oldValue; } else { list = new ArrayList<Object>(); list.add(oldValue); // replace old entry with list map.remove(key); map.put(key, list); } list.add(value); } else { map.put(key, value); } }
From source file:com.bazaarvoice.jolt.JsonUtils.java
/** * Removes a key recursively from anywhere in a JSON document. * NOTE: mutates its input./*from w w w.j a v a 2s . c om*/ * * Deprecated: use JoltUtils instead * * @param json the Jackson Object version of the JSON document * (contents changed by this call) * @param keyToRemove the key to remove from the document */ @Deprecated public static void removeRecursive(Object json, String keyToRemove) { if ((json == null) || (keyToRemove == null)) { return; } if (json instanceof Map) { Map<String, Object> jsonMap = (Map<String, Object>) json; // If this level of the tree has the key we are looking for, remove it if (jsonMap.containsKey(keyToRemove)) { jsonMap.remove(keyToRemove); } // regardless, recurse down the tree for (String subKey : jsonMap.keySet()) { Object value = jsonMap.get(subKey); removeRecursive(value, keyToRemove); } } if (json instanceof List) { for (Object value : (List) json) { removeRecursive(value, keyToRemove); } } }
From source file:com.zf.util.Post_NetNew.java
/** * ?/* w ww.j a v a 2 s . co m*/ * * @param pams * @param ip * @param port * @return * @throws Exception */ public static String pn(Map<String, String> pams, String ip, int port) throws Exception { if (null == pams) { return ""; } InetSocketAddress addr = new InetSocketAddress(ip, port); Proxy proxy = new Proxy(Type.HTTP, addr); String strtmp = "url"; URL url = new URL(pams.get(strtmp)); pams.remove(strtmp); strtmp = "body"; String body = pams.get(strtmp); pams.remove(strtmp); strtmp = "POST"; if (StringUtils.isEmpty(body)) strtmp = "GET"; HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(proxy); httpConn.setConnectTimeout(30000); httpConn.setReadTimeout(30000); httpConn.setUseCaches(false); httpConn.setRequestMethod(strtmp); for (String pam : pams.keySet()) { httpConn.setRequestProperty(pam, pams.get(pam)); } if ("POST".equals(strtmp)) { httpConn.setDoOutput(true); httpConn.setDoInput(true); DataOutputStream dos = new DataOutputStream(httpConn.getOutputStream()); dos.writeBytes(body); dos.flush(); } int resultCode = httpConn.getResponseCode(); StringBuilder sb = new StringBuilder(); sb.append(resultCode).append("\n"); String readLine; InputStream stream; try { stream = httpConn.getInputStream(); } catch (Exception ignored) { stream = httpConn.getErrorStream(); } try { BufferedReader responseReader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); while ((readLine = responseReader.readLine()) != null) { sb.append(readLine).append("\n"); } } catch (Exception ignored) { } return sb.toString(); }
From source file:org.duracloud.duradmin.util.SpaceUtil.java
private static ContentProperties populateContentProperties(Map<String, String> contentProperties) { ContentProperties properties = new ContentProperties(); properties.setMimetype(contentProperties.remove(ContentStore.CONTENT_MIMETYPE)); properties.setSize(contentProperties.remove(ContentStore.CONTENT_SIZE)); properties.setChecksum(contentProperties.remove(ContentStore.CONTENT_CHECKSUM)); properties.setModified(contentProperties.remove(ContentStore.CONTENT_MODIFIED)); properties.setTags(TagUtil.parseTags(contentProperties.remove(TagUtil.TAGS))); return properties; }