Example usage for java.util Hashtable remove

List of usage examples for java.util Hashtable remove

Introduction

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

Prototype

public synchronized V remove(Object key) 

Source Link

Document

Removes the key (and its corresponding value) from this hashtable.

Usage

From source file:press.gfw.Server.java

/**
 * //from  ww w  .java  2  s.  com
 */
public void service() {

    if (System.currentTimeMillis() - lockFile.lastModified() < 30 * 000L) {

        log("???");

        log("? " + lockFile.getAbsolutePath() + "??");

        return;

    }

    try {

        lockFile.createNewFile();

    } catch (IOException ioe) {

    }

    lockFile.deleteOnExit();

    log("GFW.Press??......");

    log("?" + proxyHost);

    log("??" + proxyPort);

    Hashtable<String, String> users = null; // 

    Hashtable<String, Server> threads = new Hashtable<String, Server>(); // 

    while (true) {

        lockFile.setLastModified(System.currentTimeMillis());

        _sleep(20 * 1000L); // ?20

        users = config.getUser(); // ?

        if (users == null || users.size() == 0) {

            continue;

        }

        Enumeration<String> threadPorts = threads.keys(); // ?

        while (threadPorts.hasMoreElements()) { // ???

            String threadPort = threadPorts.nextElement();

            String userPassword = users.remove(threadPort);

            if (userPassword == null) { // 

                threads.remove(threadPort).kill();

                log("?" + threadPort);

            } else {

                Server thread = threads.get(threadPort);

                if (!userPassword.equals(thread.getPassword())) { // ?

                    log("??" + threadPort);

                    threads.remove(threadPort);

                    thread.kill();

                    thread = new Server(proxyHost, proxyPort, threadPort, userPassword);

                    threads.put(threadPort, thread);

                    thread.start();

                }

            }

        }

        Enumeration<String> userPorts = users.keys();

        while (userPorts.hasMoreElements()) { // 

            String userPort = userPorts.nextElement();

            Server thread = new Server(proxyHost, proxyPort, userPort, users.get(userPort));

            threads.put(userPort, thread);

            thread.start();

        }

        users.clear();

    }

}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the consumption of this project's
 * allocation by each collaborator including the current user.
 * // w  ww .j  ava 2s .  c o  m
 * @param project
 * @return
 */
private DefaultPieDataset createUserDataset(Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> userUsageTable = new Hashtable<String, Double>();

    for (ProjectBean project : projectCollabTable.keySet()) {
        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        for (CollaboratorBean collab : collabs) {
            String key = collab.getFirstName() + " " + collab.getLastName();
            if (userUsageTable.containsKey(key)) {
                double oldVal = userUsageTable.get(key).doubleValue();
                userUsageTable.remove(key);
                userUsageTable.put(key, new Double(oldVal + collab.getTotalUsage().getUsed()));
            } else {
                userUsageTable.put(key, new Double(collab.getTotalUsage().getUsed()));
            }
        }
    }

    // now put the tallies in the dataset
    for (String key : userUsageTable.keySet()) {
        pds.setValue(key, userUsageTable.get(key).doubleValue());
    }

    return pds;
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the normalized usage of this project
 * on each resource in the CCG.  The values shown will be the current
 * usage on each resource, however, in terms of display, they will
 * appear as relative to each other.//w  w  w .j  av  a2  s . co m
 * 
 * @param project
 * @return
 */
private DefaultPieDataset createResourceDataset(
        Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> resourceUsageTable = new Hashtable<String, Double>();

    for (ProjectBean project : projectCollabTable.keySet()) {
        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        for (CollaboratorBean collab : collabs) {

            for (String systemName : collab.getUsageTable().keySet()) {
                UsageBean usage = collab.getUsageTable().get(systemName);

                if (resourceUsageTable.containsKey(systemName)) {
                    double previousUsage = resourceUsageTable.get(systemName).doubleValue();
                    resourceUsageTable.remove(systemName);
                    resourceUsageTable.put(systemName, new Double(previousUsage + usage.getUsed()));
                } else {
                    resourceUsageTable.put(systemName, new Double(usage.getUsed()));
                }
            }
        }
    }

    // now put the tallies in the dataset
    for (String systemName : resourceUsageTable.keySet()) {
        pds.setValue(systemName, resourceUsageTable.get(systemName).doubleValue());
    }

    return pds;

    //        System.out.println("found specified collaborator " + collab.getLastName() + 
    //                " with " + collab.getUsageTable().size() + " resource records.");
    //        
    //        for(String key: collab.getUsageTable().keySet()) {
    //            pds.setValue(key, collab.getUsageTable().get(key).getUsed());
    //        }
    //        
    //        return pds;
}

From source file:org.hdiv.filter.AbstractValidatorHelper.java

/**
 * Check if all required parameters are received in <code>request</code>.
 * //  w ww  .jav a  2 s  .c om
 * @param request HttpServletRequest to validate
 * @param state IState The restored state for this url
 * @param target Part of the url that represents the target action
 * @return True if all required parameters are received. False in otherwise.
 */
private boolean allRequiredParametersReceived(HttpServletRequest request, IState state, String target) {

    Hashtable receivedParameters = new Hashtable(state.getRequiredParams());

    String currentParameter = null;
    Enumeration requestParameters = request.getParameterNames();
    while (requestParameters.hasMoreElements()) {

        currentParameter = (String) requestParameters.nextElement();
        if (receivedParameters.containsKey(currentParameter)) {
            receivedParameters.remove(currentParameter);
        }

        // If multiple parameters are received, it is possible to pass this
        // verification without checking all the request parameters.
        if (receivedParameters.size() == 0) {
            return true;
        }
    }

    if (receivedParameters.size() > 0) {
        this.logger.log(HDIVErrorCodes.REQUIRED_PARAMETERS, target, receivedParameters.keySet().toString(),
                null);
        return false;
    }

    return true;
}

From source file:com.adito.agent.client.ProxyUtil.java

/**
 * Attempt to proxy settings from Firefox.
 * /*from  w  w w . ja va 2 s  .co m*/
 * @return firefox proxy settings
 * @throws IOException if firefox settings could not be obtained for some
 *         reason
 */
public static BrowserProxySettings lookupFirefoxProxySettings() throws IOException {

    try {

        Vector proxies = new Vector();
        Vector bypassAddr = new Vector();

        File home = new File(Utils.getHomeDirectory());
        File firefoxAppData;

        if (System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            firefoxAppData = new File(home, "Application Data\\Mozilla\\Firefox\\profiles.ini"); //$NON-NLS-1$
        } else {
            firefoxAppData = new File(home, ".mozilla/firefox/profiles.ini"); //$NON-NLS-1$
        }

        // Look for Path elements in the profiles.ini
        BufferedReader reader = null;
        Hashtable profiles = new Hashtable();
        String line;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(firefoxAppData)));
            String currentProfileName = ""; //$NON-NLS-1$

            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.startsWith("[") && line.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$
                    currentProfileName = line.substring(1, line.length() - 1);
                    continue;
                }

                if (line.startsWith("Path=")) { //$NON-NLS-1$
                    profiles.put(currentProfileName, new File(firefoxAppData.getParent(), line.substring(5)));
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }

        // Iterate through all the profiles and load the proxy infos from
        // the prefs.js file

        File prefsJS;
        String profileName;
        for (Enumeration e = profiles.keys(); e.hasMoreElements();) {
            profileName = (String) e.nextElement();
            prefsJS = new File((File) profiles.get(profileName), "prefs.js"); //$NON-NLS-1$
            Properties props = new Properties();
            reader = null;
            try {
                if (!prefsJS.exists()) {
                    // needed to defend against un-initialised profiles.
                    // #ifdef DEBUG
                    log.info("The file " + prefsJS.getAbsolutePath() + " does not exist."); //$NON-NLS-1$
                    // #endif
                    // now remove it from the map.
                    profiles.remove(profileName);
                    continue;
                }
                reader = new BufferedReader(new InputStreamReader(new FileInputStream(prefsJS)));
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("user_pref(\"")) { //$NON-NLS-1$
                        int idx = line.indexOf("\"", 11); //$NON-NLS-1$
                        if (idx == -1)
                            continue;
                        String pref = line.substring(11, idx);

                        // Save this position
                        int pos = idx + 1;

                        // Look for another quote
                        idx = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                        String value;
                        if (idx == -1) {
                            // No more quotes
                            idx = line.indexOf(" ", pos); //$NON-NLS-1$

                            if (idx == -1)
                                continue;

                            int idx2 = line.indexOf(")", pos); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);

                        } else {

                            // String value
                            int idx2 = line.indexOf("\"", idx + 1); //$NON-NLS-1$

                            if (idx2 == -1)
                                continue;

                            value = line.substring(idx + 1, idx2);
                        }

                        props.put(pref, value);

                    }
                }
            } finally {
                if (reader != null) {
                    reader.close();
                }
            }
            ProxyInfo p;
            /**
             * Extract some proxies from the properites, if the proxy is
             * enabled
             */
            if ("1".equals(props.get("network.proxy.type"))) { //$NON-NLS-1$ //$NON-NLS-2$
                boolean isProfileActive = checkProfileActive(prefsJS);
                if (props.containsKey("network.proxy.ftp")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ftp=" + props.get("network.proxy.ftp") + ":" + props.get("network.proxy.ftp_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.http")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "http=" + props.get("network.proxy.http") + ":" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    + props.get("network.proxy.http_port"), //$NON-NLS-1$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.ssl")) { //$NON-NLS-1$
                    p = createProxyInfo(
                            "ssl=" + props.get("network.proxy.ssl") + ":" + props.get("network.proxy.ssl_port"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                            "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.socks")) { //$NON-NLS-1$
                    p = createProxyInfo("socks=" + props.get("network.proxy.socks") + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                            + props.get("network.proxy.socks_port"), "Firefox Profile [" + profileName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    p.setActiveProfile(isProfileActive);
                    proxies.addElement(p);
                }

                if (props.containsKey("network.proxy.no_proxies_on")) { //$NON-NLS-1$

                    StringTokenizer tokens = new StringTokenizer(
                            props.getProperty("network.proxy.no_proxies_on"), ","); //$NON-NLS-1$ //$NON-NLS-2$

                    while (tokens.hasMoreTokens()) {
                        bypassAddr.addElement(((String) tokens.nextToken()).trim());
                    }

                }
            }
        }

        // need to ensure that the returned values are sorted correctly...
        BrowserProxySettings bps = new BrowserProxySettings();
        bps.setBrowser("Mozilla Firefox"); //$NON-NLS-1$
        bps.setProxiesActiveFirst(proxies);
        bps.setBypassAddr(new String[bypassAddr.size()]);
        bypassAddr.copyInto(bps.getBypassAddr());
        return bps;

    } catch (Throwable t) {
        throw new IOException("Failed to get proxy information from Firefox profiles: " + t.getMessage()); //$NON-NLS-1$
    }
}

From source file:ORG.oclc.os.SRW.SRWDatabase.java

/**
 * Look for indexes with context sets and construct a new index entry
 * without the context set.  If the new index is unique, keep it.
 *///  ww  w  .  ja v  a  2s  . c  o  m
static protected void makeUnqualifiedIndexes(Properties props) {
    Enumeration enumer = props.propertyNames();
    Hashtable<String, String> newIndexes = new Hashtable<String, String>();
    int start;
    String name, newName, value;
    while (enumer.hasMoreElements()) {
        name = (String) enumer.nextElement();
        if (name.startsWith("qualifier.")) {
            if ((start = name.indexOf('.', 11)) > 0) {
                newName = "hiddenQualifier." + name.substring(start + 1);
                log.debug("checking for " + newName);
                if (newIndexes.get(newName) != null) { // already got one
                    log.debug("dropping " + newName);
                    newIndexes.remove(newName); // so throw it away
                } else {
                    log.debug("keeping " + newName);
                    newIndexes.put(newName, (String) props.get(name));
                }
            }
        }
    }
    enumer = newIndexes.keys();
    while (enumer.hasMoreElements()) {
        name = (String) enumer.nextElement();
        value = newIndexes.get(name);
        if (value != null) {
            log.debug("adding: " + name + "=" + value);
            props.put(name, value);
        }
    }
}

From source file:edu.ku.brc.specify.utilapps.RegProcessor.java

/**
 * @param inFile//from   w ww  .j a  va2  s  .  com
 */
public void processSQL() {
    String sql = "SELECT r.RegisterID, r.RegNumber, ri.Name, ri.Value, ri.CountAmt, r.TimestampCreated, r.IP"
            + " FROM register r INNER JOIN registeritem ri ON r.RegisterID = ri.RegisterID WHERE r.TimestampCreated > '2009-04-12' ORDER BY r.RegNumber";
    System.err.println(sql);
    //Connection connection = DBConnection.getInstance().getConnection();
    try {
        stmt = DBConnection.getInstance().getConnection().createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        int prevId = Integer.MAX_VALUE;
        RegProcEntry currEntry = null;
        while (rs.next()) {
            int id = rs.getInt(1);
            if (id != prevId) {
                if (currEntry != null) {
                    String regType = currEntry.get("reg_type");
                    if (regType != null) {
                        Hashtable<String, RegProcEntry> entryHash = typeHash.get(regType);
                        if (entryHash == null) {
                            entryHash = new Hashtable<String, RegProcEntry>();
                            typeHash.put(regType, entryHash);
                        }
                        currEntry.put("reg_number", currEntry.getId());
                        currEntry.setType(currEntry.get("reg_type"));

                        if (entryHash.get(currEntry.getId()) == null) {
                            entryHash.put(currEntry.getId(), currEntry);
                        } else {
                            System.err.println("Already there: " + currEntry.getId());
                        }
                    } else {
                        System.err.println("1Skipping: " + rs.getString(2));
                    }
                }

                String regNumber = rs.getString(2);
                String ip = rs.getString(7);
                currEntry = regNumHash.get(regNumber);
                if (currEntry == null) {
                    if (ip != null) {
                        currEntry = new RegProcEntry();
                        regNumHash.put(regNumber, currEntry);
                        currEntry.setId(regNumber);
                        currEntry.setTimestampCreated(rs.getTimestamp(6));
                        currEntry.put("ip", ip);

                    } else {
                        System.err.println("IP is null for " + regNumber);
                        ip = "N/A";
                    }

                } else {
                    System.err.println("Already " + regNumber);
                }

                prevId = id;

            } else if (prevId == Integer.MAX_VALUE) {
                prevId = id;
            }

            String value = rs.getString(4);
            if (value == null) {
                value = rs.getString(5);
            }

            String propName = rs.getString(3);
            if (currEntry != null && value != null && propName != null) {
                currEntry.put(propName, value);
            }
        }
        rs.close();

        Hashtable<String, RegProcEntry> checkHash = new Hashtable<String, RegProcEntry>();
        Hashtable<String, RegProcEntry> instHash = typeHash.get("Institution");

        for (RegProcEntry entry : new Vector<RegProcEntry>(regNumHash.values())) {
            entry.setName(null);
            String ip = entry.get("ip");
            if (ip == null || ip.startsWith("129.") || ip.startsWith("24.")) {
                System.out.println("Removing ip: " + ip);
                instHash.remove(entry.getId());
                regNumHash.remove(entry.getId());

            } else {
                RegProcEntry e = checkHash.get(ip);
                if (e == null) {
                    checkHash.put(ip, entry);
                } else {
                    instHash.remove(e.getId());
                    regNumHash.remove(e.getId());
                    checkHash.put(ip, entry);
                    System.out.println("Compressing ip: " + ip);
                }
            }
        }

        buildTree();

    } catch (SQLException ex) {
        ex.printStackTrace();

    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:org.hdiv.filter.ValidatorHelperRequest.java

/**
 * Check if all required parameters are received in <code>request</code>.
 * /*from w  w  w.j  a v a 2  s  . c o  m*/
 * @param request
 *            HttpServletRequest to validate
 * @param state
 *            IState The restored state for this url
 * @param target
 *            Part of the url that represents the target action
 * @return valid result if all required parameters are received. False in otherwise.
 */
private ValidatorHelperResult allRequiredParametersReceived(HttpServletRequest request, IState state,
        String target) {

    Hashtable receivedParameters = new Hashtable(state.getRequiredParams());

    String currentParameter = null;
    Enumeration requestParameters = request.getParameterNames();
    while (requestParameters.hasMoreElements()) {

        currentParameter = (String) requestParameters.nextElement();
        if (receivedParameters.containsKey(currentParameter)) {
            receivedParameters.remove(currentParameter);
        }

        // If multiple parameters are received, it is possible to pass this
        // verification without checking all the request parameters.
        if (receivedParameters.size() == 0) {
            return ValidatorHelperResult.VALID;
        }
    }

    if (receivedParameters.size() > 0) {
        this.logger.log(HDIVErrorCodes.REQUIRED_PARAMETERS, target, receivedParameters.keySet().toString(),
                null);
        return new ValidatorHelperResult(HDIVErrorCodes.REQUIRED_PARAMETERS);
    }

    return ValidatorHelperResult.VALID;
}

From source file:com.autentia.intra.bean.account.AccountEntryBean.java

private void calcTotals(List<AccountEntry> res) {
    costs = new BigDecimal(0);
    incomes = new BigDecimal(0);

    costsType = new BigDecimal(0);
    incomesType = new BigDecimal(0);

    Hashtable mapaCajaTotales = new Hashtable();

    for (AccountEntry elem : res) {
        Integer accountAct = elem.getAccount().getId();
        BigDecimal accountValueAct = null;
        if (!mapaCajaTotales.containsKey(accountAct)) {
            mapaCajaTotales.put(accountAct, new BigDecimal(0));
        }/*from  w ww. ja v a2 s  .c o m*/

        accountValueAct = (BigDecimal) mapaCajaTotales.get(accountAct);

        BigDecimal actual = elem.getAmount();
        BigDecimal resul = accountValueAct.add(actual);
        elem.setAmountAccountNow(resul);
        mapaCajaTotales.remove(accountAct);
        mapaCajaTotales.put(accountAct, resul);

        if (actual.signum() >= 0) {
            setIncomes(incomes.add(actual));
        } else {
            setCosts(costs.add(actual));
        }

        if (elem.getType().getGroup().getId() == ConfigurationUtil.getDefault().getCostId()) {
            setCostsType(costsType.add(actual));
        } else {
            setIncomesType(incomesType.add(actual));
        }
    }

    setTotal(incomes.add(costs));
    setTotalType(incomesType.add(costsType));
}

From source file:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the cumulative resource usage across all
 * projects./*from w  ww . j a  v  a2  s. c om*/
 * 
 * @param projectCollabTable
 * @return
 */
@SuppressWarnings("unused")
private DefaultPieDataset createResourceDataset(
        Hashtable<ProjectBean, List<CollaboratorBean>> projectCollabTable, CollaboratorBean collab) {

    DefaultPieDataset pds = new DefaultPieDataset();

    Hashtable<String, Double> resourceUsageTable = new Hashtable<String, Double>();

    // for each project find the collaborator's usage on each resource
    for (ProjectBean project : projectCollabTable.keySet()) {

        List<CollaboratorBean> collabs = projectCollabTable.get(project);

        if (projectCollabTable.get(project).contains(collab)) {

            CollaboratorBean projectCollab = projectCollabTable.get(project)
                    .get(projectCollabTable.get(project).indexOf(collab));

            for (String systemName : projectCollab.getUsageTable().keySet()) {

                if (resourceUsageTable.containsKey(systemName)) {
                    double previousUsage = resourceUsageTable.get(systemName).doubleValue();
                    resourceUsageTable.remove(systemName);
                    resourceUsageTable.put(systemName, new Double(
                            previousUsage + projectCollab.getUsageTable().get(systemName).getUsed()));
                } else {
                    resourceUsageTable.put(systemName,
                            new Double(projectCollab.getUsageTable().get(systemName).getUsed()));
                }
            }
        }
    }

    // now put the tallies in the dataset
    for (String systemName : resourceUsageTable.keySet()) {
        pds.setValue(systemName, resourceUsageTable.get(systemName).doubleValue());
    }

    return pds;
}