Example usage for java.util LinkedHashMap remove

List of usage examples for java.util LinkedHashMap remove

Introduction

In this page you can find the example usage for java.util LinkedHashMap 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.alibaba.wasp.plan.parser.druid.DruidDDLParser.java

/**
 * Process Alter Table Statement and generate Execute Plan
 * //from w w  w  .j a  v a2 s.com
 */
private void getAlterTablePlan(ParseContext context, MySqlAlterTableStatement sqlAlterTableStatement,
        MetaEventOperation metaEventOperation) throws IOException {
    SQLExprTableSource tableSource = sqlAlterTableStatement.getTableSource();
    String tableName = parseFromClause(tableSource);
    // check if table exists and get Table info
    FTable oldTable = metaEventOperation.checkAndGetTable(tableName, true);

    FTable newTable = FTable.clone(oldTable);

    List<SQLAlterTableItem> items = sqlAlterTableStatement.getItems();
    for (SQLAlterTableItem item : items) {
        if (item instanceof WaspSqlAlterTableChangeColumn) {
            // Alter Table Change Column
            WaspSqlAlterTableChangeColumn changeColumn = (WaspSqlAlterTableChangeColumn) item;

            SQLName columnName = changeColumn.getColumnName();
            LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();
            String oldColumnName = parseName(columnName);
            // Table have this column and this column is not primary key
            metaEventOperation.checkFieldExists(oldTable, oldColumnName);
            metaEventOperation.checkFieldNotInPrimaryKeys(oldTable, oldColumnName);
            // Check column not in a index
            metaEventOperation.checkColumnNotInIndex(oldTable, oldColumnName);

            // Which column(index) to change
            Field field = ftableColumns.get(oldColumnName); // Change this Field
            SQLColumnDefinition newColumnDefinition = changeColumn.getNewColumnDefinition();
            // ColumnFamily specify do not supported.
            if (newColumnDefinition instanceof WaspSqlColumnDefinition) {
                WaspSqlColumnDefinition waspSqlColumnDefinition = (WaspSqlColumnDefinition) newColumnDefinition;
                if (waspSqlColumnDefinition.getColumnFamily() != null) {
                    throw new UnsupportedException("Alter Table, columnFamily specify do not supported.");
                }
            }
            if (newColumnDefinition.getDataType() != null) {
                field.setType(parse(newColumnDefinition.getDataType()));
            }
            String newColumnName = parseName(newColumnDefinition.getName());
            if (!oldColumnName.equals(newColumnName)) { // Change column name
                for (Field f : ftableColumns.values()) {
                    if (f.getName().equalsIgnoreCase(newColumnName)) {
                        throw new UnsupportedException(
                                "Unsupported. Rename one column to a column that already column "
                                        + newColumnName);
                    }
                }
                field.setName(newColumnName);
            }
        } else if (item instanceof MySqlAlterTableAddColumn) {
            // Alter Table Add Column
            MySqlAlterTableAddColumn addColumn = (MySqlAlterTableAddColumn) item;
            List<SQLColumnDefinition> columns = addColumn.getColumns();
            boolean first = addColumn.isFirst();
            SQLName afterColumn = addColumn.getAfterColumn();
            LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();

            List<Field> addFields = convertColumnDefForAlterTable(columns);
            // check Duplicate column name
            metaEventOperation.areLegalTableColumns(ftableColumns.values(), addFields);
            // Do not support add ColumnFamily dynamic right now.
            metaEventOperation.checkColumnFamilyName(ftableColumns.values(), addFields);
            if (first) {
                this.addFieldByPosition(-1, addFields, ftableColumns, newTable);
            } else if (afterColumn != null) {
                int index = getIndex(parseName(afterColumn), ftableColumns);
                this.addFieldByPosition(index, addFields, ftableColumns, newTable);
            } else {
                int index = ftableColumns.size() - 1;
                this.addFieldByPosition(index, addFields, ftableColumns, newTable);
            }
        } else if (item instanceof SQLAlterTableDropColumnItem) {
            // Alter Table Drop Column
            SQLAlterTableDropColumnItem dropColumn = (SQLAlterTableDropColumnItem) item;
            SQLName columnName = dropColumn.getColumnName();
            String cname = parseName(columnName);
            // This column is not primary key
            metaEventOperation.checkFieldNotInPrimaryKeys(oldTable, cname);
            // Check column not in a index, if you want to drop the column you
            // should drop the index first
            metaEventOperation.checkColumnNotInIndex(oldTable, cname);

            LinkedHashMap<String, Field> ftableColumns = newTable.getColumns();
            Field field = ftableColumns.remove(cname);
            if (field == null) {
                throw new UnsupportedException("Unsupported Do not find this column "
                        + SQLUtils.toSQLString(((SQLAlterTableDropColumnItem) item).getColumnName()));
            }
            newTable.setColumns(ftableColumns);
        } else {
            throw new UnsupportedException(SQLUtils.toSQLString(item) + " SQLAlterTableItem Unsupported");
        }
    }

    AlterTablePlan alterTable = new AlterTablePlan(oldTable, newTable);
    context.setPlan(alterTable);
    LOG.debug("AlterTablePlan " + alterTable.toString());
}

From source file:com.liferay.portal.service.impl.UserLocalServiceImpl.java

protected Hits search(long companyId, String firstName, String middleName, String lastName, String fullName,
        String screenName, String emailAddress, String street, String city, String zip, String region,
        String country, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end,
        Sort sort) throws SystemException {

    try {//from   ww  w .  j  a  va  2s .com
        SearchContext searchContext = new SearchContext();

        searchContext.setAndSearch(andSearch);

        Map<String, Serializable> attributes = new HashMap<String, Serializable>();

        attributes.put("city", city);
        attributes.put("country", country);
        attributes.put("emailAddress", emailAddress);
        attributes.put("firstName", firstName);
        attributes.put("fullName", fullName);
        attributes.put("lastName", lastName);
        attributes.put("middleName", middleName);
        attributes.put("params", params);
        attributes.put("region", region);
        attributes.put("screenName", screenName);
        attributes.put("street", street);
        attributes.put("status", status);
        attributes.put("zip", zip);

        searchContext.setAttributes(attributes);

        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);

        if (params != null) {
            String keywords = (String) params.remove("keywords");

            if (Validator.isNotNull(keywords)) {
                searchContext.setKeywords(keywords);
            }
        }

        QueryConfig queryConfig = new QueryConfig();

        queryConfig.setHighlightEnabled(false);
        queryConfig.setScoreEnabled(false);

        searchContext.setQueryConfig(queryConfig);

        searchContext.setSorts(new Sort[] { sort });
        searchContext.setStart(start);

        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

        return indexer.search(searchContext);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.huateng.startup.init.MenuInfoUtil.java

/**
 * ???//from ww  w. j  a va2s .  com
 * @param degree
 */
@SuppressWarnings("unchecked")
public static LinkedHashMap<String, Object> setOperatorMenuWithDegree(String degree, String contextPath,
        Document document) {
    String sql = "select * FROM TBL_ROLE_FUNC_MAP WHERE KEY_ID in ( " + degree + ")";
    ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO");
    List<Object[]> funcMapList = commQueryDAO.findBySQLQuery(sql);
    valueIdRole(funcMapList);
    List<Object> menuLvl1List = allMenuBean.getDataList();
    LinkedHashMap<String, Object> menuIndexMap = new LinkedHashMap<String, Object>();
    String panelStr = "";
    //?????
    for (int i = 0, n = menuLvl1List.size(); i < n; i++) {
        Map<String, Object> menuLvl1Map = (Map<String, Object>) menuLvl1List.get(i);
        LinkedList<Object> menuLvl2List = (LinkedList<Object>) menuLvl1Map.get(Constants.MENU_CHILDREN);
        List<String> menuList = new ArrayList<String>();
        for (int j = 0, m = menuLvl2List.size(); j < m; j++) {
            Map<String, Object> menuLvl2Map = (Map<String, Object>) menuLvl2List.get(j);
            LinkedList<Object> menuLvl3List = (LinkedList<Object>) menuLvl2Map.get(Constants.MENU_CHILDREN);
            for (int k = 0, l = menuLvl3List.size(); k < l; k++) {
                Map<String, Object> menuLvl3Map = (Map<String, Object>) menuLvl3List.get(k);
                for (int a = 0, b = funcMapList.size(); a < b; a++) {
                    if (StringUtils.trim(funcMapList.get(a)[1].toString())
                            .equals(StringUtils.trim(menuLvl3Map.get(Constants.MENU_ID).toString()))) {
                        if (!menuIndexMap.containsKey(menuLvl1Map.get(Constants.MENU_ID).toString())) {
                            Map<String, Object> menuLvl1HashMap = new LinkedHashMap<String, Object>();
                            String menuId = menuLvl1Map.get(Constants.MENU_ID).toString();
                            menuLvl1HashMap.put(Constants.MENU_ID, menuLvl1Map.get(Constants.MENU_ID));
                            menuLvl1HashMap.put(Constants.MENU_TEXT, menuLvl1Map.get(Constants.MENU_TEXT));
                            menuLvl1HashMap.put(Constants.MENU_CLS, menuLvl1Map.get(Constants.MENU_CLS));
                            menuLvl1HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL1_FUNC);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_TYPE, Constants.TOOL_BAR_BUTTON);
                            menuLvl1HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENU);
                            menuLvl1HashMap.put(Constants.IS_EXPAND, true);

                            if ("1".equals(menuId) && panelStr.indexOf("baseTree") == -1) {
                                panelStr = panelStr + "baseTree,";
                            }
                            if ("2".equals(menuId) && panelStr.indexOf("mchtTree") == -1) {
                                panelStr = panelStr + "mchtTree,";
                            }
                            if ("3".equals(menuId) && panelStr.indexOf("termTree") == -1) {
                                panelStr = panelStr + "termTree,";
                            }
                            if ("5".equals(menuId) && panelStr.indexOf("queryTree") == -1) {
                                panelStr = panelStr + "queryTree,";
                            }
                            if ("9".equals(menuId) && panelStr.indexOf("onLinePayTree") == -1) {
                                panelStr = panelStr + "onLinePayTree,";
                            }
                            if ("10".equals(menuId) && panelStr.indexOf("taskTree") == -1) {
                                panelStr = panelStr + "taskTree,";
                            }
                            if ("8".equals(menuId) && panelStr.indexOf("clearTree") == -1) {
                                panelStr = panelStr + "clearTree,";
                            }
                            if ("4".equals(menuId) && panelStr.indexOf("riskTree") == -1) {
                                panelStr = panelStr + "riskTree,";
                            }
                            if ("11".equals(menuId) && panelStr.indexOf("provisionsTree") == -1) {
                                panelStr = panelStr + "provisionsTree,";
                            }
                            if ("12".equals(menuId) && panelStr.indexOf("errorTree") == -1) {
                                panelStr = panelStr + "errorTree,";
                            }
                            Map<String, Object> menuLvl2HashMap = new LinkedHashMap<String, Object>();
                            menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                            menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                            menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                    menuLvl2Map.get(Constants.MENU_PARENT_ID));
                            menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                            menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                            menuLvl2HashMap.put(Constants.IS_EXPAND, true);

                            Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                            int index = menuList.lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID));
                            LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                            //System.out.println((String)menuLvl3Map.get(Constants.MENU_ID) + ">>>>>>>>>" + index + ">>>>>" + menuList.size());
                            if (-1 == index) {
                                String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID),
                                        (String) funcMapList.get(a)[5]);
                                menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                                menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL));
                                menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                                menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                menuList.add((String) menuLvl3Map.get(Constants.MENU_ID));

                                menuLvl3Child.add(menuLvl3HashMap);
                            } else {
                                Map<String, Object> menu = (Map<String, Object>) menuLvl3Child.get(index);
                                menu.put(Constants.ROLE_FLAG,
                                        (String) menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]);
                            }

                            menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                            menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                            LinkedList<Object> menuLvl2Child = new LinkedList<Object>();
                            menuLvl2Child.add(menuLvl2HashMap);
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);

                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        } else {
                            Map<String, Object> menuLvl1HashMap = (Map<String, Object>) menuIndexMap
                                    .get(menuLvl1Map.get(Constants.MENU_ID).toString());
                            LinkedList<Object> menuLvl2Child = (LinkedList<Object>) menuLvl1HashMap
                                    .get(Constants.MENU_CHILDREN);
                            boolean hasMenu = false;
                            for (int c = 0, d = menuLvl2Child.size(); c < d; c++) {
                                Map<String, Object> menuLvl2HashMap = (Map<String, Object>) menuLvl2Child
                                        .get(c);
                                if (StringUtils.trim(menuLvl2HashMap.get(Constants.MENU_ID).toString()).equals(
                                        StringUtils.trim(menuLvl2Map.get(Constants.MENU_ID).toString()))) {
                                    LinkedList<Object> menuLvl3Child = (LinkedList<Object>) menuLvl2HashMap
                                            .get(Constants.MENU_CHILDREN);
                                    Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                    int index = menuList
                                            .lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID));
                                    if (-1 == index) {
                                        String tbar = MenuUtil.initMenu(
                                                (String) menuLvl3Map.get(Constants.MENU_ID),
                                                (String) funcMapList.get(a)[5]);
                                        menuLvl3HashMap.put(Constants.MENU_ID,
                                                menuLvl3Map.get(Constants.MENU_ID));
                                        menuLvl3HashMap.put(Constants.MENU_TEXT,
                                                menuLvl3Map.get(Constants.MENU_TEXT));
                                        menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                                menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                        menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                        menuLvl3HashMap.put(Constants.MENU_URL,
                                                menuLvl3Map.get(Constants.MENU_URL));
                                        menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                        menuLvl3HashMap.put(Constants.MENU_CLS,
                                                menuLvl3Map.get(Constants.MENU_CLS));
                                        menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                        menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                                menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                        menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                        menuList.add((String) menuLvl3Map.get(Constants.MENU_ID));
                                        menuLvl3Child.add(menuLvl3HashMap);
                                    }
                                    //                              else{
                                    //                                 Map<String, Object> menu = (Map<String, Object>)menuLvl3Child.get(index);
                                    //                                 menu.put(Constants.ROLE_FLAG,(String)menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]);
                                    //                              }
                                    menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                    menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                    menuLvl2HashMap.put(Constants.IS_EXPAND, true);
                                    menuLvl2Child.set(c, menuLvl2HashMap);
                                    hasMenu = true;
                                    break;
                                }
                            }
                            if (!hasMenu) {
                                String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID),
                                        (String) funcMapList.get(a)[5]);
                                Map<String, Object> menuLvl2HashMap = new HashMap<String, Object>();
                                menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID));
                                menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT));
                                menuLvl2HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl2Map.get(Constants.MENU_PARENT_ID));
                                menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS));
                                menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                menuLvl2HashMap.put(Constants.IS_EXPAND, true);
                                LinkedList<Object> menuLvl3Child = new LinkedList<Object>();
                                Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>();
                                menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID));
                                menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT));
                                menuLvl3HashMap.put(Constants.MENU_PARENT_ID,
                                        menuLvl3Map.get(Constants.MENU_PARENT_ID));
                                menuLvl3HashMap.put(Constants.MENU_LEAF, true);
                                menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL));
                                menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS));
                                menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar);
                                menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC);
                                //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM);
                                menuLvl3HashMap.put(Constants.TOOLBAR_ICON,
                                        menuLvl3Map.get(Constants.TOOLBAR_ICON));
                                menuLvl3HashMap.put(Constants.IS_EXPAND, true);

                                menuLvl3Child.add(menuLvl3HashMap);
                                menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child);
                                menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child);
                                menuLvl2Child.add(menuLvl2HashMap);
                            }
                            menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child);
                            menuLvl1HashMap.put(Constants.IS_EXPAND, true);
                            menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap);
                        }
                    }
                }
            }
        }
    }
    menuIndexMap.remove(Constants.TREE_MENU_PANEL);
    if (panelStr.length() != 0) {
        menuIndexMap.put(Constants.TREE_MENU_PANEL, panelStr.substring(0, panelStr.length() - 1));
    } else {
        menuIndexMap.put(Constants.TREE_MENU_PANEL, "");
    }
    return menuIndexMap;
}