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:de.inetsource.jsfforum.config.ViewScope.java

@Override
public Object remove(String name) {
    Object instance = this.getViewMap().remove(name);
    if (instance == null) {
        Map<String, Runnable> callbacks = (Map<String, Runnable>) this.getViewMap().get(VIEW_SCOPE_CALLBACKS);
        if (callbacks != null) {
            callbacks.remove(name);
        }// www. j a  v a 2 s.  c  o m
    }
    return instance;
}

From source file:com.yahoo.sql4d.query.topn.TopNQueryMeta.java

@Override
public Map<String, Object> getJsonMap() {
    Map<String, Object> map = super.getJsonMap();
    map.put("queryType", "topN");
    map.remove("dimensions");// During promotion from GroupBy dimensions may have sneaked in so remove it.
    if (dimension != null) {
        map.put("dimension", dimension);
    }/* w  w w .j a  va  2 s.com*/
    map.put("threshold", threshold);
    if (metric != null) {
        map.put("metric", metric);
    }
    return map;
}

From source file:org.openmrs.module.mirebalaisreports.definitions.InpatientStatsDailyReportManagerTest.java

private void assertAndRemove(Map<String, Integer> results, String key, int expected) {
    assertThat(key + " should be " + expected, results.get(key), is(expected));
    results.remove(key);
}

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

/**
 * @see org.springframework.web.portlet.mvc.SimpleFormController#onSubmitAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException)
 */// w ww . ja v a2s  .co m
@Override
protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    final String targetParentPath = StringUtils.defaultIfEmpty(request.getParameter("folderPath"), null);
    final String targetEntryPath = StringUtils.defaultIfEmpty(request.getParameter("idPath"), null);

    //User edited bookmark
    final CollectionFolder commandCollection = (CollectionFolder) command;

    //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 + "'");
    }

    //Get the target parent folder
    final IdPathInfo targetParentPathInfo = FolderUtils.getEntryInfo(bs, targetParentPath);
    if (targetParentPathInfo == null || targetParentPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified parent Folder does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetParentPath + "'");
    }

    final Folder targetParent = (Folder) targetParentPathInfo.getTarget();
    final Map<Long, Entry> targetChildren = targetParent.getChildren();

    //Get the original bookmark & it's parent folder
    final IdPathInfo originalBookmarkPathInfo = FolderUtils.getEntryInfo(bs, targetEntryPath);
    if (targetParentPathInfo == null || originalBookmarkPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified Bookmark does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetEntryPath + "'");
    }

    final Folder originalParent = originalBookmarkPathInfo.getParent();
    final CollectionFolder originalCollection = (CollectionFolder) originalBookmarkPathInfo.getTarget();

    //If moving the bookmark
    if (targetParent.getId() != originalParent.getId()) {
        final Map<Long, Entry> originalChildren = originalParent.getChildren();
        originalChildren.remove(originalCollection.getId());

        commandCollection.setCreated(originalCollection.getCreated());
        commandCollection.setModified(new Date());

        targetChildren.put(commandCollection.getId(), commandCollection);
    }
    //If just updaing the bookmark
    //TODO should the formBackingObject be smarter on form submits for editBookmark and return the targeted bookmark?
    else {
        originalCollection.setModified(new Date());
        originalCollection.setName(commandCollection.getName());
        originalCollection.setNote(commandCollection.getNote());
        originalCollection.setUrl(commandCollection.getUrl());
        originalCollection.setMinimized(commandCollection.isMinimized());
    }

    //Persist the changes to the BookmarkSet 
    this.bookmarkStore.storeBookmarkSet(bs);
}

From source file:android.databinding.tool.store.SetterStore.java

private static <K, V> void removeFromMap(Map<K, V> map, List<K> keys) {
    for (K key : keys) {
        map.remove(key);
    }// w w  w  .  ja  v  a 2 s .  c  om
    keys.clear();
}

From source file:com.yahoo.sql4d.query.search.SearchQueryMeta.java

@Override
public Map<String, Object> getJsonMap() {
    Map<String, Object> map = super.getJsonMap();
    map.put("queryType", "search");
    map.remove("dimensions");// Because it is called searchDimensions here.
    if (fetchDimensions != null) {
        JSONArray dimensionsArray = new JSONArray();
        for (String dim : fetchDimensions.keySet()) {
            dimensionsArray.put(dim);/*from  w  w w . java  2 s.  co  m*/
        }
        map.put("searchDimensions", dimensionsArray);
    }
    JSONObject queryJson = new JSONObject();
    queryJson.put("type", type);
    // TODO: more validation needed here.
    if (type.equals("insensitive_contains")) {
        queryJson.put("value", values.get(0));
    } else if (type != null && type.equals("fragment")) {
        JSONArray valuesArray = new JSONArray();
        for (String val : values) {
            valuesArray.put(val);
        }
        queryJson.put("values", valuesArray);
    }
    map.put("query", queryJson);
    if (sort != null) {
        JSONObject sortJson = new JSONObject();
        sortJson.put("type", sort);
        map.put("sort", sortJson);
    }
    return map;
}

From source file:com.netflix.ice.basic.BasicS3ApplicationGroupService.java

public boolean deleteApplicationGroup(String name) {
    Map<String, ApplicationGroup> appgroups = getApplicationGroups();
    ApplicationGroup appgroup = appgroups.remove(name);

    try {//from ww  w  .  ja  va  2 s.  c om
        String json = getJson(appgroups);
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups",
                new ByteArrayInputStream(json.getBytes()), new ObjectMetadata());

        BasicS3ApplicationGroupService.logger.info("delete appgroup " + name + " " + appgroup);
        return true;
    } catch (JSONException e) {
        logger.error("Error deleting appgroup " + appgroup, e);
        return false;
    }
}

From source file:com.swtxml.swt.types.LayoutType.java

public Layout convert(String value, Strictness strictness) {
    Map<String, String> layoutConstraints = KeyValueParser.parse(value, strictness);

    String layoutName = layoutConstraints.remove(LAYOUT_KEY);
    if (layoutName == null) {
        if (strictness == Strictness.STRICT) {
            throw new ParseException("no layout specified");
        } else {/*from  w  w  w.  java  2s. c om*/
            return null;
        }
    }

    Layout layout = createLayout(layoutName, Strictness.STRICT);

    IInjector injector = SwtInfo.LAYOUT_PROPERTIES.getProperties(layout.getClass()).getInjector(layout);
    injector.setPropertyValues(layoutConstraints);

    return layout;
}

From source file:com.mnt.base.web.action.impl.ActionControllerManagerImpl.java

@Override
public void dispatchRequest(String requestUri, String method, Map<String, Object> parameters,
        ResponseHandler responseHandler) {

    Object responseHolder = super.processRequest(requestUri, method, parameters);

    if (responseHolder != null) {
        String responseText = "";

        if (responseHolder instanceof Map) {
            Map<String, Object> resultMap = CommonUtil.uncheckedMapCast(responseHolder);
            int statusCode = CommonUtil.parseAsInt(resultMap.remove(ActionController.K_RESPONSE_CODE), 200);
            WebUtils.getResponse().setStatus(statusCode);

            try {
                responseText = JSONTool.convertObjectToJson(resultMap);
            } catch (Exception e) {
                log.error("Fail to convert response object to json string: " + responseHolder, e);
            } finally {
                CommonUtil.deepClear(responseHolder);
            }//from   w  w w .  j a  v  a  2s .com
        } else if (responseHolder instanceof String) {
            responseText = CommonUtil.castAsString(responseHolder);
        } else {
            try {
                responseText = JSONTool.convertObjectToJson(responseHolder);
            } catch (Exception e) {
                log.error("Fail to convert response object to json string: " + responseHolder, e);
            } finally {
                CommonUtil.deepClear(responseHolder);
            }
        }

        responseHandler.response(responseText);
    }
}

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

/**
 * @see org.springframework.web.portlet.mvc.SimpleFormController#onSubmitAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException)
 *///w  w  w  .j a va 2 s . c  om
@Override
protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command,
        BindException errors) throws Exception {
    final String targetParentPath = StringUtils.defaultIfEmpty(request.getParameter("folderPath"), null);
    final String targetEntryPath = StringUtils.defaultIfEmpty(request.getParameter("idPath"), null);

    //User edited bookmark
    final Bookmark commandBookmark = (Bookmark) command;

    //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 + "'");
    }

    //Get the target parent folder
    final IdPathInfo targetParentPathInfo = FolderUtils.getEntryInfo(bs, targetParentPath);
    if (targetParentPathInfo == null || targetParentPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified parent Folder does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetParentPath + "'");
    }

    final Folder targetParent = (Folder) targetParentPathInfo.getTarget();
    final Map<Long, Entry> targetChildren = targetParent.getChildren();

    //Get the original bookmark & it's parent folder
    final IdPathInfo originalBookmarkPathInfo = FolderUtils.getEntryInfo(bs, targetEntryPath);
    if (targetParentPathInfo == null || originalBookmarkPathInfo.getTarget() == null) {
        throw new IllegalArgumentException("The specified Bookmark does not exist. BaseFolder='" + bs
                + "' and idPath='" + targetEntryPath + "'");
    }

    final Folder originalParent = originalBookmarkPathInfo.getParent();
    final Bookmark originalBookmark = (Bookmark) originalBookmarkPathInfo.getTarget();

    //If moving the bookmark
    if (targetParent.getId() != originalParent.getId()) {
        final Map<Long, Entry> originalChildren = originalParent.getChildren();
        originalChildren.remove(originalBookmark.getId());

        commandBookmark.setCreated(originalBookmark.getCreated());
        commandBookmark.setModified(new Date());

        targetChildren.put(commandBookmark.getId(), commandBookmark);
    }
    //If just updaing the bookmark
    //TODO should the formBackingObject be smarter on form submits for editBookmark and return the targeted bookmark?
    else {
        originalBookmark.setModified(new Date());
        originalBookmark.setName(commandBookmark.getName());
        originalBookmark.setNote(commandBookmark.getNote());
        originalBookmark.setUrl(commandBookmark.getUrl());
        originalBookmark.setNewWindow(commandBookmark.isNewWindow());
    }

    //Persist the changes to the BookmarkSet 
    this.bookmarkStore.storeBookmarkSet(bs);
}