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:Main.java

/**
 * Increase counter.get(key) by increase.
 * If value decrease to zero, it is removed from map.
 *///from w  ww. ja v  a  2  s .  c  om
public static <K> void increaseMapCounter(Map<K, Integer> counter, K key, int increase) {
    if (!counter.containsKey(key)) {
        counter.put(key, 0);
    }
    counter.put(key, counter.get(key) + increase);
    if (counter.get(key) == 0) {
        counter.remove(key);
    }
}

From source file:io.brooklyn.camp.spi.pdp.Artifact.java

@SuppressWarnings("unchecked")
public static Artifact of(Map<String, Object> artifact) {
    Map<String, Object> fields = MutableMap.copyOf(artifact);

    Artifact result = new Artifact();
    result.name = (String) fields.remove("name");
    result.description = (String) fields.remove("description");
    result.artifactType = (String) (String) Yamls.removeMultinameAttribute(fields, "artifactType", "type");

    result.content = ArtifactContent.of(fields.remove("content"));

    result.requirements = new ArrayList<ArtifactRequirement>();
    Object reqs = fields.remove("requirements");
    if (reqs instanceof Iterable) {
        for (Object req : (Iterable<Object>) reqs) {
            if (req instanceof Map) {
                result.requirements.add(ArtifactRequirement.of((Map<String, Object>) req));
            } else {
                throw new IllegalArgumentException("requirement should be a map, not " + req.getClass());
            }/*w  ww. j ava2s  .c  o  m*/
        }
    } else if (reqs != null) {
        // TODO "map" short form
        throw new IllegalArgumentException("artifacts body should be iterable, not " + reqs.getClass());
    }

    result.customAttributes = fields;

    return result;
}

From source file:Main.java

/**
 * Delete all the keys with null values of the map received
 * @param map Map<String, Object> map to clean
 *///  w  w w.  ja v a  2  s.c o m
public static void cleanMapNullValues(Map<String, Object> map) {

    //check map is null
    if (map == null) {
        return;
    }

    for (String key : new ArrayList<>(map.keySet())) {
        if (map.get(key) == null) {
            map.remove(key);
        }
    }

}

From source file:edu.harvard.iq.dvn.core.web.StudyListing.java

public static void clearStudyListingMap(Map sessionMap) {
    sessionMap.remove("studyListings");
}

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static void setLongProperty(Map<String, JsonNode> properties, String name, Long value) {
    if (value == null) {
        properties.remove(name);
    } else {//from   ww w  .  j a  va 2s.  c  o  m
        properties.put(name, JsonNodeFactory.instance.numberNode(value));
    }
}

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static void setUUIDProperty(Map<String, JsonNode> properties, String name, UUID value) {
    if (value == null) {
        properties.remove(name);
    } else {//from   w  ww  .  j  a  va2s  .  c  om
        properties.put(name, JsonNodeFactory.instance.textNode(value.toString()));
    }
}

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static void setFloatProperty(Map<String, JsonNode> properties, String name, Float value) {
    if (value == null) {
        properties.remove(name);
    } else {/* w w  w .j  av  a2 s. c  om*/
        properties.put(name, JsonNodeFactory.instance.numberNode(value));
    }
}

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static void setStringProperty(Map<String, JsonNode> properties, String name, String value) {
    if (value == null) {
        properties.remove(name);
    } else {//w ww .j  a v a 2 s  . c  om
        properties.put(name, JsonNodeFactory.instance.textNode(value));
    }
}

From source file:org.apache.usergrid.android.sdk.utils.JsonUtils.java

public static void setObjectProperty(Map<String, JsonNode> properties, String name, Object value) {
    if (value == null) {
        properties.remove(name);
    } else {//w ww .jav a2  s.  com
        properties.put(name, JsonNodeFactory.instance.textNode(value.toString()));
    }
}

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

/**
 * Gets the changed data./*from  ww w  . ja va 2 s.c o m*/
 *
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return the changed data
 * @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 this {@code Method} object is enforcing Java language access control
 *             and the underlying method is inaccessible.
 */
@SuppressWarnings("rawtypes")
public static List<ChangedAttributeResult> getChangedData(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 List<ChangedAttributeResult> changedData = new ArrayList<>();
    for (final Object key : beanDescription.keySet()) {
        if (CompareObjectExtensions.compareTo(sourceOjbect, objectToCompare, key.toString()) != 0) {
            final Object sourceAttribute = beanDescription.get(key);
            final Object changedAttribute = clonedBeanDescription.get(key);
            changedData.add(new ChangedAttributeResult(key, sourceAttribute, changedAttribute));
        }
    }
    return changedData;
}