Example usage for java.util Map remove

List of usage examples for java.util Map remove

Introduction

In this page you can find the example usage for java.util Map remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:CopyOnWriteMap.java

/**
 * Removed the value and key from this map based on the
 * provided key./*from   w  ww .  j av a2s.c o m*/
 *
 * @see java.util.Map#remove(java.lang.Object)
 */
public V remove(Object key) {
    synchronized (this) {
        Map<K, V> newMap = new HashMap<K, V>(internalMap);
        V val = newMap.remove(key);
        internalMap = newMap;
        return val;
    }
}

From source file:edu.wisc.my.portlets.bookmarks.web.DeleteEntryFormController.java

/**
 * @see org.springframework.web.portlet.mvc.AbstractController#handleActionRequestInternal(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
 *//* ww w . ja v a 2 s  . com*/
@Override
protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
    final String entryIndex = StringUtils.defaultIfEmpty(request.getParameter("entryIndex"), null);

    //Get the BookmarkSet from the store
    final BookmarkSet bs = this.bookmarkSetRequestResolver.getBookmarkSet(request, false);
    if (bs == null) {
        throw new IllegalArgumentException("No BookmarkSet exists for request='" + request + "'");
    }

    final IdPathInfo targetEntryPathInfo = FolderUtils.getEntryInfo(bs, entryIndex);
    if (targetEntryPathInfo != null && targetEntryPathInfo.getTarget() != null) {
        final Folder parentFolder = targetEntryPathInfo.getParent();
        if (parentFolder != null) {
            final Map<Long, Entry> children = parentFolder.getChildren();
            final Entry target = targetEntryPathInfo.getTarget();
            children.remove(target.getId());

            //Persist the changes to the BookmarkSet 
            this.bookmarkStore.storeBookmarkSet(bs);
        } else {
            //Deleting the root bookmark
            this.bookmarkStore.removeBookmarkSet(bs.getOwner(), bs.getName());
        }
    } else {
        this.logger.warn("No IdPathInfo found for BaseFolder='" + bs + "' and idPath='" + entryIndex + "'");
    }

    //Go back to view bookmarks
    response.setRenderParameter("action", "viewBookmarks");
}

From source file:io.fabric8.camel.FabricPublisherEndpoint.java

public FabricPublisherEndpoint(String uri, FabricComponent component, String singletonId, String child)
        throws Exception {
    super(uri, component);
    this.component = component;
    this.singletonId = singletonId;

    String path = child;//from  w w w  . j a v  a  2 s .  c  o m
    int idx = path.indexOf('?');
    if (idx > -1) {
        path = path.substring(0, idx);
    }
    Map<String, Object> params = URISupport.parseParameters(new URI(child));
    String consumer = params != null ? (String) params.remove("consumer") : null;
    if (consumer != null) {
        Map<String, Object> properties = IntrospectionSupport.extractProperties(params, "consumer.");
        if (properties != null && properties.size() > 0) {
            consumer = consumer + "?" + URISupport.createQueryString(properties);
            for (String k : properties.keySet()) {
                params.remove(k);
            }
        }
        child = path;
        if (params.size() > 0) {
            child = child + "?" + URISupport.createQueryString(params);
        }
    } else {
        consumer = child;
    }
    LOG.info("Child: " + child);
    LOG.info("Consumer: " + consumer);
    this.child = child;
    this.consumer = consumer;

    path = getComponent().getFabricPath(singletonId);
    group = getComponent().createGroup(path);
    CamelNodeState state = new CamelNodeState(singletonId);
    state.consumer = consumer;
    group.update(state);
}

From source file:com.solace.labs.spring.cloud.cloudfoundry.SolaceMessagingServiceInfoCreatorTest.java

@Test(expected = IllegalArgumentException.class)
public void corruptVcapTest() {
    Map<String, Object> exVcapServices = createVcapMap();

    exVcapServices.remove("credentials");

    SolaceMessagingInfoCreator smic = new SolaceMessagingInfoCreator();

    // Should still accept it.
    assertTrue(smic.accept(exVcapServices));

    // Should be throw exception for null credentials.
    smic.createServiceInfo(exVcapServices);
}

From source file:org.cybercat.automation.core.WeakReferenceThreadScope.java

@SuppressWarnings("rawtypes")
public Object get(String name, ObjectFactory objectFactory) {
    System.gc();/*from w ww .j a  v a 2  s . c o m*/
    Map<String, WeakReference<Object>> scope = threadScope.get();
    WeakReference<Object> wRef = scope.get(name);
    Object object;
    if (wRef == null || wRef.get() == null) {
        scope.remove(name);
        object = objectFactory.getObject();
        wRef = new WeakReference<Object>(object);
        scope.put(name, wRef);
    } else {
        object = wRef.get();
    }
    return object;
}

From source file:io.cloudslang.lang.runtime.bindings.scripts.ScriptEvaluator.java

private boolean getSensitive(Map<String, Serializable> executionResultContext,
        boolean systemPropertiesInContext) {
    if (systemPropertiesInContext) {
        Map<String, Serializable> context = new HashMap<>(executionResultContext);
        PyObject rawSystemProperties = (PyObject) context.remove(SYSTEM_PROPERTIES_MAP);
        @SuppressWarnings("unchecked")
        Map<String, Value> systemProperties = Py.tojava(rawSystemProperties, Map.class);
        @SuppressWarnings("unchecked")
        Collection<Serializable> systemPropertyValues = (Collection) systemProperties.values();
        return checkSensitivity(systemPropertyValues) || checkSensitivity(context.values());
    } else {//  w  w w.  ja v a  2 s. c om
        return (checkSensitivity(executionResultContext.values()));
    }
}

From source file:net.big_oh.common.web.listener.session.SimpleSessionTrackingListener.java

public void sessionDestroyed(HttpSessionEvent se) {
    Map<HttpSession, Object> sessions = getSessionsCollectionForServletContext(
            se.getSession().getServletContext());

    sessions.remove(se.getSession());

    logger.info("Registered the destruction of an HttpSession: " + se.getSession().getId());
}

From source file:org.geppetto.core.scope.ThreadScope.java

/**
 * Removes bean from scope./*from w w  w.  j  a  v  a 2 s. c o  m*/
 */
public Object remove(String name) {
    Object result = null;

    Map<String, Object> hBeans = ThreadScopeContextHolder.currentThreadScopeAttributes().getBeanMap();

    if (hBeans.containsKey(name)) {
        result = hBeans.get(name);

        hBeans.remove(name);
    }

    return result;
}

From source file:fr.ortolang.diffusion.core.indexing.MetadataObjectIndexableContent.java

public MetadataObjectIndexableContent(MetadataObject metadata, MetadataFormat format)
        throws IndexingServiceException, OrtolangException, KeyNotFoundException, RegistryServiceException {
    super(metadata, CoreService.SERVICE_NAME, MetadataObject.OBJECT_TYPE);
    RegistryService registry = (RegistryService) OrtolangServiceLocator.lookup(RegistryService.SERVICE_NAME,
            RegistryService.class);
    OrtolangObjectIdentifier objectIdentifier = registry.lookup(metadata.getTarget());
    content.put("target", metadata.getTarget());
    content.put("targetType", objectIdentifier.getType());
    content.put("size", metadata.getSize());
    content.put("mimeType", metadata.getContentType());
    //        if (metadata.getName().startsWith("system-x-")) {
    if (format != null && format.isIndexable() && metadata.getStream() != null
            && metadata.getStream().length() > 0) {
        BinaryStoreService binary = (BinaryStoreService) OrtolangServiceLocator
                .lookup(BinaryStoreService.SERVICE_NAME, BinaryStoreService.class);
        ObjectMapper mapper = new ObjectMapper();
        try {/*from  ww w. jav  a  2 s  .co m*/
            Map extraction = mapper.readValue(binary.getFile(metadata.getStream()), Map.class);
            for (String key : UNUSED_KEYS) {
                extraction.remove(key);
            }
            content.put("extraction", extraction);
        } catch (IOException | BinaryStoreServiceException | DataNotFoundException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    setContent(content);
}

From source file:com.liferay.portal.servlet.PortalSessionListener.java

public void sessionDestroyed(HttpSessionEvent event) {
    HttpSession ses = event.getSession();

    PortalSessionContext.remove(ses.getId());

    String companyId = (String) ses.getAttribute(WebKeys.COMPANY_ID);
    String userId = (String) ses.getAttribute(WebKeys.USER_ID);

    // Close mail connections

    // Shared session

    String sharedSessionId = (String) ses.getAttribute(WebKeys.SHARED_SESSION_ID);

    _log.debug("Shared session id is " + sharedSessionId);

    // Just in case the session is not properly removed in time, MainServlet
    // and SharedServletWrapper also make calls to ensure the session is
    // removed from the pool for garbage collection

    if (sharedSessionId != null) {
        _log.debug("Removing session from pool");

        SharedSessionPool.remove(sharedSessionId);
    }//from  w w  w. ja va2  s .  co  m

    // User tracker

    if (companyId != null) {
        Map currentUsers = (Map) WebAppPool.get(companyId, WebKeys.CURRENT_USERS);

        UserTracker userTracker = (UserTracker) currentUsers.remove(ses.getId());

        try {
            if (userTracker != null) {
                UserTrackerLocalManagerUtil.addUserTracker(userTracker.getCompanyId(), userTracker.getUserId(),
                        userTracker.getModifiedDate(), userTracker.getRemoteAddr(), userTracker.getRemoteHost(),
                        userTracker.getUserAgent(), userTracker.getPaths());
            }
        } catch (Exception e) {
            Logger.error(this, e.getMessage(), e);
        }
    }

    // Process session destroyed events

    try {
        EventsProcessor.process(PropsUtil.getArray(PropsUtil.SERVLET_SESSION_DESTROY_EVENTS), ses);
    } catch (ActionException ae) {
        Logger.error(this, ae.getMessage(), ae);
    }
}