Java Map Remove removeValue(Map subject, String property, Map value, boolean propertyIsArray)

Here you can find the source of removeValue(Map subject, String property, Map value, boolean propertyIsArray)

Description

remove Value

License

Open Source License

Declaration

static void removeValue(Map<String, Object> subject, String property, Map<String, Object> value,
            boolean propertyIsArray) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;
import java.util.Map;

public class Main {
    /**/*from ww  w .j  a v  a2 s  .co m*/
     * Removes a value from a subject.
     *
     * @param subject
     *            the subject.
     * @param property
     *            the property that relates the value to the subject.
     * @param value
     *            the value to remove.
     * @param [options] the options to use: [propertyIsArray] true if the
     *        property is always an array, false if not (default: false).
     */
    static void removeValue(Map<String, Object> subject, String property, Map<String, Object> value) {
        removeValue(subject, property, value, false);
    }

    static void removeValue(Map<String, Object> subject, String property, Map<String, Object> value,
            boolean propertyIsArray) {
        // filter out value
        final List<Object> values = new ArrayList<Object>();
        if (subject.get(property) instanceof List) {
            for (final Object e : ((List) subject.get(property))) {
                if (!(value.equals(e))) {
                    values.add(value);
                }
            }
        } else {
            if (!value.equals(subject.get(property))) {
                values.add(subject.get(property));
            }
        }

        if (values.size() == 0) {
            subject.remove(property);
        } else if (values.size() == 1 && !propertyIsArray) {
            subject.put(property, values.get(0));
        } else {
            subject.put(property, values);
        }
    }
}

Related

  1. removeParentBeans(Map parentBeans, Map beans)
  2. removePrivateColumns( Map contentValues)
  3. removeRownum(List> rows)
  4. removeTrailingNumber(Map names)
  5. removeValue(final Map map, final Object key, final Object value)
  6. removeValueFromAll(final Map map, final Object value)
  7. removeValueList(final Map> map, final K key, final V value)
  8. removeValuesFromMap(Map map, Collection removed)
  9. removeVersionSelector( Map selector)