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:com.cloudseal.spring.client.userdetails.CloudsealUserAttributes.java

private Collection<GrantedAuthority> removeRoleListAttribute(Map<String, Collection<XMLObject>> attributes) {
    Collection<XMLObject> list = attributes.remove(ROLES);
    if (list == null || list.isEmpty()) {
        return Collections.emptyList();
    }// ww  w . j a v a2s .  c om
    Collection<GrantedAuthority> roles = new ArrayList<GrantedAuthority>(list.size());
    for (XMLObject xmlObject : list) {
        if (XSString.class.isInstance(xmlObject)) {
            String roleName = ((XSString) xmlObject).getValue();
            roles.add(new GrantedAuthorityImpl(roleName));
        }
    }
    return Collections.unmodifiableCollection(roles);
}

From source file:com.bstek.dorado.idesupport.parse.RuleTemplateParser.java

@Override
@SuppressWarnings("unchecked")
protected Object doParse(Node node, ParseContext context) throws Exception {
    Element element = (Element) node;
    ConfigRuleParseContext parserContext = (ConfigRuleParseContext) context;
    RuleTemplate ruleTemplate;//from www . j  a v a 2 s. c om
    String name = element.getAttribute("name");

    if (StringUtils.isNotBlank(name)) {
        ruleTemplate = parserContext.getRuleTemplateMap().get(name);
        if (ruleTemplate != null) {
            return ruleTemplate;
        }
    }
    if (StringUtils.isBlank(name)) {
        if (global) {
            throw new XmlParseException("The global rule's 'name' attribute can not be blank.", node, context);
        } else {
            name = element.getAttribute("nodeName");
            if (StringUtils.isBlank(name)) {
                throw new XmlParseException(
                        "The 'name' attribute and the 'nodeName' attribute can not be blank at the same time.",
                        node, context);
            }
        }
    }

    ruleTemplate = new RuleTemplate(name);
    if (global) {
        parserContext.getRuleTemplateMap().put(name, ruleTemplate);
        ruleTemplate.setGlobal(true);
    }

    Map<String, Object> properties = parseProperties(element, context);

    String[] parents = (String[]) properties.remove("parents");
    if (parents != null) {
        List<RuleTemplate> parentList = new ArrayList<RuleTemplate>();
        for (String parentName : parents) {
            RuleTemplate parent = getRuleTemplate(parentName, parserContext);
            if (parent != null)
                parentList.add(parent);
        }
        properties.put("parents", parentList.toArray(new RuleTemplate[0]));
    }

    String clientTypesText = (String) properties.remove("clientTypes");
    int clientTypes = ClientType.parseClientTypes(clientTypesText);
    if (clientTypes > 0) {
        ruleTemplate.setClientTypes(clientTypes);
    }

    BeanUtils.copyProperties(ruleTemplate, properties);

    Element primitivePropsEl = DomUtils.getChildByTagName(element, "PrimitiveProps");
    if (primitivePropsEl != null) {
        ruleTemplate.addPrimitiveProperties(
                (Collection<PropertyTemplate>) dispatchChildElements(primitivePropsEl, parserContext));
    }

    Element propsEl = DomUtils.getChildByTagName(element, "Props");
    if (propsEl != null) {
        ruleTemplate
                .addProperties((Collection<PropertyTemplate>) dispatchChildElements(propsEl, parserContext));
    }

    Element eventsEl = DomUtils.getChildByTagName(element, "ClientEvents");
    if (eventsEl != null) {
        ruleTemplate.addClientEvents((Collection<ClientEvent>) dispatchChildElements(eventsEl, parserContext));
    }

    Element childrenEl = DomUtils.getChildByTagName(element, "Children");
    if (childrenEl != null) {
        ruleTemplate.addChildren((Collection<ChildTemplate>) dispatchChildElements(childrenEl, parserContext));
    }
    return ruleTemplate;
}

From source file:com.precioustech.fxtrading.utils.TradingUtilsTest.java

@Test
public void isEmptyTest() {
    List<String> nameColl = Lists.newArrayList("foo", "bar");
    assertFalse(TradingUtils.isEmpty(nameColl));
    nameColl.clear();/*from   w w  w.  j  a va  2 s  .  c o m*/
    assertTrue(TradingUtils.isEmpty(nameColl));
    nameColl = null;
    assertTrue(TradingUtils.isEmpty(nameColl));
    Map<Integer, String> idNameMap = Maps.newHashMap();
    idNameMap.put(1, "foobar");
    assertFalse(TradingUtils.isEmpty(idNameMap));
    idNameMap.remove(1);
    assertTrue(TradingUtils.isEmpty(idNameMap));
    idNameMap = null;
    assertTrue(TradingUtils.isEmpty(idNameMap));
}

From source file:algorithm.BagItPackaging.java

@Override
public List<RestoredFile> restore(File data) throws IOException {
    // BagIt won't override an existing directory, so delete:
    FileUtils.deleteDirectory(new File(RESTORED_DIRECTORY + data.getName().split("_")[0] + "_BAG"));
    File restoredData = new File(RESTORED_DIRECTORY + data.getName());
    // Move bag to restoration directory:
    if (!data.getPath().equals(restoredData.getPath())) {
        FileUtils.copyFile(data, restoredData);
    }/*  w ww. j  a  v  a  2s .  com*/
    List<RestoredFile> restoredFiles = new ArrayList<RestoredFile>();
    Loader loader = new Loader(restoredData);
    Bag bag = loader.load();
    // get carrier / digital object files:
    Map<String, String> carriersContents = bag.payloadManifest();
    for (Entry<String, String> entry : carriersContents.entrySet()) {
        String carrierName = entry.getKey();
        File carrierFile = new File(RESTORED_DIRECTORY + bag.bagName() + File.separator + carrierName);
        RestoredFile restoredCarrier = new RestoredFile(RESTORED_DIRECTORY + carrierFile.getName());
        restoredCarrier.delete();// BagIt won't override!
        FileUtils.moveFile(carrierFile, restoredCarrier);
        restoredCarrier.algorithm = this;
        restoredCarrier.wasCarrier = true;
        restoredFiles.add(restoredCarrier);
    }
    // get payload / metadata files:
    Map<String, String> payloadContents = bag.tagManifest();
    payloadContents.remove("bagit.txt");
    payloadContents.remove("bag-info.txt");
    payloadContents.remove("manifest-md5.txt");
    for (Entry<String, String> entry : payloadContents.entrySet()) {
        String payloadName = entry.getKey();
        File payloadFile = new File(RESTORED_DIRECTORY + bag.bagName() + File.separator + payloadName);
        RestoredFile restoredPayload = new RestoredFile(RESTORED_DIRECTORY + payloadFile.getName());
        restoredPayload.delete();// BagIt won't override existing files!
        FileUtils.moveFile(payloadFile, restoredPayload);
        restoredPayload.wasPayload = true;
        restoredFiles.add(restoredPayload);
    }
    for (RestoredFile file : restoredFiles) {
        file.algorithm = this;
        file.checksumValid = true;
        file.restorationNote = "The algorithm doesn't alter these files, so they are brought to its original state. No checksum validation executed.";
        for (RestoredFile relatedFile : restoredFiles) {
            if (file != relatedFile) {
                file.relatedFiles.add(relatedFile);
            }
        }
    }
    return restoredFiles;
}

From source file:com.alibaba.cobar.manager.web.screen.CobarDetailScreen.java

@SuppressWarnings("unchecked")
@Override/*from w ww.j a  v a 2s  .c om*/
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long nodeId = 0;
    try {
        nodeId = Long.parseLong(request.getParameter("nodeId").trim());
    } catch (Exception e) {
        throw new IllegalArgumentException("parameter 'nodeId' is invalid: " + request.getParameter("nodeId"));
    }
    CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(nodeId);
    if (null == cobar) {
        throw new IllegalArgumentException("no cobar exsit for id : " + nodeId);
    }

    PropertyUtilsBean util = new PropertyUtilsBean();
    Map<String, Object> cobarMap = null;
    try {
        cobarMap = util.describe(cobar);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    cobarMap.remove("class");
    cobarMap.remove("name");
    cobarMap.put("name", CobarStringUtil.htmlEscapedString(cobar.getName()));

    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(cobar.getClusterId());
    Map<String, Object> clusterMap = new HashMap<String, Object>();
    clusterMap.put("id", cluster.getId());
    clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));

    return new ModelAndView("v_cobarDetail", new FluenceHashMap<String, Object>().putKeyValue("user", user)
            .putKeyValue("cluster", clusterMap).putKeyValue("cobarNode", cobarMap));
}

From source file:com.eucalyptus.auth.login.Hmacv2LoginModule.java

private String makeSubjectString(String httpMethod, String host, String path,
        final Map<String, String> parameters) throws UnsupportedEncodingException {
    URLCodec codec = new URLCodec();
    parameters.remove("");
    StringBuilder sb = new StringBuilder();
    sb.append(httpMethod);// ww  w .j  a v a  2  s .  com
    sb.append("\n");
    sb.append(host);
    sb.append("\n");
    sb.append(path);
    sb.append("\n");
    String prefix = sb.toString();
    sb = new StringBuilder();
    NavigableSet<String> sortedKeys = new TreeSet<String>();
    sortedKeys.addAll(parameters.keySet());
    String firstKey = sortedKeys.pollFirst();
    if (firstKey != null) {
        sb.append(codec.encode(firstKey, "UTF-8")).append("=").append(
                codec.encode(Strings.nullToEmpty(parameters.get(firstKey)), "UTF-8").replaceAll("\\+", "%20"));
    }
    while ((firstKey = sortedKeys.pollFirst()) != null) {
        sb.append("&").append(codec.encode(firstKey, "UTF-8")).append("=").append(
                codec.encode(Strings.nullToEmpty(parameters.get(firstKey)), "UTF-8").replaceAll("\\+", "%20"));
    }
    String subject = prefix + sb.toString();
    LOG.trace("VERSION2: " + subject);
    return subject;
}

From source file:com.hortonworks.streamline.streams.catalog.TopologyEdge.java

@Override
public Map<String, Object> toMap() {
    Map<String, Object> map = super.toMap();
    map.remove(STREAMGROUPINGS);
    try {/*from  www .  j a v a2s.  c  om*/
        map.put(STREAMGROUPINGSDATA, getStreamGroupingsData());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}

From source file:org.elasticsearch.client.RestClientBuilderTestCase.java

/** Checks the given rest client has the provided default headers. */
public void assertHeaders(RestClient client, Map<String, String> expectedHeaders) {
    expectedHeaders = new HashMap<>(expectedHeaders); // copy so we can remove as we check
    for (Header header : client.defaultHeaders) {
        String name = header.getName();
        String expectedValue = expectedHeaders.remove(name);
        if (expectedValue == null) {
            fail("Found unexpected header in rest client: " + name);
        }/*from   w ww.  j  a  v a2 s  .  com*/
        assertEquals(expectedValue, header.getValue());
    }
    if (expectedHeaders.isEmpty() == false) {
        fail("Missing expected headers in rest client: " + Strings.join(expectedHeaders.keySet(), ", "));
    }
}

From source file:eu.trentorise.smartcampus.ac.provider.repository.memory.AcDaoMemoryImpl.java

@Override
public <T extends AcObject> boolean delete(T acObj) {
    boolean result = false;
    Map<Long, T> map = (Map<Long, T>) cache.get(acObj.getClass());
    if (map != null) {
        result = map.remove(acObj.getId()) != null;
    }//from w  w w .ja v  a  2 s .c o  m
    return result;
}

From source file:com.etsy.arbiter.util.NamedArgumentInterpolator.java

/**
 * Performs variable interpolation using the named arguments from an Action
 * This will create a new map if any interpolation is performed
 *
 * @param input The positional arguments possibly containing keys to be interpolated
 * @param namedArgs The key/value pairs used for interpolation
 * @param defaultArgs Default values for the named args, used if an interpolation key has no value given
 * @param listArgs The key/value list pairs used for list interpolation. List interpolation allows for interpolating a list of values in place of a single key
 *                 If any interpolation is performed this map is modified to remove the key that was interpolated
 *
 * @return A copy of input with variable interpolation performed
 *///w  w w .  j a v a  2s.c  o  m
public static Map<String, List<String>> interpolate(Map<String, List<String>> input,
        final Map<String, String> namedArgs, final Map<String, String> defaultArgs,
        final Map<String, List<String>> listArgs) {
    if (namedArgs == null || input == null) {
        return input;
    }

    final Map<String, String> interpolationArgs = createFinalInterpolationMap(namedArgs, defaultArgs);

    return Maps.transformValues(input, new Function<List<String>, List<String>>() {
        @Override
        public List<String> apply(List<String> input) {
            List<String> result = new ArrayList<>(input.size());
            for (String s : input) {
                String interpolated = StrSubstitutor.replace(s, interpolationArgs, PREFIX, SUFFIX);
                String listInterpolationKey = interpolated.replace(PREFIX, "").replace(SUFFIX, ""); // Strip out the prefix/suffix to get the actual key

                // If we have a standalone key we can use it for list interpolation
                // We only support standalone entries as it does not make sense to interpolate a list as part of a string
                if (listArgs != null && listArgs.containsKey(listInterpolationKey)) {
                    result.addAll(listArgs.get(listInterpolationKey));
                    listArgs.remove(listInterpolationKey);
                } else {
                    result.add(interpolated);
                }
            }

            return result;
        }
    });
}