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.microsoft.alm.plugin.idea.common.utils.EventContextHelper.java

public static void setRepository(final Map<String, Object> eventContext, final GitRepository repository) {
    ArgumentHelper.checkNotNull(eventContext, "eventContext");
    if (repository == null) {
        eventContext.remove(EventContextHelper.CONTEXT_REPOSITORY);
    } else {/*from   w w  w. j a v a2s. c  o  m*/
        eventContext.put(EventContextHelper.CONTEXT_REPOSITORY, repository);
    }
}

From source file:de.alpharogroup.lang.object.CompareObjectExtensions.java

/**
 * Compares the given two objects./*from w w w  .ja va  2s .  c om*/
 *
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return true, if successful otherwise false
 * @throws IllegalAccessException
 *             Thrown if this {@code Method} object is enforcing Java language access control
 *             and the underlying method is inaccessible.
 * @throws InvocationTargetException
 *             Thrown if the property accessor method throws an exception
 * @throws NoSuchMethodException
 *             Thrown if a matching method is not found or if the name is "&lt;init&gt;"or
 *             "&lt;clinit&gt;".
 */
@SuppressWarnings("rawtypes")
public static boolean compare(final Object sourceOjbect, final Object objectToCompare)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (sourceOjbect == null || objectToCompare == null
            || !sourceOjbect.getClass().equals(objectToCompare.getClass())) {
        throw new IllegalArgumentException("Object should not be null and be the same type.");
    }
    final Map beanDescription = BeanUtils.describe(sourceOjbect);
    beanDescription.remove("class");
    final Map clonedBeanDescription = BeanUtils.describe(objectToCompare);
    clonedBeanDescription.remove("class");
    for (final Object key : beanDescription.keySet()) {
        if (compareTo(sourceOjbect, objectToCompare, key.toString()) != 0) {
            return false;
        }
    }
    return true;
}

From source file:de.alpharogroup.lang.object.CompareObjectExtensions.java

/**
 * Gets the compare to result./*from w  w w . ja  va 2s  . c o m*/
 *
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return the compare to result
 * @throws IllegalAccessException
 *             Thrown if this {@code Method} object is enforcing Java language access control
 *             and the underlying method is inaccessible.
 * @throws InvocationTargetException
 *             Thrown if the property accessor method throws an exception
 * @throws NoSuchMethodException
 *             Thrown if a matching method is not found or if the name is "&lt;init&gt;"or
 *             "&lt;clinit&gt;".
 */
@SuppressWarnings("rawtypes")
public static Map<String, Integer> getCompareToResult(final Object sourceOjbect, final Object objectToCompare)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (sourceOjbect == null || objectToCompare == null
            || !sourceOjbect.getClass().equals(objectToCompare.getClass())) {
        throw new IllegalArgumentException("Object should not be null and be the same type.");
    }
    final Map beanDescription = BeanUtils.describe(sourceOjbect);
    beanDescription.remove("class");
    final Map clonedBeanDescription = BeanUtils.describe(objectToCompare);
    clonedBeanDescription.remove("class");
    final Map<String, Integer> compareResult = new HashMap<>();
    for (final Object key : beanDescription.keySet()) {
        compareResult.put(key.toString(),
                Integer.valueOf(compareTo(sourceOjbect, objectToCompare, key.toString())));
    }
    return compareResult;
}

From source file:de.alpharogroup.lang.object.CompareObjectExtensions.java

/**
 * Compares the given two objects and returns the result as {@link int}.
 *
 * @param sourceOjbect/*  ww  w.  j  a  v a 2 s. co m*/
 *            the source object
 * @param objectToCompare
 *            the object to compare
 * @return the resulted int value
 * @throws IllegalAccessException
 *             Thrown if this {@code Method} object is enforcing Java language access control
 *             and the underlying method is inaccessible.
 * @throws InvocationTargetException
 *             Thrown if the property accessor method throws an exception
 * @throws NoSuchMethodException
 *             Thrown if a matching method is not found or if the name is "&lt;init&gt;"or
 *             "&lt;clinit&gt;".
 */
@SuppressWarnings("rawtypes")
public static int compareTo(final Object sourceOjbect, final Object objectToCompare)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (sourceOjbect == null || objectToCompare == null
            || !sourceOjbect.getClass().equals(objectToCompare.getClass())) {
        throw new IllegalArgumentException("Object should not be null and be the same type.");
    }
    final Map beanDescription = BeanUtils.describe(sourceOjbect);
    beanDescription.remove("class");
    final Map clonedBeanDescription = BeanUtils.describe(objectToCompare);
    clonedBeanDescription.remove("class");
    int result = 0;
    for (final Object key : beanDescription.keySet()) {
        result = compareTo(sourceOjbect, objectToCompare, key.toString());
        if (result == 0) {
            continue;
        }
    }
    return result;
}

From source file:ch.sdi.core.TestUtils.java

/**
 * Adds the given key/value pair to the environment into the PropertySourceForTest collection
 *
 * @param aEnv the environment//from  w  w  w . j a v  a 2  s . c  o  m
 * @param aKey the key
 * @param aValue the value
 */
public static void addToEnvironment(ConfigurableEnvironment aEnv, String aKey, String aValue)
        throws SdiException {
    Map<String, Object> map = ConfigUtils.getOrCreatePropertySource(aEnv, TEST_PROPERTY_SOURCE_NAME);

    myLog.debug("setting property " + aKey + " = " + aValue + " into the environment");
    map.remove(aKey);
    map.put(aKey, aValue);
}

From source file:com.github.gaoyangthu.core.hbase.HbaseSynchronizationManager.java

/**
 * Actually remove the value of the resource that is bound for the given key.
 *///from  ww  w  .j a  va 2s  .c o m
private static HTableInterface doUnbindResource(Object actualKey) {
    Map<String, HTableInterface> map = resources.get();
    if (map == null) {
        return null;
    }
    HTableInterface value = map.remove(actualKey);
    // Remove entire ThreadLocal if empty...
    if (map.isEmpty()) {
        resources.remove();
    }

    if (value != null && logger.isTraceEnabled()) {
        logger.trace("Removed value [" + value + "] for key [" + actualKey + "] from thread ["
                + Thread.currentThread().getName() + "]");
    }
    return value;
}

From source file:Main.java

public static <T, U> void mapMergeRemove(Map<T, List<U>> map, Map<T, List<U>> mapToRemove) {
    for (Map.Entry<T, List<U>> e : mapToRemove.entrySet()) {
        if (map.containsKey(e.getKey())) {
            map.get(e.getKey()).removeAll(e.getValue());
            if (map.get(e.getKey()).isEmpty()) {
                map.remove(e.getKey());
            }/*w  ww  .j av a2  s  .c o m*/
        }
    }
}

From source file:ch.sdi.core.TestUtils.java

/**
 * Replaces the value of given key in the environments collection PropertySourceForTest
 *
 * @param aEnv the environment// w w  w.  j a  v  a2s. co  m
 * @param aKey the key
 * @param aValue the new value
 */
public static void replaceInEnvironment(ConfigurableEnvironment aEnv, String aKey, String aValue)
        throws SdiException {
    Map<String, Object> map = ConfigUtils.getOrCreatePropertySource(aEnv, TEST_PROPERTY_SOURCE_NAME);

    myLog.debug("replacing property " + aKey + " in the environment. New value: " + aValue);
    map.remove(aKey);
    map.put(aKey, aValue);
}

From source file:org.apache.usergrid.java.client.utils.JsonUtils.java

public static void setObjectProperty(@NotNull final Map<String, JsonNode> properties,
        @NotNull final String name, @Nullable final ObjectNode value) {
    if (value == null) {
        properties.remove(name);
    } else {//from   w  ww.j ava  2 s . c o  m
        properties.put(name, value);
    }
}

From source file:com.quartercode.eventbridge.test.ExtraAssert.java

public static void assertMapEquals(String message, Map<?, ?> map, Pair<?, ?>... entries) {

    assertTrue(message, map.size() == entries.length);

    Map<?, ?> mapClone = new HashMap<>(map);
    for (Pair<?, ?> expectedEntry : entries) {
        Object actualValue = mapClone.get(expectedEntry.getKey());
        assertTrue(message, Objects.equals(expectedEntry.getValue(), actualValue));

        mapClone.remove(expectedEntry.getKey());
    }//from   w  w  w  .  j  a  v  a2s.c o  m
}