Example usage for java.util Hashtable get

List of usage examples for java.util Hashtable get

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:io.cloudslang.content.database.services.dbconnection.DBConnectionManager.java

/**
 * @param aDbType   one of the supported db type, for example ORACLE, NETCOOL
 * @param aDbUrl    connection url//from   w w  w  .j a  v  a 2s  .c  om
 * @param aUsername username to connect to db
 * @param aPassword password to connect to db
 * @return a db Connection which is pooled
 * @throws SQLException
 */
protected Connection getPooledConnection(DBType aDbType, String aDbUrl, String aUsername, String aPassword)
        throws SQLException {
    Connection retCon;

    //key to hashtable of datasources for that dbms
    String dbmsKey = aDbType + "." + aDbUrl;

    if (dbmsPoolTable.containsKey(dbmsKey)) {

        //each pool has pooled datasources, pool is based on dbUrl
        //so we can control the total size of connection to dbms
        Hashtable<String, DataSource> dsTable = dbmsPoolTable.get(dbmsKey);

        String encryptedPass;
        try {
            encryptedPass = TripleDES.encryptPassword(aPassword);
        } catch (Exception e) {
            throw new SQLException("Failed to encrypt password for key = " + dbmsKey, e);
        }

        String dsTableKey = aDbUrl + "." + aUsername + "." + encryptedPass;

        DataSource ds;
        if (dsTable.containsKey(dsTableKey)) {

            ds = dsTable.get(dsTableKey);
            retCon = ds.getConnection();
        } else {

            //need to check if it is ok to create another ds
            ds = this.createDataSource(aDbType, aDbUrl, aUsername, aPassword, dsTable);
            retCon = ds.getConnection();

            dsTable.put(dsTableKey, ds);
        }
    } else//don't have dbmsKey, will create one for that dbtype.dburl
    {

        //just create, don't need to check, since we don't have this dbmsKey
        PooledDataSource ds = (PooledDataSource) this.createDataSource(aDbType, aDbUrl, aUsername, aPassword);
        retCon = getPooledConnection(ds, aUsername, aPassword);

        Hashtable<String, DataSource> dsTable = new Hashtable<>();
        String encryptedPass;
        try {
            encryptedPass = TripleDES.encryptPassword(aPassword);
        } catch (Exception e) {
            throw new SQLException("Failed to encrypt password for key = " + dbmsKey, e);
        }
        String dsTableKey = aDbUrl + "." + aUsername + "." + encryptedPass;
        dsTable.put(dsTableKey, ds);
        dbmsPoolTable.put(dbmsKey, dsTable);
    }
    return retCon;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test counts for each product area. 
 *
 * @param   builds   List of builds/*from   w  w  w . ja va  2 s  . co  m*/
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAreaTestCountChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Integer>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Integer testCount = new Integer(suite.getTestCount());

            // Parse the build information so we can track the time by build
            Hashtable<String, Integer> areaCount = null;
            if (buildTotals.containsKey(buildId)) {
                areaCount = (Hashtable) buildTotals.get(buildId);
            } else {
                areaCount = new Hashtable<String, Integer>();
                buildTotals.put(buildId, areaCount);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Integer totalValue = null;
            String areaName = area.getDisplayName();
            if (areaCount.containsKey(areaName)) {
                Integer oldTotal = (Integer) areaCount.get(areaName);
                totalValue = oldTotal + testCount;
            } else {
                totalValue = testCount;
            }
            areaCount.put(areaName, totalValue);

        } // while list has elements

        // Make sure every area is represented in the build totals
        Enumeration bt = buildTotals.keys();
        while (bt.hasMoreElements()) {
            // Get the build ID for the current build
            Integer bid = (Integer) bt.nextElement();

            // Get the list of area totals for the current build
            Hashtable<String, Integer> ac = (Hashtable<String, Integer>) buildTotals.get(bid);
            Iterator a = areas.iterator();
            while (a.hasNext()) {
                // Add a value of zero if no total was found for the current area
                CMnDbFeatureOwnerData area = (CMnDbFeatureOwnerData) a.next();
                if (!ac.containsKey(area.getDisplayName())) {
                    ac.put(area.getDisplayName(), new Integer(0));
                }
            }
        }

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Enumeration bList = builds.elements();
        while (bList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) bList.nextElement();
            Integer buildId = new Integer(build.getId());
            Hashtable areaCount = (Hashtable) buildTotals.get(buildId);

            Enumeration areaKeys = areaCount.keys();
            while (areaKeys.hasMoreElements()) {
                String area = (String) areaKeys.nextElement();
                Integer count = (Integer) areaCount.get(area);
                dataset.addValue(count, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Test Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

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// w  ww.  j av  a2  s  .  co m
 * 
 * @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:edu.ku.brc.specify.utilapps.ERDVisualizer.java

/**
 * @param table/*from   ww  w .ja  va2 s. c  o  m*/
 * @param level
 */
protected void processAsTree(final ERDTable table, final int level) {
    //System.out.println("["+table.getClassName()+"]");

    NodeInfo ni = tblTracker.getNodeInfo(table);

    boolean skip = false;
    if (ni.getOkWhenParent() != null) {
        skip = ni.getOkWhenParent() != table.getTreeParent();
    }

    if (ni.isSkip()) {
        tblTracker.getUsedHash().put(table.getClassName(), true);
        return;
    }

    if (skip || !ni.isAlwaysAKid() || tblTracker.getUsedHash().get(table) != null) {
        return;
    }

    /* DEBUG
    if (table.getClassName().indexOf("Taxon") > 0)
    {
    System.out.println(table.getClassName());
    }
            
    if (table.getClassName().indexOf("ReferenceWork") > 0)
    {
    System.out.println(table.getClassName());
    for (ERDTable t : ni.getKids())
    {
        System.out.println(ni.getClassName()+ " " + t.getClassName());
    }
    }*/

    Dimension tableSize = table.getPreferredSize();
    table.getSpace().width = tableSize.width;
    table.getSpace().height = tableSize.height;

    int maxHeight = 0;
    int maxWidth = 0;

    if (ni.isProcessKids() || ni.getKids().size() > 0) {
        Hashtable<String, Boolean> usedRelClasses = new Hashtable<String, Boolean>();
        for (DBRelationshipInfo r : table.getTable().getRelationships()) {
            ERDTable rTable = tblTracker.getHash().get(r.getClassName());
            if (rTable == null) {
                continue;
            }

            if (usedRelClasses.get(r.getClassName()) != null) {
                continue;
            }
            usedRelClasses.put(r.getClassName(), true);

            NodeInfo kni = tblTracker.getNodeInfo(rTable);

            boolean kidOK = true;
            boolean override = false;
            if (!ni.isProcessKids()) {
                kidOK = ni.getKids().contains(rTable);
                override = true;

            } else {
                if (kni.isSkip()) {
                    tblTracker.getUsedHash().put(rTable.getClassName(), true);
                    continue;
                }

                if (ni.getKids().contains(rTable)) {
                    override = true;
                }
            }

            if (kni.isOkToDuplicate()) {
                System.out.println("Duplicating [" + rTable.getClassName() + "]");
                rTable = rTable.duplicate(tblTracker.getFont());
            }

            if (kidOK && (override || r.getType() == DBRelationshipInfo.RelationshipType.OneToMany)) {
                //System.out.println("    ["+rTable.getClassName()+"]");

                if (table.addKid(rTable)) {
                    rTable.setTreeParent(table);
                    processAsTree(rTable, level + 1);

                    Dimension size = rTable.getSpace();
                    maxWidth += size.width + 10;
                    maxHeight = Math.max(maxHeight, size.height + VGAP);
                }
            }
        }
    }

    //System.out.println(level+"   mw "+maxWidth+"  mh "+ maxHeight+ "  " + table.getKids().size());
    table.getSpace().width = Math.max(tableSize.width, maxWidth);
    table.getSpace().height = tableSize.height + maxHeight;
    System.out.println(
            "Table " + table.getClassName() + " " + table.getSpace().width + " " + table.getSpace().height);
    tblTracker.getUsedHash().put(table.getClassName(), true);
}

From source file:de.nava.informa.parsers.RSS_2_0_Parser.java

private CategoryIF getCategoryList(CategoryIF parent, String title, Hashtable children) {
    // Assuming category hierarchy for each category element
    // is already mapped out into Hashtable tree;  Hense the children Hashtable

    // create channel builder to help create CategoryIF objects
    ChannelBuilder builder = new ChannelBuilder();

    // create current CategoryIF object; Parent may be null if at top level
    CategoryIF cat = builder.createCategory(parent, title);
    // iterate off list of keys from children list
    Enumeration itChild = children.keys();
    while (itChild.hasMoreElements()) {
        String childKey = (String) itChild.nextElement();
        // don't need to keep track of return CategoryIF since it will be added as child of another instance
        getCategoryList(cat, childKey, (Hashtable) children.get(childKey));
    }/*from  w ww.  j a v a 2  s . co m*/
    return cat;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a stacked bar graph representing test execution time for each 
 * product area. /*from   ww w. j  a  v a  2  s. c o m*/
 *
 * @param   builds   List of builds
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * 
 * @return  Stacked bar chart representing test execution times across all builds 
 */
public static final JFreeChart getAreaTestTimeChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the total times for each build, organized by area
    // This hashtable maps a build to the area/time information for that build
    Hashtable<Integer, Hashtable> buildTotals = new Hashtable<Integer, Hashtable>();

    // Generate placeholders for each build so the chart maintains a 
    // format consistent with the other charts that display build information
    HashSet areaNames = new HashSet();
    if (builds != null) {
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            // Create the empty area list
            buildTotals.put(new Integer(build.getId()), new Hashtable<String, Long>());
        }
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect build test numbers for each of the builds in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the test summary for the current build
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Integer buildId = new Integer(suite.getParentId());
            Long elapsedTime = new Long(suite.getElapsedTime());

            // Parse the build information so we can track the time by build
            Hashtable<String, Long> areaTime = null;
            if (buildTotals.containsKey(buildId)) {
                areaTime = (Hashtable) buildTotals.get(buildId);
            } else {
                areaTime = new Hashtable<String, Long>();
                buildTotals.put(buildId, areaTime);
            }

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData area = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                CMnDbFeatureOwnerData currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    area = currentArea;
                }
            }

            // Add the elapsed time for the current suite to the area total
            Long totalValue = null;
            String areaName = area.getDisplayName();
            areaNames.add(areaName);
            if (areaTime.containsKey(areaName)) {
                Long oldTotal = (Long) areaTime.get(areaName);
                totalValue = oldTotal + elapsedTime;
            } else {
                totalValue = elapsedTime;
            }
            areaTime.put(areaName, totalValue);

        } // while list has elements

        // Populate the data set with the area times for each build
        Collections.sort(builds, new CMnBuildIdComparator());
        Iterator buildIter = builds.iterator();
        while (buildIter.hasNext()) {
            CMnDbBuildData build = (CMnDbBuildData) buildIter.next();
            Integer buildId = new Integer(build.getId());
            Hashtable areaTime = (Hashtable) buildTotals.get(buildId);

            Iterator areaKeys = areaNames.iterator();
            while (areaKeys.hasNext()) {
                String area = (String) areaKeys.next();
                Long time = (Long) areaTime.get(area);
                if (time != null) {
                    // Convert the time from milliseconds to minutes
                    time = time / (1000 * 60);
                } else {
                    time = new Long(0);
                }
                dataset.addValue(time, area, buildId);
            }
        }

    } // if list has elements

    // API: ChartFactory.createStackedBarChart(title, domainAxisLabel, rangeAxisLabel, dataset, orientation, legend, tooltips, urls)
    chart = ChartFactory.createStackedBarChart("Automated Tests by Area", "Builds", "Execution Time (min)",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    // get a reference to the plot for further customization...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, dataset);

    return chart;
}

From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java

/**
 * Fill the Vector with all the views from the DOM document
 * @param doc the DOM document conforming to form.xsd
 * @param views the list to be filled/*from   w  ww.j av a2  s  . co m*/
 * @throws Exception for duplicate view set names or if a Form ID is not unique
 */
public static String getViews(final Element doc, final Hashtable<String, ViewIFace> views,
        final Hashtable<AltViewIFace, String> altViewsViewDefName) throws Exception {
    instance.viewSetName = doc.attributeValue(NAME);

    /*
    System.err.println("#################################################");
    System.err.println("# "+instance.viewSetName);
    System.err.println("#################################################");
    */

    Element viewsElement = (Element) doc.selectSingleNode("views");
    if (viewsElement != null) {
        for (Iterator<?> i = viewsElement.elementIterator("view"); i.hasNext();) {
            Element element = (Element) i.next(); // assume element is NOT null, if it is null it will cause an exception
            ViewIFace view = createView(element, altViewsViewDefName);

            if (view != null) {
                if (views.get(view.getName()) == null) {
                    views.put(view.getName(), view);
                } else {
                    String msg = "View Set [" + instance.viewSetName + "] [" + view.getName()
                            + "] is not unique.";
                    log.error(msg);
                    FormDevHelper.appendFormDevError(msg);
                }
            }
        }
    }

    return instance.viewSetName;
}

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  w  w.j  a v a 2  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:com.flexive.tests.browser.AdmContentTest.java

/**
 * fill in a current query (must be loaded)
 * @param pName parameter name//www. j  a va2s. com
 * @param value value
 */
private void fillInQuery(String pName, Object value) {
    int trys = 4;

    while (trys-- > 0) {
        try {
            selectFrame(Frame.Content);
            String html = correctHTML(selenium.getHtmlSource(), "<table ", "</table>");
            int i1, i1_, i2;
            int begin = html.indexOf("<table ");
            i1 = html.indexOf("id=\"queryEditorRoot\"", begin);
            i1_ = html.indexOf("id=queryEditorRoot", begin);
            i1 = Math.max(i1, i1_);
            i2 = html.indexOf(">", begin);
            if (i1 > i2 || i1 < 0) {
                throw new ResultTableNotFoundException(writeHTMLtoHD("wrongResultTable", LOG, html));
            }
            Hashtable<String, String> input;
            if (begin > 0) {
                int ende = html.indexOf("</table>", begin);
                if (ende < 0)
                    throw new ResultTableNotFoundException(writeHTMLtoHD("wrongResultTable", LOG, html));
                input = getInput(html.substring(begin, ende), pName, "id", "type");
                if (input.get("type").equals("text")) {
                    selenium.type(input.get("id"), value.toString());
                }
            } else {
                throw new ResultTableNotFoundException(writeHTMLtoHD("wrongResultTable", LOG, html));
            }
            break;
        } catch (RowNotFoundException rnfe) {
            sleep(300);
        }
    }
}

From source file:com.alfaariss.oa.authentication.remote.saml2.profile.AbstractAuthNMethodSAML2Profile.java

/**
 * Maps attributes using the configured mapping (if exists).
 *
 * @param source The source attributes, probably from the SAML response.
 * @param target The mapped attributes, to be used by OA.
 * @param mapping The mapping hashtable.
 * @return The mapped attributes.//from   w w w  .j  a  v  a  2 s .c  o  m
 */
protected IAttributes mapAttributes(IAttributes source, IAttributes target, Hashtable<String, String> mapping) {
    Enumeration enumNames = source.getNames();
    while (enumNames.hasMoreElements()) {
        String sName = (String) enumNames.nextElement();
        Object oValue = source.get(sName);
        String sMappedName = mapping.get(sName);
        if (sMappedName != null)
            sName = sMappedName;

        if (_bCompatible) {
            //DD Unspecified name format will be ignored
            String sAttributeNameFormat = source.getFormat(sName);
            if (sAttributeNameFormat != null && sAttributeNameFormat.equals(Attribute.UNSPECIFIED))
                sAttributeNameFormat = null;

            target.put(sName, sAttributeNameFormat, oValue);
        } else {// not using unsupported attribute format
            target.put(sName, oValue);
        }
    }
    return target;
}