Example usage for java.util HashMap remove

List of usage examples for java.util HashMap remove

Introduction

In this page you can find the example usage for java.util HashMap remove.

Prototype

public V remove(Object key) 

Source Link

Document

Removes the mapping for the specified key from this map if present.

Usage

From source file:net.doubledoordev.backend.webserver_old.methods.Post.java

/**
 * Handle post requests from the login page
 *///ww  w . j  a  v  a  2s.com
private static void handleLogin(HashMap<String, Object> dataObject, NanoHTTPD.HTTPSession session,
        Map<String, String> map) {
    if (map.containsKey("username") && map.containsKey("password")) {
        User user = Settings.getUserByName(map.get("username"));
        if (user != null && user.verify(map.get("password"))) {
            session.getCookies().set(COOKIE_KEY, user.getUsername() + "|" + user.getPasshash(), 30);
            dataObject.put("user", user);
        } else
            dataObject.put("message", "Login failed.");
    } else if (map.containsKey("logout")) {
        session.getCookies().delete(COOKIE_KEY);
        dataObject.remove("user");
    } else if (dataObject.containsKey("user") && map.containsKey("oldPassword")
            && map.containsKey("newPassword")) {
        User user = (User) dataObject.get("user");
        if (user.updatePassword(map.get("oldPassword"), map.get("newPassword"))) {
            session.getCookies().set(COOKIE_KEY, user.getUsername() + "|" + user.getPasshash(), 30);
        } else
            dataObject.put("message", "Old password was wrong.");
    } else
        dataObject.put("message", "Form error.");
}

From source file:org.dbpedia.spotlight.lucene.index.external.SSEKnowledgeBaseBuilder.java

public static LinkedHashMap sortHashMap(HashMap passedMap) {
    List mapKeys = new ArrayList(passedMap.keySet());
    List mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);//from  w  ww . j a  va2s  .com
    Collections.reverse(mapValues);
    Collections.sort(mapKeys);

    LinkedHashMap sortedMap = new LinkedHashMap();

    Iterator valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Object val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            String comp1 = passedMap.get(key).toString();
            String comp2 = val.toString();

            if (comp1.equals(comp2)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put((String) key, (Integer) val);
                break;
            }
        }
    }
    return sortedMap;
}

From source file:com.viettel.util.StringUtils.java

public static void buidQuery(String name, HashMap<String, Object> searchParams, StringBuilder strQuery,
         Map<String, Object> params, String... prefix) {
     ArrayList<String> arrQuery = new ArrayList<String>();
     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
     HashMap<String, Object> searchParamsCopy = new HashMap<>(searchParams);
     for (Map.Entry<String, Object> entry : searchParams.entrySet()) {
         String key = entry.getKey();
         Object value = entry.getValue();
         if (value == null || value.toString().equals("")) {
             searchParamsCopy.remove(key);
         }/*from  w  w  w .j a  va 2s .  c  o m*/
     }
     String pref = prefix != null && prefix.length > 0 ? prefix[0] + "." : "";
     for (Map.Entry<String, Object> entry : searchParamsCopy.entrySet()) {
         String key = entry.getKey();

         Object value = entry.getValue();
         /*
          * if (value == null || value.toString().equals("") || (value
          * instanceof Long && 0 >= (int) value)) { continue; }
          */
         if (arrQuery.size() > 0) {
             arrQuery.add(" AND  ");
         }
         if (value instanceof Date || DateUtil.isValidDateWithFormat(value.toString(), "yyyy-MM-dd")) {
             try {
                 if (key.startsWith("from")) {
                     String cl = key.replace("from", "");
                     if (searchParamsCopy.containsKey("to" + cl)) {
                         arrQuery.add(String.format("%1$s BETWEEN :%2$s", pref + cl, key));
                         params.put(key, formatter.parse(value.toString()));

                         Object objTo = searchParamsCopy.get("to" + cl);
                         if (objTo != null) {
                             arrQuery.add(String.format(" AND :%s", "to" + cl));
                             params.put("to" + cl, formatter.parse(objTo.toString()));
                         }
                     } else {
                         arrQuery.add(String.format("%1$s >= :%2$s", pref + cl, key));
                         params.put(key, formatter.parse(value.toString()));
                     }
                 } else if (key.startsWith("to")) {
                     String cl = key.replace("to", "");
                     if (!searchParamsCopy.containsKey("from" + cl)) {
                         arrQuery.add(String.format("%1$s <= :%2$s", pref + cl, key));
                         params.put(key, formatter.parse(value.toString()));
                     } else {
                         if (arrQuery.size() > 0) {
                             arrQuery.remove(arrQuery.size() - 1);
                         }
                     }
                 } else {
                     arrQuery.add(String.format("DATE(%1$s) = DATE(:%2$s)", pref + key, key));
                     params.put(key, value + "%");
                 }
             } catch (ParseException ex) {

             }
         } else if (value instanceof Number) {
             if (key.startsWith("and_")) {
                 if (searchParamsCopy.containsKey(key.replace("and_", ""))) {
                     if (!CollectionUtils.isEmpty(arrQuery)) {
                         arrQuery.remove(arrQuery.size() - 1);
                     }
                 }
             } else if (searchParamsCopy.containsKey("and_" + key)) {
                 arrQuery.add(String.format("(%1$s = :%2$s", pref + key, key));
                 if (value instanceof Integer) {
                     params.put(key, Integer.parseInt(value.toString()));
                 } else if (value instanceof Long) {
                     params.put(key, Long.parseLong(value.toString()));
                 } else if (value instanceof Float) {
                     params.put(key, Float.parseFloat(value.toString()));
                 } else if (value instanceof Double) {
                     params.put(key, Double.parseDouble(value.toString()));
                 }

                 Object obj = searchParamsCopy.get("and_" + key);
                 if (obj != null) {
                     arrQuery.add(String.format(" OR %1$s = :%2$s)", pref + key, "and_" + key));
                     if (value instanceof Integer) {
                         params.put("and_" + key, Integer.parseInt(obj.toString()));
                     } else if (value instanceof Long) {
                         params.put("and_" + key, Long.parseLong(obj.toString()));
                     } else if (value instanceof Float) {
                         params.put("and_" + key, Float.parseFloat(obj.toString()));
                     } else if (value instanceof Double) {
                         params.put("and_" + key, Double.parseDouble(obj.toString()));
                     }
                 }
             } else {
                 arrQuery.add(String.format("%1$s = :%2$s", pref + key, key));
                 if (value instanceof Integer) {
                     params.put(key, Integer.parseInt(value.toString()));
                 } else if (value instanceof Long) {
                     params.put(key, Long.parseLong(value.toString()));
                 } else if (value instanceof Float) {
                     params.put(key, Float.parseFloat(value.toString()));
                 } else if (value instanceof Double) {
                     params.put(key, Double.parseDouble(value.toString()));
                 }
             }
         } else if (value instanceof String) {
             if (key.startsWith("and_")) {
                 if (searchParamsCopy.containsKey(key.replace("and_", ""))) {
                     if (arrQuery.size() > 0) {
                         arrQuery.remove(arrQuery.size() - 1);
                     }
                 }
             } else if (searchParamsCopy.containsKey("and_" + key)) {
                 arrQuery.add(String.format("(LOWER(%1$s) like LOWER(:%2$s)", pref + key, key));
                 params.put(key, "%" + value + "%");

                 Object obj = searchParamsCopy.get("and_" + key);
                 if (obj != null) {
                     arrQuery.add(String.format(" OR LOWER(%1$s) LIKE LOWER(:%2$s))", pref + key, "and_" + key));
                     params.put("and_" + key, "%" + obj + "%");
                 }
             } else if (key.startsWith("in_cond_")) {
                 String cl = key.replace("in_cond_", "");
                 arrQuery.add(String.format("%1$s IN (%2$s)", pref + cl, value.toString()));
                 params.remove(key);
             } else if (key.startsWith("not_in_cond_")) {
                 String cl = key.replace("not_in_cond_", "");
                 arrQuery.add(String.format("%1$s NOT IN (%2$s)", pref + cl, value.toString()));
                 params.remove(key);
             } else {
                 arrQuery.add(String.format("LOWER(%1$s) LIKE LOWER(:%2$s)", pref + key, key));
                 params.put(key, "%" + value + "%");
             }
         }
     }
     strQuery.append(String.join("", arrQuery));
 }

From source file:com.noshufou.android.su.util.Util.java

public static boolean deleteStoreFile(Context context, int uid, int execUid, String cmd) {
    File storeFile = getStoreFile(context, uid, execUid);
    if (!storeFile.exists())
        return true;
    HashMap<String, String> cmds = readStoreFile(storeFile);
    cmds.remove(cmd);
    if (cmds.isEmpty() || cmds.containsKey("any")) {
        return storeFile.delete();
    } else {/* w w w .ja  va 2s  . c  o  m*/
        return writeStoreFile(storeFile, cmds);
    }
}

From source file:org.hfoss.posit.web.Communicator.java

/**
 * cleanup the item key,value pairs so that we can receive and save to the internal database
 * @param rMap/*from   www.j  a  v  a 2  s  .c  o  m*/
 */
public static void cleanupOnReceive(HashMap<String, Object> rMap) {
    rMap.put(PositDbHelper.FINDS_SYNCED, PositDbHelper.FIND_IS_SYNCED);
    rMap.put(PositDbHelper.FINDS_GUID, rMap.get("barcode_id"));
    //rMap.put(PositDbHelper.FINDS_GUID, rMap.get("barcode_id"));

    rMap.put(PositDbHelper.FINDS_PROJECT_ID, projectId);
    if (rMap.containsKey("add_time")) {
        rMap.put(PositDbHelper.FINDS_TIME, rMap.get("add_time"));
        rMap.remove("add_time");
    }
    if (rMap.containsKey("images")) {
        if (Utils.debug)
            Log.d(TAG, "contains image key");
        rMap.put(PositDbHelper.PHOTOS_IMAGE_URI, rMap.get("images"));
        rMap.remove("images");
    }
}

From source file:com.example.common.ApiRequestFactory.java

/**
 * Generate the API XML request body// w w  w  .j a  v  a  2  s . c o m
 */
@SuppressWarnings("unchecked")
private static String generateXmlRequestBody(Object params) {

    if (params == null) {
        return "<request version=\"2\"></request>";
    }

    HashMap<String, Object> requestParams;
    if (params instanceof HashMap) {
        requestParams = (HashMap<String, Object>) params;
    } else {
        return "<request version=\"2\"></request>";
    }

    final StringBuilder buf = new StringBuilder();

    // TODO: add local_version parameter if exist
    // 2010/12/29 update version to 2 to get comments from bbs
    buf.append("<request version=\"2\"");
    if (requestParams.containsKey("local_version")) {
        buf.append(" local_version=\"" + requestParams.get("local_version") + "\" ");
        requestParams.remove("local_version");
    }
    buf.append(">");

    // add parameter node
    final Iterator<String> keySet = requestParams.keySet().iterator();
    while (keySet.hasNext()) {
        final String key = keySet.next();

        if ("upgradeList".equals(key)) {
            buf.append("<products>");
            List<PackageInfo> productsList = (List<PackageInfo>) requestParams.get(key);
            for (PackageInfo info : productsList) {
                buf.append("<product package_name=\"").append(info.packageName);
                buf.append("\" version_code=\"").append(info.versionCode).append("\"/>");
            }
            buf.append("</products>");
            continue;
        } else if ("appList".equals(key)) {
            buf.append("<apps>");
            List<UpgradeInfo> productsList = (List<UpgradeInfo>) requestParams.get(key);
            for (UpgradeInfo info : productsList) {
                buf.append("<app package_name=\"").append(info.pkgName);
                buf.append("\" version_code=\"").append(info.versionCode);
                buf.append("\" version_name=\"").append(info.versionName);
                buf.append("\" app_name=\"").append(wrapText(info.name));
                //                    buf.append("\" md5=\"").append(info.md5);
                buf.append("\"/>");
            }
            buf.append("</apps>");
            continue;
        }

        buf.append("<").append(key).append(">");
        buf.append(requestParams.get(key));
        buf.append("</").append(key).append(">");
    }

    // add the enclosing quote
    buf.append("</request>");
    return buf.toString();
}

From source file:com.clustercontrol.hinemosagent.util.AgentConnectUtil.java

/**
 * ???//  www  .  ja v a 2 s  .  c  om
 */
public static ArrayList<String> getValidAgent() {
    try {
        _agentCacheLock.writeLock();

        HashMap<String, AgentInfo> agentMap = getAgentCache();
        Set<AgentInfo> removedSet = new HashSet<AgentInfo>();
        for (Entry<String, AgentInfo> entry : new HashSet<Entry<String, AgentInfo>>(agentMap.entrySet())) {
            if (!entry.getValue().isValid()) {
                removedSet.add(agentMap.remove(entry.getKey()));
                m_log.info("remove " + entry.getValue());
            }
        }
        if (removedSet.size() > 0) {
            storeAgentCache(agentMap);
        }
    } finally {
        _agentCacheLock.writeUnlock();
    }

    try {
        _agentCacheLock.readLock();

        Map<String, AgentInfo> agentMap = getAgentCache();

        ArrayList<String> list = new ArrayList<String>();
        for (String fid : agentMap.keySet()) {
            list.add(fid);
        }

        return list;
    } finally {
        _agentCacheLock.readUnlock();
    }
}

From source file:asu.edu.msse.gpeddabu.moviedescriptions.MovieLibrary.java

public void deleteMovie(String genre, String title) throws JSONException {
    HashMap<String, JSONObject> childHash = movieMap.get(genre);
    childHash.remove(title);
}

From source file:ruige.GrabFTPDateManager.java

private static Boolean saveIntoDB(HashMap<String, String> orderHM, ArrayList<HashMap<String, String>> list,
        ArrayList<HashMap<String, String>> list2, ArrayList<HashMap<String, String>> list3,
        ArrayList<HashMap<String, String>> list4, String DeclearTime, String fromType) throws Exception {
    boolean result = true;
    DBUtil db = null;// w  ww.  j a v a 2  s  .  c  om
    try {
        if (list == null) {
            return true;
        }
        if (DeclearTime.length() > 0) {
            orderHM.put("DeclearTime", DeclearTime);
            orderHM.put("IsUpdatePassTime", "1");
        }
        db = DBUtil.getInstance();
        db.setConnectionAttr(false);
        if ("1".equals(fromType)) {
            orderHM.put("CompanyType", "1");//1
        }
        String orderID = db.insert(orderHM, "SSRESOrderInfo");

        for (int i = 0; i < list.size(); i++) {
            HashMap<String, String> partHash = (HashMap<String, String>) list.get(i);
            if (null != partHash.get("GOODS_ID")) {
                String str = partHash.get("GOODS_ID").toString();
                boolean isDigit = false;
                for (int m = 0; m < str.length(); m++) { //   
                    if (!Character.isDigit(str.charAt(m))) {//char
                        isDigit = true;
                        break;
                    }
                }
                if (isDigit) {
                    partHash.remove("GOODS_ID");
                    partHash.put("GOODS_ID", "");
                }
            }
            partHash.put("OrderID", orderID);
            partHash.put("TransCode", orderHM.get("BILL_NO"));
            partHash.put("G_NAME", partHash.get("G_NAME").toString().replace("'", "''"));
            db.insert(partHash, "SSRESPartsList");
        }
        for (int i = 0; i < list2.size(); i++) {
            HashMap<String, String> ContrainerHash = (HashMap<String, String>) list2.get(i);
            ContrainerHash.put("OrderID", orderID);
            db.insert(ContrainerHash, "SSRESContainerList");
        }
        for (int i = 0; i < list3.size(); i++) {
            HashMap<String, String> CertHash = (HashMap<String, String>) list3.get(i);
            CertHash.put("OrderID", orderID);
            db.insert(CertHash, "SSRESCERTList");
        }
        for (int i = 0; i < list4.size(); i++) {
            HashMap<String, String> DocHash = (HashMap<String, String>) list4.get(i);
            DocHash.put("OrderID", orderID);
            db.insert(DocHash, "SSRESDocList");
        }
        db.commitConn();
    } catch (Exception e) {
        db.rollBackConn();
        e.printStackTrace();
        return false;
    }
    return result;
}

From source file:edu.utah.bmi.ibiomes.lite.ExperimentIndex.java

/**
 * Remove entry (experiment) from index/*from   w  w  w  .j  av a2  s.  co m*/
 * @param experimentPath Path to experiment
 * @throws IOException 
 * @throws CompressorException 
 */
public void removeEntry(String experimentPath) throws IOException, CompressorException {
    HashMap<String, IndexEntry> index = loadIndexFromFile();
    index.remove(experimentPath);
    storeIndexToFile(index);
}