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:org.apache.sqoop.shell.utils.TestConfigFiller.java

@SuppressWarnings("unchecked")
@Test(enabled = false)/*from  w  ww.j ava 2s .  c  om*/
public void testFillInputMapWithBundle() throws IOException {
    initEnv();
    // End of the process
    MMapInput input = new MMapInput("Map", false, InputEditable.ANY, StringUtils.EMPTY, StringUtils.EMPTY,
            Collections.EMPTY_LIST);
    assertFalse(fillInputMapWithBundle(input, reader, resourceBundle));

    // empty
    initData("\r");
    input.setEmpty();
    assertTrue(fillInputMapWithBundle(input, reader, resourceBundle));

    // Add k1=v1 and k2=v2
    initData("k1=v1\rk2=v2\r\r");
    input.setEmpty();
    assertTrue(fillInputMapWithBundle(input, reader, resourceBundle));
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("k1", "v1");
    map.put("k2", "v2");
    assertEquals(input.getValue(), map);

    // Remove k2
    initData("k2\r\r");
    assertTrue(fillInputMapWithBundle(input, reader, resourceBundle));
    map.remove("k2");
    assertEquals(input.getValue(), map);
}

From source file:net.sf.fakenames.fddemo.BaseDirLayout.java

private void parseMounts(HashMap<File, String> pathNameMap, List<StorageVolume> volumes) throws IOException {
    mounts: for (LongObjectCursor<MountInfo.Mount> mount : mountInfo.mountMap) {
        final Iterator<Map.Entry<File, String>> i = pathNameMap.entrySet().iterator();
        while (i.hasNext()) {
            final Map.Entry<File, String> e = i.next();
            final String p = e.getKey().toString();
            if (p.equals(mount.value.rootPath) || p.startsWith(mount.value.rootPath + '/')) {
                i.remove();//from   w w  w .  ja  v  a  2  s. c  o m
                pathNameMap.remove(e.getKey());
                mount.value.rootPath = p;
                mount.value.description = e.getValue();
                usableFilesystems.add(mount.value.fstype);
                break;
            }
        }

        if (Build.VERSION.SDK_INT >= 24) {
            final File mountRoot = new File(mount.value.rootPath);

            final StorageManager sm = (StorageManager) getSystemService(STORAGE_SERVICE);
            Iterator<StorageVolume> j = volumes.iterator();
            while (j.hasNext()) {
                StorageVolume knownVolume = j.next();

                if (knownVolume.equals(sm.getStorageVolume(mountRoot))) {
                    // seems like the mount belongs to the storage device, appropriately labeled
                    // by the manufacturer  use system-provided description
                    j.remove();
                    mount.value.description = knownVolume.getDescription(this);
                    usableFilesystems.add(mount.value.fstype);
                    continue mounts;
                }
            }
        }
    }

    final Set<File> current = new HashSet<>();
    Collections.addAll(current, home.listFiles());

    // display all mounts with sensible descriptions
    for (LongObjectCursor<MountInfo.Mount> mount : mountInfo.mountMap) {
        if (TextUtils.isEmpty(mount.value.description)) {
            continue;
        }

        File descFile = new File(home, mount.value.description);

        if (!descFile.exists()) {
            if (current.contains(descFile)) {
                // a broken link...

                //noinspection ResultOfMethodCallIgnored
                descFile.delete();
            }

            @Fd
            int dir = os.opendir(home.getPath());

            os.symlinkat(mount.value.rootPath, dir, descFile.getName());
        }
    }
}

From source file:org.mobicents.servlet.sip.example.DistributableClick2CallSipServlet.java

protected void doRegister(SipServletRequest req) throws ServletException, IOException {
    logger.info("Received register request: " + req.getTo());
    int response = SipServletResponse.SC_OK;
    SipServletResponse resp = req.createResponse(response);
    HashMap<String, String> users = (HashMap<String, String>) req.getApplicationSession()
            .getAttribute("registeredUsersMap");
    if (users == null)
        users = new HashMap<String, String>();
    req.getApplicationSession().setAttribute("registeredUsersMap", users);

    Address address = req.getAddressHeader(CONTACT_HEADER);
    String fromURI = req.getFrom().getURI().toString();

    int expires = address.getExpires();
    if (expires < 0) {
        expires = req.getExpires();/*from  w w  w  . ja  v  a 2  s. c  om*/
    }
    if (expires == 0) {
        users.remove(fromURI);
        logger.info("User " + fromURI + " unregistered");
    } else {
        resp.setAddressHeader(CONTACT_HEADER, address);
        users.put(fromURI, address.getURI().toString());
        logger.info("User " + fromURI + " registered with an Expire time of " + expires);
    }

    resp.send();
}

From source file:net.dv8tion.jda.handle.EntityBuilder.java

public void createGuildSecondPass(String guildId, List<JSONArray> memberChunks) {
    HashMap<String, JSONObject> cachedGuildJsons = cachedJdaGuildJsons.get(api);
    HashMap<String, Consumer<Guild>> cachedGuildCallbacks = cachedJdaGuildCallbacks.get(api);

    JSONObject guildJson = cachedGuildJsons.remove(guildId);
    Consumer<Guild> secondPassCallback = cachedGuildCallbacks.remove(guildId);
    GuildImpl guildObj = (GuildImpl) api.getGuildMap().get(guildId);

    if (guildObj == null)
        throw new IllegalStateException(
                "Attempted to preform a second pass on an unknown Guild. Guild not in JDA "
                        + "mapping. GuildId: " + guildId);
    if (guildJson == null)
        throw new IllegalStateException(
                "Attempted to preform a second pass on an unknown Guild. No cached Guild "
                        + "for second pass. GuildId: " + guildId);
    if (secondPassCallback == null)
        throw new IllegalArgumentException("No callback provided for the second pass on the Guild!");

    for (JSONArray chunk : memberChunks) {
        createGuildMemberPass(guildObj, chunk);
    }/*www  .  j a v  a2 s . co  m*/

    User owner = api.getUserById(guildJson.getString("owner_id"));
    if (owner != null)
        guildObj.setOwner(owner);

    if (guildObj.getOwner() == null)
        JDAImpl.LOG.fatal("Never set the Owner of the Guild: " + guildObj.getId()
                + " because we don't have the owner User object! How?!");

    JSONArray channels = guildJson.getJSONArray("channels");
    createGuildChannelPass(guildObj, channels);

    secondPassCallback.accept(guildObj);
    GuildLock.get(api).unlock(guildId);
}

From source file:com.jennifer.ui.util.DomUtil.java

public DomUtil removeClass(String s) {
    String[] list = attrs.optString("class").split(" ");
    String[] listEx = s.split(" ");
    ArrayList<String> result = new ArrayList<String>();

    HashMap<String, Boolean> map = new HashMap<String, Boolean>();
    for (String key : list) {
        map.put(key, new Boolean(true));
    }/*  w w  w . j  a v a 2  s  .  c o  m*/

    for (String key : listEx) {
        map.remove(key);
    }

    for (String key : map.keySet()) {
        result.add(key);
    }

    put("class", StringUtil.join(result, " "));

    return this;

}

From source file:com.snsplus.soqlive.Fragment.Found_Fragment.java

/**
 *
 *
 *//*www  .java  2 s  .  c  o m*/
private void toggleLikeUserApi(final String vjUserId, final int isGuanzu) {
    String dialogText = mContext.getResources().getString(R.string.server_loading);
    final ProgressDialog mProgressDialog = mCustomProgressDialogUtil.getCustomProgressDialog(dialogText);

    ChinaHttpApi.toggleLikeUser(mContext, mAppData.getUserInfo().getUserId(), vjUserId,
            new ChinaHttpApi.Callback() {
                @Override
                public void onResponse(final String response) {
                    LogUtil.i("ToggleUser", "result : " + response);
                    mainHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (mProgressDialog != null && mProgressDialog.isShowing()) {
                                mProgressDialog.dismiss();
                            }
                            boolean isSuccess = false;

                            try {
                                JSONObject temp = new JSONObject(response);
                                isSuccess = temp.optBoolean("isSuccessFlag");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            if (isSuccess) {
                                //isFans 0 , 1
                                for (int i = 0; i < mFoundAdapter.listData.size(); i++) {
                                    if (mFoundAdapter.listData.get(i).userInfo.getUserId()
                                            .equalsIgnoreCase(vjUserId)) {
                                        if (isGuanzu == 0) {
                                            mFoundAdapter.listData.get(i).isFans = 1;
                                        } else {
                                            mFoundAdapter.listData.get(i).isFans = 0;
                                        }
                                        break;
                                    }
                                }
                                mUserInfor_Pref = new UserInfor_Pref(getActivity());
                                HashMap<String, Boolean> mLikeMap = mUserInfor_Pref.getUserLikeMap();
                                if (mLikeMap != null) {
                                    if (mLikeMap.containsKey(vjUserId)) {
                                        if (isGuanzu == 0) {
                                            mLikeMap.remove(vjUserId);
                                            mLikeMap.put(vjUserId, true);
                                        } else {
                                            mLikeMap.remove(vjUserId);
                                        }
                                    } else {
                                        if (isGuanzu == 0) {
                                            mLikeMap.put(vjUserId, true);
                                        }
                                    }
                                } else {
                                    mLikeMap = new HashMap<String, Boolean>();
                                    if (isGuanzu == 0) {
                                        mLikeMap.put(vjUserId, true);
                                    }
                                }
                                mUserInfor_Pref.saveUserLikeMap(mLikeMap);

                                //                                 ??? local 
                                mServerData_Pref.changeSaveGuanzuData(vjUserId, isGuanzu);
                                mFoundAdapter.notifyDataSetChanged();
                            }
                        }
                    });
                }

                @Override
                public void onErrorResponse(VolleyError error) {
                    LogUtil.e(TAG, "error", error);

                    if (mProgressDialog != null && mProgressDialog.isShowing()) {
                        mProgressDialog.dismiss();
                    }
                }
            });
}

From source file:gov.lanl.adore.djatoka.plugin.ExtractPDF.java

/**
 * Returns PDF props in ImageRecord/*  w ww.j  a  va2s . c  om*/
 * @param r ImageRecord containing absolute file path of PDF file.
 * @return a populated ImageRecord object
 * @throws DjatokaException
 */
@Override
public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
    if ((r.getImageFile() == null || !new File(r.getImageFile()).exists()) && r.getObject() == null)
        throw new DjatokaException("Image Does Not Exist: " + r.toString());
    logger.debug("Get metadata: " + r.toString());
    try {
        DjatokaDecodeParam params = new DjatokaDecodeParam();
        BufferedImage bi = process(r, params);

        r.setWidth(bi.getWidth());
        r.setHeight(bi.getHeight());
        r.setDWTLevels(DEFAULT_LEVELS);
        r.setLevels(DEFAULT_LEVELS);
        r.setBitDepth(bi.getColorModel().getPixelSize());
        r.setNumChannels(bi.getColorModel().getNumColorComponents());

        //r.setCompositingLayerCount(getNumberOfPages(r)); // Semantics: number of pages in the PDF file.
        HashMap<String, String> pdfProps = (HashMap<String, String>) getPDFProperties(r);
        int n = Integer.parseInt(pdfProps.remove("Pages"));
        r.setCompositingLayerCount(n);

        // Since it is not possible for the viewer to query about a specific page's width and height
        // (because in Djatoka's point of view a PDF is just one image with various compositing layers, which are the pages),
        // at this point right here we query the PDF file about the size of all pages and store this
        // information in a Map. This map can be returned by getMetadata by setting it as the instProps member of the
        // ImageRecord class, which Djatoka already implements and which is returned as JSON to the viewer JS.
        // The viewer then has to store this information and later query it instead of asking Djatoka (getMetadata) again.
        //Map<String, String> instProps = getPagesSizes(r);
        r.setInstProps(pdfProps);
        logger.debug("instProps: " + r.getInstProps());

        logger.debug("Get metadata: " + r.toString());
    } catch (Exception e) {
        throw new DjatokaException(e);
    }

    return r;
}

From source file:com.erudika.scoold.core.Profile.java

public HashMap<String, Integer> getBadgesMap() {
    HashMap<String, Integer> badgeMap = new HashMap<String, Integer>(0);
    if (StringUtils.isBlank(badges)) {
        return badgeMap;
    }//from www. j a  va  2s. c  o m

    for (String badge : badges.split(",")) {
        Integer val = badgeMap.get(badge);
        int count = (val == null) ? 0 : val.intValue();
        badgeMap.put(badge, ++count);
    }

    badgeMap.remove("");
    return badgeMap;
}

From source file:com.vmware.thinapp.vi.InventoryBrowser.java

/**
 * Method to filter out TAF VMs (appliances, templates, and capture
 * instances managed by this appliances as well as others) from the
 * input parameter 'vms'. Returns only VMs that does not belong to
 * any TAF server. This method also update the tafVMs and othersVMs
 * lists on seeing new VMs./*w  w w .  j av a 2s  .  c o  m*/
 *
 * @param vms all VMs to be checked.
 *
 * @return VMs that not belong to any TAF server.
 */
private VirtualMachine[] filterOutTAFVms(VirtualMachine vms[]) throws RemoteException {
    HashMap<String, VirtualMachine> vmMap = new HashMap<String, VirtualMachine>();

    for (VirtualMachine vm : vms) {
        String moid = vm.getMOR().get_value();
        vmMap.put(moid, vm);
    }

    // Check the tafVMs list.
    for (String moid : tafVMs) {
        if (vmMap.remove(moid) != null) {
            log.trace("VM {} in known TAF VM list is filtered out.", moid);
        }
    }

    // Check the othersVMs list, os type, machine.id etc.
    Iterator<VirtualMachine> itr = vmMap.values().iterator();
    while (itr.hasNext()) {
        VirtualMachine vm = itr.next();
        String moid = vm.getMOR().get_value();

        if (othersVMs.contains(moid)) {
            continue;
        }

        // We haven't seen this VM previously. check its guest id against
        // support guest id list.
        VirtualMachineConfigInfo info = vm.getConfig();
        String guestId = info.getGuestId();
        if (!VIConstants.GUEST_ID_SUPPOTRED.contains(guestId)) {
            tafVMs.add(moid);
            itr.remove();
            log.trace("VM {} of {} guest is filtered out.", moid, guestId);
            continue;
        }

        // It is not a Linux VM, we check its machine.id
        OptionValue[] extraConfig = info.getExtraConfig();
        if (extraConfig == null) {
            // No extra config, it is not a TAF VM. Hence, add it to the
            // othersVMs
            othersVMs.add(moid);
            continue;
        }

        boolean isTAFVm = false;

        for (OptionValue optval : extraConfig) {
            if (optval.getKey().equals(TAF_VM_KEY)) {
                isTAFVm = true;
                break;
            }
        }

        if (isTAFVm) {
            // It is a TAF VM, add to the known TAF VM list and remove from
            // display VM list.
            tafVMs.add(moid);
            itr.remove();
            log.trace("VM {} is managed by a TAF and is filtered out.", vm.getName());
        } else {
            // It is not a TAF VM, add to the others VM list to reduce further
            // VC call.
            othersVMs.add(moid);
            log.trace("Added VM {} to othersVMs.", vm.getName());
        }
    }

    // What left in the vmMap are all non-TAF VMs.
    return vmMap.values().toArray(new VirtualMachine[] {});
}

From source file:org.apache.hadoop.mapred.DatanodeBenThread.java

private static HashMap<String, ArrayList<Path>> getNSPickLists(DistributedFileSystem dfs, String workdir,
        long minFile, Set<String> victims) throws IOException {
    HashMap<String, ArrayList<Path>> nsPickLists = new HashMap<String, ArrayList<Path>>();
    RemoteIterator<LocatedFileStatus> iter = dfs.listLocatedStatus(new Path(workdir));
    while (iter.hasNext()) {
        LocatedFileStatus lfs = iter.next();
        if (lfs.isDir())
            continue;
        if (lfs.getBlockLocations().length != 1)
            continue;
        for (String hostname : lfs.getBlockLocations()[0].getHosts()) {
            // Skip the uninterested datanodes
            if (victims != null && !victims.contains(hostname))
                continue;
            ArrayList<Path> value = null;
            if (!nsPickLists.containsKey(hostname)) {
                value = new ArrayList<Path>();
                nsPickLists.put(hostname, value);
            } else {
                value = nsPickLists.get(hostname);
            }/*from w  w w. ja  v  a 2 s. co  m*/
            value.add(lfs.getPath());
        }
    }
    if (victims == null) {
        String[] hostnames = nsPickLists.keySet().toArray(new String[0]);
        //Remove the datanodes with not enough files
        for (String hostname : hostnames) {
            if (nsPickLists.get(hostname).size() < minFile) {
                nsPickLists.remove(hostname);
            }
        }
    }
    return nsPickLists;
}