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.netsteadfast.greenstep.base.model.SqlGenerateUtil.java

public static Map<String, Object> getUpdateByPK(boolean allField, Object entityObject) throws Exception {
    String tableName = getTableName(entityObject);
    String pk = getPKname(entityObject);
    Object value = getPKvalue(entityObject);
    if ("".equals(tableName.trim()) || null == pk || "".equals(pk) || null == value) {
        throw new java.lang.IllegalArgumentException(NOT_ENTITY_BEAN);
    }/*ww w  .  j a v a 2  s  . c  om*/
    Map<String, Object> fieldMap = getField(entityObject);
    if (!allField) {
        fieldMap = getNewFieldMap(fieldMap);
    }
    fieldMap.remove(pk);
    if (!checkValueParams(fieldMap)) {
        throw new java.lang.IllegalArgumentException(NOT_ENTITY_BEAN);
    }
    Map<String, Object> queryMap = new HashMap<String, Object>();
    int field = 0;
    StringBuilder sql = new StringBuilder();
    Object params[] = new Object[fieldMap.size() + 1];
    sql.append(" update ").append(tableName).append(" set ");
    for (Map.Entry<String, Object> entry : fieldMap.entrySet()) {
        params[field] = entry.getValue();
        field++;
        sql.append(" ").append(entry.getKey()).append("=?");
        if (field < fieldMap.size()) {
            sql.append(", ");
        }
    }
    sql.append(" where ").append(pk).append("=?");
    params[field] = value;
    queryMap.put(RETURN_SQL, sql.toString());
    queryMap.put(RETURN_PARAMS, params);
    return queryMap;
}

From source file:net.sourceforge.jaulp.lang.ObjectUtils.java

/**
 * Compares the given object over the given property.
 * //from   w w  w. j  a  va  2  s.c om
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @param property
 *            the property
 * @return the int
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws NoSuchMethodException
 *             the no such method exception
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static int compareTo(Object sourceOjbect, Object objectToCompare, String property)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<?, ?> beanDescription = BeanUtils.describe(sourceOjbect);
    beanDescription.remove("class");
    Map<?, ?> clonedBeanDescription = BeanUtils.describe(objectToCompare);
    clonedBeanDescription.remove("class");
    Object sourceAttribute = beanDescription.get(property);
    Object changedAttribute = clonedBeanDescription.get(property);
    if (sourceAttribute == null && changedAttribute == null) {
        return 0;
    }
    if (sourceAttribute != null && changedAttribute == null) {
        return 1;
    } else if (sourceAttribute == null && changedAttribute != null) {
        return -1;
    }
    return new BeanComparator(property).compare(sourceOjbect, objectToCompare);
}

From source file:gemlite.core.common.DateUtil.java

private static Date correctDate(String dateStr, String format) {
    Map<String, Locale> set = new HashMap<String, Locale>();
    set.put(US_MMM_dd_yyyy_hhmmssSSSaa, Locale.US);
    set.put(yyyyMMdd_HHmmssSSS, Locale.US);
    set.put(US_EEE_MMM_dd_hhmmsszyyyy, Locale.US);
    set.put(yyyyMMdd_HHmmssSSS, Locale.getDefault());
    set.put(yyyy_MM_dd_HHmmss_SSS, Locale.getDefault());
    set.remove(format);
    for (Entry<String, Locale> es : set.entrySet()) {
        SimpleDateFormat sdf = new SimpleDateFormat(es.getKey(), es.getValue());

        try {//w ww .j  a  va2  s  . c  om
            Date s_date = sdf.parse(dateStr);
            LogUtil.getAppLog().error("DateUtil.correctDate work.DateStr:" + dateStr + " fmt:" + es.getKey());
            return s_date;
        } catch (ParseException e) {
            LogUtil.getAppLog().error("DateUtil.correctDate errr.DateStr:" + dateStr + " fmt:" + es.getKey());
        }
    }
    return null;
}

From source file:com.discovery.darchrow.util.MapUtil.java

/**
 *  sub map(??keys).// www.j a  v a2  s. com
 *
 * @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("the map is null or 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:Main.java

public static <T> boolean hasCycle(Collection<T> vertices, Function<T, Collection<T>> neighborExtractor) {
    Map<T, Collection<T>> parents = vertices.stream().collect(toMap(identity(), v -> new ArrayList<T>()));
    vertices.forEach(//  w  w  w  .  java2  s. c  o m
            v -> nullSafeCollection(neighborExtractor.apply(v)).forEach(child -> parents.get(child).add(v)));

    Set<T> roots = vertices.stream().filter(v -> parents.get(v).isEmpty()).collect(Collectors.toSet());

    while (!roots.isEmpty()) {
        T root = roots.iterator().next();
        roots.remove(root);
        parents.remove(root);

        nullSafeCollection(neighborExtractor.apply(root)).forEach(child -> {
            parents.get(child).remove(root);
            if (parents.get(child).isEmpty()) {
                roots.add(child);
            }
        });

    }

    return !parents.isEmpty();
}

From source file:de.alpharogroup.lang.ObjectExtensions.java

/**
 * Gets the compare to result.//from  w  w w  .  ja  v  a2  s. c  o m
 *
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return the compare to result
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws NoSuchMethodException
 *             the no such method exception
 */
@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<String, Integer>();
    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.ObjectExtensions.java

/**
 * Gets the changed data./*from   w w w.j  av a 2  s  . co m*/
 *
 * @param sourceOjbect
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return the changed data
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws NoSuchMethodException
 *             the no such method exception
 */
@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<ChangedAttributeResult>();
    for (final Object key : beanDescription.keySet()) {
        if (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;
}

From source file:de.alpharogroup.lang.ObjectExtensions.java

/**
 * Compares the given two objects and gets the changed data.
 *
 * @param sourceOjbect//w  ww  .j  a  v a2 s.c  o  m
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @return the changed data
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws NoSuchMethodException
 *             the no such method exception
 */
@SuppressWarnings("rawtypes")
public static Map<Object, ChangedAttributeResult> getChangedDataMap(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<Object, ChangedAttributeResult> changedData = new HashMap<Object, ChangedAttributeResult>();
    for (final Object key : beanDescription.keySet()) {
        final Object sourceAttribute = beanDescription.get(key);
        final Object changedAttribute = clonedBeanDescription.get(key);
        if (compareTo(sourceOjbect, objectToCompare, key.toString()) != 0) {
            changedData.put(key, new ChangedAttributeResult(key, sourceAttribute, changedAttribute));
        }
    }
    return changedData;
}

From source file:io.cloudslang.content.database.utils.SQLUtils.java

@NotNull
public static String getStrColumns(@NotNull final GlobalSessionObject<Map<String, Object>> globalSessionObject,
        @NotNull final String strKeyCol) {
    final Map<String, Object> globalMap = globalSessionObject.get();
    if (globalMap.containsKey(strKeyCol) && globalMap.get(strKeyCol) instanceof String) {
        try {//ww  w.  j  a v  a  2s .  c  om
            return (String) globalMap.get(strKeyCol);
        } catch (Exception e) {
            globalMap.remove(strKeyCol);
            globalSessionObject.setResource(new SQLSessionResource(globalMap));
        }
    }
    return EMPTY;

}

From source file:de.alpharogroup.lang.ObjectExtensions.java

/**
 * Compares the given object over the given property.
 *
 * @param sourceOjbect//from   w  w  w  .  j ava 2  s  . co m
 *            the source ojbect
 * @param objectToCompare
 *            the object to compare
 * @param property
 *            the property
 * @return the int
 * @throws IllegalAccessException
 *             the illegal access exception
 * @throws InvocationTargetException
 *             the invocation target exception
 * @throws NoSuchMethodException
 *             the no such method exception
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static int compareTo(final Object sourceOjbect, final Object objectToCompare, final String property)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    final Map<?, ?> beanDescription = BeanUtils.describe(sourceOjbect);
    beanDescription.remove("class");
    final Map<?, ?> clonedBeanDescription = BeanUtils.describe(objectToCompare);
    clonedBeanDescription.remove("class");
    final Object sourceAttribute = beanDescription.get(property);
    final Object changedAttribute = clonedBeanDescription.get(property);
    if (sourceAttribute == null && changedAttribute == null) {
        return 0;
    }
    if (sourceAttribute != null && changedAttribute == null) {
        return 1;
    } else if (sourceAttribute == null && changedAttribute != null) {
        return -1;
    }
    return new BeanComparator(property).compare(sourceOjbect, objectToCompare);
}