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.hortonworks.streamline.streams.catalog.TopologyComponent.java

@Override
public Map<String, Object> toMap() {
    Map<String, Object> map = super.toMap();
    map.remove(CONFIG);
    try {//from ww w  .  j a v a 2s  . c o m
        map.put(CONFIG_DATA, getConfigData());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return map;
}

From source file:org.kuali.maven.plugins.graph.processor.StyleProcessor.java

protected List<String> getStyleProperties() {
    try {/*from  w  w w  .  j a  va 2  s.  c  o  m*/
        @SuppressWarnings("unchecked")
        Map<String, ?> map = BeanUtils.describe(Style.DEFAULT_STYLE);
        map.remove("class");
        return new ArrayList<String>(map.keySet());
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:com.github.dactiv.fear.service.test.config.DictionaryCategoryServiceTest.java

@Test
public void testSaveDictionaryCategory() {
    Map<String, Object> dictionaryCategory = configService.getDictionaryCategory(1);

    dictionaryCategory.remove("id");
    dictionaryCategory.put("name", "?");
    dictionaryCategory.put("code", "nationality");

    int before = countRowsInTable("tb_dictionary_category");

    configService.saveDictionaryCategory(dictionaryCategory);

    int after = countRowsInTable("tb_dictionary_category");

    assertEquals(before + 1, after);/*from w  ww. j  ava  2 s  .c  o m*/

    dictionaryCategory.put("name", "?");
    dictionaryCategory.put("code", "native-place");

    before = countRowsInTable("tb_dictionary_category");

    configService.saveDictionaryCategory(dictionaryCategory);

    after = countRowsInTable("tb_dictionary_category");

    assertEquals(before, after);

    Integer id = Casts.cast(dictionaryCategory.get("id"), Integer.class);
    configService.getDictionaryCategory(id);

    assertEquals(dictionaryCategory.get("name"), "?");
    assertEquals(dictionaryCategory.get("code"), "native-place");
}

From source file:au.org.ala.layers.dao.FieldDAOImpl.java

@Override
public synchronized void addField(Field field) {
    logger.info("Add new field for " + field.getName());

    Map<String, Object> parameters = field.toMap();
    parameters.remove("id");

    //calc new fieldId
    String idPrefix = "Contextual"
            .equalsIgnoreCase(layerDao.getLayerById(Integer.parseInt(field.getSpid())).getType()) ? "cl" : "el";

    //test for default id
    String newId = getFieldById(idPrefix + field.getSpid()) == null ? idPrefix + field.getSpid() : null;
    if (newId == null) {
        //calculate next field Id using general form: prefix (n x 1000 + layerId)
        String idEnd = field.getSpid();
        while (idEnd.length() < 3) {
            idEnd = "0" + idEnd;
        }//from  w  w  w . jav  a  2  s. c  o  m
        int maxNFound = 0;
        for (Field f : getFields(false)) {
            if (f.getId().startsWith(idPrefix) && f.getId().endsWith(idEnd)) {
                if (f.getId().length() - idEnd.length() > 2) {
                    int n = Integer.parseInt(f.getId().substring(2, f.getId().length() - idEnd.length()));
                    if (n > maxNFound) {
                        maxNFound = n;
                    }
                }
            }
        }

        newId = idPrefix + (maxNFound + 1) + idEnd;
    }
    parameters.put("id", newId);
    //fix for field 'desc' and 'intersect'
    if (parameters.containsKey("desc")) {
        parameters.put("\"desc\"", parameters.get("desc"));
        parameters.remove("desc");
    }
    if (parameters.containsKey("intersect")) {
        parameters.put("\"intersect\"", parameters.get("intersect"));
        parameters.remove("intersect");
    }

    insertField.execute(parameters);

    field.setId(newId);
}

From source file:com.chiorichan.util.WebUtils.java

@SuppressWarnings("unchecked")
public static String createTable(Map<Object, Object> tableData, List<String> headerArray, String tableId,
        String altTableClass) {/*  w  w  w.j a v  a2 s  .  co m*/
    if (tableId == null)
        tableId = "";

    if (tableData == null)
        return "";

    if (altTableClass == null || altTableClass.isEmpty())
        altTableClass = "altrowstable";

    StringBuilder sb = new StringBuilder();
    int x = 0;
    sb.append("<table id=\"" + tableId + "\" class=\"" + altTableClass + "\">\n");

    if (headerArray != null) {
        sb.append("<tr>\n");
        for (String col : headerArray) {
            sb.append("<th>" + col + "</th>\n");
        }
        sb.append("</tr>\n");
    }

    int colLength = (headerArray != null) ? headerArray.size() : tableData.size();
    for (Object row : tableData.values()) {
        if (row instanceof Map) {
            colLength = Math.max(((Map<String, Object>) row).size(), colLength);
        }
    }

    for (Object row : tableData.values()) {
        String clss = (x % 2 == 0) ? "evenrowcolor" : "oddrowcolor";
        x++;

        if (row instanceof Map || row instanceof List) {
            Map<Object, Object> map = Maps.newLinkedHashMap();

            if (row instanceof Map)
                map = (Map<Object, Object>) row;
            else {
                int y = 0;
                for (Object o : (List<Object>) row) {
                    map.put(Integer.toString(y), o);
                    y++;
                }
            }

            sb.append("<tr");

            for (Entry<Object, Object> e : map.entrySet())
                try {
                    if (ObjectUtil.castToStringWithException(e.getKey()).startsWith(":")) {
                        map.remove(e.getKey());
                        sb.append(" " + ObjectUtil.castToStringWithException(e.getKey()).substring(1) + "=\""
                                + ObjectUtil.castToStringWithException(e.getValue()) + "\"");
                    }
                } catch (ClassCastException ex) {
                    ex.printStackTrace();
                }

            sb.append(" class=\"" + clss + "\">\n");

            if (map.size() == 1) {
                sb.append("<td style=\"text-align: center; font-weight: bold;\" class=\"\" colspan=\""
                        + colLength + "\">" + map.get(0) + "</td>\n");
            } else {
                int cc = 0;
                for (Object col : map.values()) {
                    if (col != null) {
                        String subclass = (col instanceof String && ((String) col).isEmpty()) ? " emptyCol"
                                : "";
                        sb.append("<td id=\"col_" + cc + "\" class=\"" + subclass + "\">" + col + "</td>\n");
                        cc++;
                    }
                }
            }
            sb.append("</tr>\n");
        } else if (row instanceof String) {
            sb.append("<tr><td class=\"" + clss + "\" colspan=\"" + colLength + "\"><b><center>"
                    + ((String) row) + "</b></center></td></tr>\n");
        } else {
            sb.append("<tr><td class=\"" + clss + "\" colspan=\"" + colLength + "\"><b><center>"
                    + row.toString() + "</b></center></td></tr>\n");
        }
    }
    sb.append("</table>\n");

    return sb.toString();
}

From source file:com.mile24.springframework.data.neo4j.context.support.CypherMessageSource.java

public void initialize() {

    Assert.notNull(neo4jOperations, "neo4jOperations must not be null");

    if (!initialized) {

        initialized = true;/*from   w w w .  j  a  va 2s. com*/

        Map<String, Object> parameters = new HashMap<String, Object>();
        Result results = neo4jOperations.query(queryCypher, parameters);

        Iterable<Map<String, Object>> resultNodes = results.queryResults();

        for (Map<String, Object> nodeMap : resultNodes) {

            String code = nodeMap.remove("code").toString();

            Set<String> propertyKeys = nodeMap.keySet();

            for (String propertyKey : propertyKeys) {

                String message = nodeMap.get(propertyKey).toString();

                Locale locale = LocaleUtils.toLocale(propertyKey);
                addMessage(code, locale, message);

            }

        }

    }

}

From source file:com.feilong.core.util.MapUtil.java

/**
 *  <code>map</code>  <code>keys</code>.
 * //from  w w w.ja  va  2  s .com
 * <h3>?</h3>
 * 
 * <blockquote>
 * <p>
 * ??<code>map</code>, <code>keys</code>,<br>
 *  <code>map</code>?key, {@link Map#remove(Object)},<br>
 * ??,warn
 * </p>
 * </blockquote>
 * 
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * 
 * Map{@code <String, String>} map = newLinkedHashMap(3);
 * 
 * map.put("name", "feilong");
 * map.put("age", "18");
 * map.put("country", "china");
 * 
 * LOGGER.debug(JsonUtil.format(MapUtil.removeKeys(map, "country")));
 * 
 * </pre>
 * 
 * <b>:</b>
 * 
 * <pre class="code">
 * {
 * "name": "feilong",
 * "age": "18"
 * }
 * 
 * </pre>
 * 
 * </blockquote>
 *
 * @param <K>
 *            the key type
 * @param <V>
 *            the value type
 * @param map
 *            the map
 * @param keys
 *            the keys
 * @return  <code>map</code> null, {@link NullPointerException}<br>
 * @since 1.6.3
 */
@SafeVarargs
public static <K, V> Map<K, V> removeKeys(Map<K, V> map, K... keys) {
    Validate.notNull(map, "map can't be null!");
    for (K key : keys) {
        if (map.containsKey(key)) {
            map.remove(key);
        } else {
            LOGGER.warn("map:[{}] don't contains key:[{}]", JsonUtil.format(map.keySet(), 0, 0), key);
        }
    }
    return map;
}

From source file:com.haulmont.cuba.security.idp.IdpServiceBean.java

@Override
public IdpSession removeSessionAttribute(String sessionId, String name) {
    IdpSession session = sessionStore.getSession(sessionId);
    if (session != null) {
        Map<String, Object> attributes = session.getAttributes();
        if (attributes != null) {
            attributes.remove(name);
        }/*from  w w  w  .j  a v a2 s  .  c o  m*/
        sessionStore.propagate(session.getId());
    }
    return session;
}

From source file:com.linuxbox.enkive.statistics.consolidation.HourConsolidator.java

@SuppressWarnings("unchecked")
private List<Map<String, Object>> getStatTypeData(String gathererName, String type) {
    StatsQuery query = new MongoStatsQuery(gathererName, filterType, type, startDate, endDate);
    StatsFilter filter = new StatsTypeFilter(type);
    List<Map<String, Object>> result = createListOfMaps();
    Set<Map<String, Object>> queryData = client.queryStatistics(query, filter);
    for (Map<String, Object> statsMap : queryData) {
        statsMap.remove("_id");// WARNING mongo specific pollution

        if (statsMap != null && !statsMap.isEmpty()) {
            result.add(new HashMap<String, Object>((Map<String, Object>) statsMap.get(type)));
        }//  w w  w .  ja  va  2s  .  co  m
    }
    return result;
}

From source file:net.ontopia.topicmaps.utils.TopicMapSynchronizer.java

private static void update(TopicNameIF tbn, TopicNameIF sbn, DeciderIF<TMObjectIF> tfilter) {
    TopicMapIF target = tbn.getTopicMap();
    TopicMapBuilderIF builder = target.getBuilder();

    // build map of existing variants
    Map<String, VariantNameIF> origs = new HashMap<String, VariantNameIF>();
    Iterator<VariantNameIF> it = tbn.getVariants().iterator();
    while (it.hasNext()) {
        VariantNameIF vn = it.next();/*from  w w w  .  jav a  2  s  . c  o  m*/
        if (tfilter.ok(vn))
            origs.put(KeyGenerator.makeVariantKey(vn), vn);
    }

    // walk through new variants
    it = sbn.getVariants().iterator();
    while (it.hasNext()) {
        VariantNameIF svn = it.next();
        Collection<TopicIF> tscope = translateScope(target, svn.getScope());
        String key = KeyGenerator.makeScopeKey(tscope) + KeyGenerator.makeDataKey(svn);
        if (origs.containsKey(key))
            origs.remove(key); // we've got it already; remember not to delete it
        else {
            // this is a new variant; add it
            VariantNameIF tvn = builder.makeVariantName(tbn, svn.getValue(), svn.getDataType());
            addScope(tvn, tscope);
        }
    }

    // delete old variants not in source
    it = origs.values().iterator();
    while (it.hasNext())
        it.next().remove();
}