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.sunchenbin.store.feilong.core.util.MapUtil.java

/**
 *  sub map(??keys).//from   www  .j  a v  a 2  s . c o m
 *
 * @param <K>
 *            the key type
 * @param <T>
 *            the generic type
 * @param map
 *            the map
 * @param excludeKeys
 *            the keys
 * @return the sub map<br>
 *         if (Validator.isNullOrEmpty(keys)) map<br>
 * @since 1.0.9
 */
public static <K, T> Map<K, T> getSubMapExcludeKeys(Map<K, T> map, K[] excludeKeys) {
    if (Validator.isNullOrEmpty(map)) {
        throw new NullPointerException("map can't be null/empty!");
    }
    if (Validator.isNullOrEmpty(excludeKeys)) {
        return map;
    }

    Map<K, T> returnMap = new HashMap<K, T>(map);

    for (K key : excludeKeys) {
        if (map.containsKey(key)) {
            returnMap.remove(key);
        } else {
            LOGGER.warn("map don't contains key:[{}]", key);
        }
    }
    return returnMap;
}

From source file:edu.kit.dama.staging.util.TransferClientPropertiesUtils.java

/**
 * Helper method to convert a map of key-value-pairs to a
 * TransferClientProperties object.//from   w  w  w .  j av  a2s .  c  o  m
 *
 * @param pProperties a key-value map.
 *
 * @return A TransferClientProperties object reflecting pProperties.
 */
public static TransferClientProperties mapToProperties(Map<String, String> pProperties) {
    TransferClientProperties result = new TransferClientProperties();

    //transfer standard properties and remove them from the map
    String v = pProperties.get(STAGING_ACCESS_POINT_KEY);
    if (v != null) {
        result.setStagingAccessPointId(v);
        pProperties.remove(v);
    }
    v = pProperties.get(STAGING_URL_KEY);
    if (v != null) {
        result.setStagingUrl(v);
        pProperties.remove(v);
    }
    v = pProperties.get(CLIENT_ACCESS_URL_KEY);
    if (v != null) {
        result.setTransferClientUrl(v);
        pProperties.remove(v);
    }

    v = pProperties.get(MAIL_NOTIFICATION_KEY);
    if (v != null) {
        result.setSendMailNotification(Boolean.parseBoolean(v));
        pProperties.remove(v);
    }
    v = pProperties.get(MAIL_RECEIVER_KEY);
    if (v != null) {
        result.setReceiverMail(v);
        pProperties.remove(v);
    }
    v = pProperties.get(API_KEY_KEY);
    if (v != null) {
        result.setApiKey(v);
        pProperties.remove(v);
    }
    v = pProperties.get(API_SECRET_KEY);
    if (v != null) {
        result.setApiSecret(v);
        pProperties.remove(v);
    }

    v = pProperties.get(PROCESSOR_KEY);
    if (v != null) {
        //extract all staging processors by their ID
        String[] processorIds = StringUtils.split(v, ";");

        for (String id : processorIds) {
            if (id != null && id.length() > 3) {
                //get processor by id
                StagingProcessor processor = StagingConfigurationPersistence
                        .getSingleton(StagingConfigurationManager.getSingleton().getStagingPersistenceUnit())
                        .findStagingProcessorById(id.trim());
                if (processor != null) {
                    //add processor
                    result.addProcessor(processor);
                }
            }
        }
        pProperties.remove(v);
    }

    //transfer custom properties
    Set<Entry<String, String>> entries = pProperties.entrySet();

    for (Entry<String, String> entry : entries) {
        result.addCustomProperty(entry.getKey(), entry.getValue());
    }

    return result;
}

From source file:gr.omadak.leviathan.asp.AspParser.java

private static XmlASPClass getInstrictObject(String name, Map map) {
    XmlASPClass clazz = (XmlASPClass) map.remove(name.toUpperCase());
    if (clazz == null) {
        LOG.error("Instrict object " + name + " was not loaded");
    }//from  w ww.j  a v a2 s  .c  o m
    return clazz;
}

From source file:com.acc.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(//from   w ww  . jav a  2  s  .c  o m
            new ClassPathResource("/bncfulfilmentprocess/test/bncfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;
    processService = null;
}

From source file:com.exxonmobile.ace.hybris.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
            "/exxonmobilfulfilmentprocess/test/exxonmobilfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;/*  ww w .  j a v a  2 s. c o m*/
    processService = null;
}

From source file:com.mitre.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
            "/mitrefulfilmentprocess/test/mitrefulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;//from   w w  w  .  java  2  s . co m
    processService = null;
}

From source file:org.vinmonopolet.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
            "/vinmonopoletfulfilmentprocess/test/vinmonopoletfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;/*from   ww  w. jav  a  2s . c  o m*/
    processService = null;
}

From source file:org.training.fulfilmentprocess.test.ProcessFlowTest.java

@AfterClass
public static void removeProcessDefinitions() {
    LOG.debug("cleanup...");

    final ApplicationContext appCtx = Registry.getApplicationContext();

    assertTrue("Application context of type " + appCtx.getClass() + " is not a subclass of "
            + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext);

    final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx;
    final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    assertTrue("Bean Factory of type " + beanFactory.getClass() + " is not of type "
            + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry);
    final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory);
    xmlReader.loadBeanDefinitions(new ClassPathResource(
            "/trainingfulfilmentprocess/test/trainingfulfilmentprocess-spring-testcleanup.xml"));

    //cleanup command factory
    final Map<String, CommandFactory> commandFactoryList = applicationContext
            .getBeansOfType(CommandFactory.class);
    commandFactoryList.remove("mockupCommandFactory");
    final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx
            .getBean(DefaultCommandFactoryRegistryImpl.class);
    commandFactoryReg.setCommandFactoryList(commandFactoryList.values());

    processService.setTaskService(appCtx.getBean(DefaultTaskService.class));
    definitonFactory = null;/*www .j  av  a 2 s .c  om*/
    processService = null;
}

From source file:com.opengamma.component.tool.ToolContextUtils.java

private static ComponentInfo getComponentInfo(ComponentServer componentServer, List<String> preferenceList,
        Class<?> type) {//  www.  j  a  v a  2  s .c  o m
    Map<String, ComponentInfo> infos = componentServer.getComponentInfoMap(type);
    if (preferenceList != null) {
        for (String preference : preferenceList) {
            ComponentInfo componentInfo = infos.get(preference);
            if (componentInfo != null) {
                return componentInfo;
            }
        }
    }
    infos.remove("test");
    if (infos.size() == 0) {
        return null;
    }
    if (infos.size() > 1) {
        s_logger.warn("Multiple remote components match: " + type.getSimpleName() + "::" + infos.keySet());
        return null;
    }
    return infos.values().iterator().next();
}

From source file:Main.java

public static Map<? extends Object, ? extends Double> merge(Map<? extends Object, ? extends Double> map1,
        Map<? extends Object, ? extends Double> map2) {
    Map<Object, Double> result = new HashMap<Object, Double>();

    Map<? extends Object, ? extends Double> biggerMap = map1.size() > map2.size() ? map1 : map2;
    Map<? extends Object, ? extends Double> smallerMap = map1.size() > map2.size() ? map2 : map1;

    for (Entry<? extends Object, ? extends Double> entry : smallerMap.entrySet()) {
        Object key = entry.getKey();
        Double value = entry.getValue();

        Double value2 = (Double) getValue(biggerMap, key, Double.class);
        value2 += value;/*  w  ww.j a  v  a 2 s  .  com*/
        result.put(key, value2);
        biggerMap.remove(key);
    }
    result.putAll(biggerMap);
    return sortByValueDesc(result);
}