List of usage examples for java.util Map remove
V remove(Object key);
From source file:Main.java
/** * Removes all the given keys from the given map and adds their * corresponding values to the given collection. * * @param <TKey> The type of the keys of the map. * @param <TValue> The types of the values of the map. * @param target The map to remove the specified keys from. * @param keys An iterator providing the keys to be removed. * @param values A collection where the values corresponding to the given * keys are added./* w w w . j a v a 2s .c om*/ * @note In case the target or the keys are not effective, nothing happens. * @note In case values is not effective, the keys are removed without * adding them. */ public static <TKey, TValue> void removeAll(final Map<TKey, TValue> target, final Iterator<? extends TKey> keys, Collection<? super TValue> values) { if (values != null) { if (target != null && keys != null) { while (keys.hasNext()) { values.add(target.remove(keys.next())); } } } else { removeAll(target, keys); } }
From source file:com.exzogeni.dk.http.HttpTask.java
@NonNull private static Map<String, List<String>> getHeaderFields(HttpURLConnection cn) { final Map<String, List<String>> headers = cn.getHeaderFields(); if (headers != null) { final Map<String, List<String>> localHeaders = new HashMap<>(headers); localHeaders.remove(null); return Collections.unmodifiableMap(localHeaders); }/*from w w w .jav a2s . co m*/ return Collections.emptyMap(); }
From source file:com.baidu.rigel.biplatform.ac.util.ThreadLocalPlaceholder.java
/** * Remove the object from thread.//from w ww . j ava 2s. c om * * @param key * key of object */ public static void unbindProperty(Object key) { if (key == null) { throw new IllegalArgumentException("Parameter must not be null"); } // Get Current Thread Map Map<Object, Object> propertiesMap = getThreadMap(); if (!propertiesMap.containsKey(key)) { LOG.debug("Removed value [" + key + "] from thread [" + Thread.currentThread().getName() + "]"); } propertiesMap.remove(key); LOG.debug("Removed key [" + key + "] from thread [" + Thread.currentThread().getName() + "]"); }
From source file:Main.java
public static void printDetails(Map<String, String> map) { String usage = map.get("CSS"); System.out.println("Map: " + map); System.out.println("Map Size: " + map.size()); System.out.println("Map is empty: " + map.isEmpty()); System.out.println("Map contains CSS key: " + map.containsKey("CSS")); System.out.println("Usage: " + usage); System.out.println("removed: " + map.remove("CSS")); }
From source file:org.wso2.carbon.appmgt.gateway.handlers.Utils.java
public static void sendFault(MessageContext messageContext, int status) { org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); axis2MC.setProperty(NhttpConstants.HTTP_SC, status); messageContext.setResponse(true);// w w w . ja v a 2s . com messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MC.removeProperty("NO_ENTITY_BODY"); String method = (String) axis2MC.getProperty(Constants.Configuration.HTTP_METHOD); if (method.matches("^(?!.*(POST|PUT)).*$")) { // If the request was not an entity enclosing request, send a XML response back axis2MC.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml"); } // Always remove the ContentType - Let the formatter do its thing axis2MC.removeProperty(Constants.Configuration.CONTENT_TYPE); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { headers.remove(HttpHeaders.AUTHORIZATION); // headers.remove(HttpHeaders.ACCEPT); headers.remove(HttpHeaders.AUTHORIZATION); //headers.remove(HttpHeaders.ACCEPT); //Default we will send xml out put if error_message_type is json then we will send json response to client // We can set this parameter in _auth_failure_handler_ as follows /*<sequence name="_auth_failure_handler_"> <property name="error_message_type" value="application/json"/> <sequence key="_build_"/> </sequence> */ if (messageContext.getProperty("error_message_type") != null && messageContext .getProperty("error_message_type").toString().equalsIgnoreCase("application/json")) { axis2MC.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/json"); } headers.remove(HttpHeaders.HOST); } Axis2Sender.sendBack(messageContext); }
From source file:net.sf.groovyMonkey.GroovyMonkeyPlugin.java
public static void removeScript(final String name) { final Map<String, ScriptMetadata> store = scriptStore(); final ScriptMetadata oldScript = store.remove(name); if (oldScript == null) return;/*from w w w . j a va 2 s . c om*/ oldScript.unsubscribe(); }
From source file:com.elasticbox.jenkins.k8s.util.TestUtils.java
public static void clearEnv(String... keys) { try {/* w w w . j a v a 2s. c o m*/ Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment"); Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment"); theEnvironmentField.setAccessible(true); Map<String, String> env = (Map<String, String>) theEnvironmentField.get(null); for (String key : keys) { env.remove(key); } Field theCaseInsensitiveEnvironmentField = processEnvironmentClass .getDeclaredField("theCaseInsensitiveEnvironment"); theCaseInsensitiveEnvironmentField.setAccessible(true); Map<String, String> cienv = (Map<String, String>) theCaseInsensitiveEnvironmentField.get(null); for (String key : keys) { cienv.remove(key); } } catch (NoSuchFieldException e) { try { Class[] classes = Collections.class.getDeclaredClasses(); Map<String, String> env = System.getenv(); for (Class cl : classes) { if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) { Field field = cl.getDeclaredField("m"); field.setAccessible(true); Object obj = field.get(env); Map<String, String> map = (Map<String, String>) obj; for (String key : keys) { map.remove(key); } } } } catch (Exception e2) { e2.printStackTrace(); } } catch (Exception e1) { e1.printStackTrace(); } }
From source file:Main.java
/** * Removes the entries of a map that have null values. * // w w w . ja v a 2s .c o m * @param map * The map to strip. * @return The map that was passed in. */ public static <K, V> Map<K, V> stripNulls(final Map<K, V> map) { List<Object> toRemove = null; for (final Object key : map.keySet()) { if (map.get(key) == null) { toRemove = safeAdd(toRemove, key); } } if (toRemove != null) { for (final Object key : toRemove) { map.remove(key); } } return map; }
From source file:com.sun.faces.application.ApplicationAssociate.java
public static void clearInstance(ExternalContext externalContext) { Map applicationMap = externalContext.getApplicationMap(); applicationMap.remove(ASSOCIATE_KEY); }
From source file:org.wso2.carbon.appmgt.gateway.utils.GatewayUtils.java
private static void removeIrrelevantHeadersBeforeResponding(Map headerMap) { headerMap.remove(HttpHeaders.HOST); headerMap.remove(HTTPConstants.HEADER_COOKIE); }