Example usage for java.util Hashtable keySet

List of usage examples for java.util Hashtable keySet

Introduction

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

Prototype

Set keySet

To view the source code for java.util Hashtable keySet.

Click Source Link

Document

Each of these fields are initialized to contain an instance of the appropriate view the first time this view is requested.

Usage

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

/**
 * Returns a dataset representing the cumulative resource usage across all
 * projects./*  w ww .j a  va2 s .  c o m*/
 * 
 * @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;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.cotijob.CotiJobDetailHandler.java

private void changeFileListByXliff(List<String> p_fileList, String p_file, FileProfile p_fileProfile) {
    Hashtable<String, FileProfile> subFiles = new Hashtable<String, FileProfile>();
    String tmp = "";
    XliffFileUtil.processMultipleFileTags(subFiles, p_file, p_fileProfile);
    for (Iterator<String> iterator = subFiles.keySet().iterator(); iterator.hasNext();) {
        tmp = iterator.next();/*from  w  ww .  jav  a 2s .  c o  m*/
        p_fileList.add(tmp);
    }
}

From source file:edu.ku.brc.specify.datamodel.SpUIViewDef.java

/**
 * @param enableRulesArg/*from w w w . j  a va2s . c  o  m*/
 * @return
 */
protected String createEnableRulesXML(final Hashtable<String, String> enableRulesArg) {
    if (enableRulesArg.keySet().size() > 0) {
        StringBuilder sb = new StringBuilder("<enableRules>");
        for (String key : enableRulesArg.keySet()) {
            sb.append("<rule id=\"");
            sb.append(key);
            sb.append("\"><![CDATA[");
            sb.append(enableRulesArg.get(key));
            sb.append("]]></rule>");
        }
        sb.append("</enableRules>");
        return sb.toString();
    }
    return null;
}

From source file:org.apache.torque.util.BasePeer.java

/**
 * Converts a hashtable to a byte array for storage/serialization.
 *
 * @param hash The Hashtable to convert.
 * @return A byte[] with the converted Hashtable.
 * @exception TorqueException/*from w  w  w  .  j a v  a 2 s . c  o m*/
 */
public static byte[] hashtableToByteArray(Hashtable hash) throws TorqueException {
    Hashtable saveData = new Hashtable(hash.size());
    String key = null;
    Object value = null;
    byte[] byteArray = null;

    Iterator keys = hash.keySet().iterator();
    while (keys.hasNext()) {
        key = (String) keys.next();
        value = hash.get(key);
        if (value instanceof Serializable) {
            saveData.put(key, value);
        }
    }

    ByteArrayOutputStream baos = null;
    BufferedOutputStream bos = null;
    ObjectOutputStream out = null;
    try {
        // These objects are closed in the finally.
        baos = new ByteArrayOutputStream();
        bos = new BufferedOutputStream(baos);
        out = new ObjectOutputStream(bos);

        out.writeObject(saveData);
        out.flush();
        bos.flush();
        byteArray = baos.toByteArray();
    } catch (Exception e) {
        throw new TorqueException(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException ignored) {
            }
        }

        if (bos != null) {
            try {
                bos.close();
            } catch (IOException ignored) {
            }
        }

        if (baos != null) {
            try {
                baos.close();
            } catch (IOException ignored) {
            }
        }
    }
    return byteArray;
}

From source file:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java

/** This method calculates all roots for the given messages in messageData
 * and stores this information in the database
 * @param messages a list of Messages/*from www.ja  va 2s.c om*/
 * @throws SQLException if there was an error with the database
 */
private void calculateRoots(List<MM2Message> messages, Connection connection) throws SQLException {
    // Needed Data Structures
    Hashtable<String, String> parentsTable = new Hashtable<String, String>();
    Hashtable<String, String> rootsTable = new Hashtable<String, String>();

    // Build up parents table form database
    String query = "SELECT * FROM parent";
    Statement stmt = connection.createStatement();
    ResultSet results = stmt.executeQuery(query);
    while (results.next()) {
        parentsTable.put(results.getString("msg_id"), results.getString("parent_id"));
    }

    Main.getLogger().debug(3, parentsTable.keySet().size() + " parent relations are known!");

    // Calculate all roots
    for (MM2Message msg : messages) {
        String msgUID = msg.getHeaderEntry("msg_id");
        String rootUID = msgUID;
        if (parentsTable.containsKey(msgUID)) {
            Set<String> seenParents = new HashSet<String>();

            String myParent = parentsTable.get(msgUID);
            seenParents.add(myParent);
            while (myParent != null) {
                rootUID = myParent;
                myParent = parentsTable.get(myParent);
                if (seenParents.contains(myParent)) {
                    Main.getLogger().log("Parents Cycle: " + rootUID + " " + myParent);
                    break;
                } else {
                    seenParents.add(myParent);
                }
            }
        }
        rootsTable.put(msgUID, rootUID);
    }
    Main.getLogger().log("Storing " + rootsTable.keySet().size() + " roots in database...");
    storeRoots(rootsTable, connection);
}

From source file:org.kepler.objectmanager.library.LibraryManager.java

private void copyAttributes(LibItem li, ComponentEntity ce) {
    Hashtable<String, String> attributes = li.getAttributes();
    for (String key : attributes.keySet()) {
        String value = attributes.get(key);
        try {/*from  w  w  w .  j  a  va  2  s. c om*/
            StringAttribute sa = new StringAttribute(ce, key);
            sa.setExpression(value);
        } catch (IllegalActionException e) {
            e.printStackTrace();
        } catch (NameDuplicationException e) {
            e.printStackTrace();
        }
    }
}

From source file:hr.restart.util.chart.ChartXY.java

/**
 * //from  www  . j ava 2s .co m
 * @return String[], with all captions from the DataSet
 */
private String[] makeCaptions() {

    Hashtable hcols = new Hashtable();
    Column[] ccols = getDataSet().getColumns();
    for (int i = 0; i < ccols.length; i++) {
        //System.out.println("checking "+ccols[i].getColumnName());
        if (ccols[i].getDataType() == Variant.BIGDECIMAL) {
            hcols.put(ccols[i].getColumnName(), ccols[i].getCaption());
        }
    }

    colNamesY = (String[]) hcols.keySet().toArray(new String[0]);
    String[] colCaptionsY = new String[hcols.size()];
    for (int i = 0; i < colNamesY.length; i++) {
        colCaptionsY[i] = hcols.get(colNamesY[i]).toString();
    }

    return colCaptionsY;
}

From source file:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java

/**
 * This method stores the root associations of a roots table into the database
 * @param roots a list of roots associations
 * @throws SQLException/*from   w  w  w .j a  v a  2s  .c  o m*/
 */
private void storeRoots(Hashtable<String, String> roots, Connection connection) throws SQLException {
    // Use StringBuilders to create big insertion queries

    StringBuilder rootQueryBuilder = new StringBuilder();

    // Queries use the pgpsql functions
    // merge_parent(int msg_uid, int parent_uid)
    // merge_root(int msg_uid, int root_uid)
    // that take care of insertion / update automatically

    rootQueryBuilder.append("PREPARE rootplan (int, int) AS SELECT merge_root($1, $2);");
    // Genereate the roots query
    int i = 0;
    for (String key : roots.keySet()) {
        rootQueryBuilder.append("EXECUTE rootplan (" + key + ", " + roots.get(key) + ");"
                + System.getProperty("line.separator"));
        i++;
        if ((i % 1000) == 0) {
            i = 0;
            rootQueryBuilder.append("DEALLOCATE rootplan;" + System.getProperty("line.separator"));
            String sqlstr = rootQueryBuilder.toString();
            Statement statement = connection.createStatement();
            statement.execute(sqlstr);
            statement.close();
            rootQueryBuilder.delete(0, rootQueryBuilder.length());
            rootQueryBuilder.append("PREPARE rootplan (int, int) AS SELECT merge_root($1, $2);");
            Main.getLogger().debug(4, "Stored 1000 root relations!");
        }
    }
    if (i > 0) {
        rootQueryBuilder.append("DEALLOCATE rootplan;" + System.getProperty("line.separator"));
        String sqlstr = rootQueryBuilder.toString();
        Statement statement = connection.createStatement();
        statement.execute(sqlstr);
        statement.close();
        Main.getLogger().debug(4, "Stored " + i + " root relations!");
    }
}

From source file:ca.queensu.cs.sail.mailboxmina2.main.modules.ThreadsModule.java

/**
 * This method stores associations of parents given as Hash Table
 * in the Database/*ww  w.  ja va  2 s. c  om*/
 * 
 * @param parents
 *            a table that maps for every method having a parent this
 *            parent's ID
 * @throws SQLException
 */
private void storeParents(Hashtable<String, String> parents, Connection connection) throws SQLException {
    // Use StringBuilders to create big insertion queries

    StringBuilder parentQueryBuilder = new StringBuilder();

    // Queries use the pgpsql functions
    // merge_parent(int msg_uid, int parent_uid)
    // merge_root(int msg_uid, int root_uid)
    // that take care of insertion / update automatically

    parentQueryBuilder.append("PREPARE parentplan (int, int) AS SELECT merge_parent($1, $2);");
    // Genereate the parents query
    int i = 0;
    for (String key : parents.keySet()) {
        parentQueryBuilder.append("EXECUTE parentplan (" + key + ", " + parents.get(key) + ");"
                + System.getProperty("line.separator"));
        i++;
        if ((i % 1000) == 0) {
            i = 0;
            parentQueryBuilder.append("DEALLOCATE parentplan;" + System.getProperty("line.separator"));
            String sqlstr = parentQueryBuilder.toString();
            Statement statement = connection.createStatement();
            statement.execute(sqlstr);
            statement.close();
            parentQueryBuilder.delete(0, parentQueryBuilder.length());
            parentQueryBuilder.append("PREPARE parentplan (int, int) AS SELECT merge_parent($1, $2);");
            Main.getLogger().debug(4, "Stored 1000 parent relations!");
        }
    }
    if (i > 0) {
        parentQueryBuilder.append("DEALLOCATE parentplan;" + System.getProperty("line.separator"));
        String sqlstr = parentQueryBuilder.toString();
        Statement statement = connection.createStatement();
        statement.execute(sqlstr);
        statement.close();
        Main.getLogger().debug(4, "Stored " + i + " parent relations!");
    }
}

From source file:com.stimulus.archiva.extraction.MessageExtraction.java

protected String extractMessage(Email message) throws MessageExtractionException {

    if (message == null)
        throw new MessageExtractionException("assertion failure: null message", logger);

    logger.debug("extracted message {" + message + "}");

    Hashtable<String, Part> att = new Hashtable<String, Part>();
    Hashtable<String, String> inl = new Hashtable<String, String>();
    Hashtable<String, String> imgs = new Hashtable<String, String>();
    Hashtable<String, String> nonImgs = new Hashtable<String, String>();
    Hashtable<String, String> ready = new Hashtable<String, String>();
    ArrayList<String> mimeTypes = new ArrayList<String>();
    String viewFileName;/*  ww w.  j  a  v  a  2  s.  co m*/
    try {
        dumpPart(message, att, inl, imgs, nonImgs, mimeTypes, message.getSubject());
        for (String attachFileName : att.keySet()) {
            Part p = (Part) att.get(attachFileName);
            writeAttachment(p, attachFileName);
            ready.put(attachFileName, attachFileName);
            //if (!imgs.containsKey(attachFileName) && !nonImgs.containsKey(attachFileName))
            addAttachment(attachFileName, p);
        }

        if (inl.containsKey("text/html")) {
            viewFileName = prepareHTMLMessage(baseURL, inl, imgs, nonImgs, ready, mimeTypes);
        } else if (inl.containsKey("text/plain")) {
            viewFileName = preparePlaintextMessage(inl, imgs, nonImgs, ready, mimeTypes);
        } else {
            logger.debug(
                    "unable to extract message since the content type is unsupported. returning empty message body.");
            return writeTempMessage("<html><head><META http-equiv=Content-Type content=\"text/html; charset="
                    + serverEncoding + "\"></head><body></body></html>", ".html");
        }
    } catch (Exception ex) {
        throw new MessageExtractionException(ex.getMessage(), ex, logger);
    }
    logger.debug("message successfully extracted {filename='" + fileName + "' " + message + "}");
    return viewFileName;
}