Example usage for java.util Hashtable containsKey

List of usage examples for java.util Hashtable containsKey

Introduction

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

Prototype

public synchronized boolean containsKey(Object key) 

Source Link

Document

Tests if the specified object is a key in this hashtable.

Usage

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.//ww w. j ava 2s .c  o  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.panlab.tgw.ptm.iface.ModTypeThread.java

public void run() {
    try {//from ww  w  .ja v a  2  s.  c  om
        //sleep(Integer.parseInt(System.getProperty("singleton.thread")));
        ResourceSpec rs = RepoAdapter.getResourceSpec(m_type, m_ptm_id);
        if (rs != null) {
            log.info("The following Spec is already in the Repository for ptm: " + m_ptm_id);
            log.info(rs.getId());
            log.info(rs.getCommonName());
            log.info(rs.getDescription());
            //log.info(RepoAdapter.createResourceInstance(m_id,rs.getId(),"9"));
            String specID = rs.getConfigurationParameters().getId();
            log.info("-----------" + specID + "-----------");

            Hashtable<String, ConfigParamAtomic> cpaHash = new Hashtable<String, ConfigParamAtomic>();
            ConfigParamAtomic[] cpa = RepoAdapter.getComposite(specID).getConfigParams()
                    .getConfigParamAtomicArray();
            for (int i = 0; i < cpa.length; i++) {
                ConfigParamAtomic tempCPA = RepoAdapter.getAtomic(cpa[i].getId());
                log.info("    " + tempCPA.getCommonName());
                log.info("    " + tempCPA.getConfigParamType());
                log.info("    " + tempCPA.getDescription());
                log.info("    " + tempCPA.getId());
                cpaHash.put(tempCPA.getCommonName(), tempCPA);
            }

            log.info("<Creating Atomic(s) for type" + m_type + ">");
            Object[] elems = XMLUtil.getElements(m_conf);
            String[] atomic_ids = new String[elems.length];
            for (int i = 0; i < elems.length; i++) {
                XMLElement elem = (XMLElement) elems[i];
                if (!cpaHash.containsKey(elem.m_name)) {
                    atomic_ids[i] = RepoAdapter.createAtomic(elem.m_name,
                            elem.m_attributes.get("type").replace("\"", ""), "",
                            "Atomic Parameter Created by Teagle Gateway");
                    log.info(atomic_ids[i]);
                } else {
                    ConfigParamAtomic tempCPA = cpaHash.get(elem.m_name);
                    tempCPA.setConfigParamType(elem.m_attributes.get("type").replace("\"", ""));
                    atomic_ids[i] = tempCPA.getId();
                }
            }
            log.info("</Creating Atomic(s) for type" + m_type + ">");

            log.info("<Updating Composite for type" + m_type + ">");

            String cpc = RepoAdapter.updateComposite(rs.getConfigurationParameters().getId(), m_type,
                    atomic_ids, "Composite Parameter Updated by Teagle Gateway");
            log.info(cpc);
            log.info("</Updating Composite for type" + m_type + ">");

        }

    } catch (Exception error) {
        log.error(error.getMessage());
        error.printStackTrace();
    }
}

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// w ww . j a  va  2s  . c o 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:com.smartmarmot.orabbix.Orabbixmon.java

@Override
public void run() {
    try {/* w  w  w  .j a v a2 s . c om*/
        Configurator cfg = null;
        try {
            cfg = new Configurator(configFile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while creating configurator with " + configFile + " " + e);
        }
        RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
        String pid = rmxb.getName();
        SmartLogger.logThis(Level.INFO,
                Constants.PROJECT_NAME + " started with pid:" + pid.split("@")[0].toString());
        // System.out.print("pid: "+pid.split("@")[0].toString());
        String pidfile = cfg.getPidFile();
        try {
            Utility.writePid(pid.split("@")[0].toString(), pidfile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while trying to write pidfile " + e);
        }

        Locale.setDefault(Locale.US);

        DBConn[] myDBConn = cfg.getConnections();

        if (myDBConn == null) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is null");
            throw new Exception("ERROR on main - Connections is null");

        } else if (myDBConn.length == 0) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is empty");
            throw new Exception("ERROR on main - Connections is empty");
        }

        /**
         * retrieve maxThread
         */
        Integer maxThread = 0;
        try {
            maxThread = cfg.getMaxThread();
        } catch (Exception e) {
            SmartLogger.logThis(Level.WARN,
                    "MaxThread not defined calculated maxThread = " + myDBConn.length * 3);
        }
        if (maxThread == null)
            maxThread = 0;
        if (maxThread == 0) {
            maxThread = myDBConn.length * 3;
        }

        ExecutorService executor = Executors.newFixedThreadPool(maxThread.intValue());
        /**
         * populate qbox
         */
        Hashtable<String, Querybox> qbox = new Hashtable<String, Querybox>();
        for (int i = 0; i < myDBConn.length; i++) {
            Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
            qbox.put(myDBConn[i].getName(), qboxtmp);
        } // for (int i = 0; i < myDBConn.length; i++) {

        cfg = null;
        /**
         * daemon begin here
         */
        while (running) {
            /**
             * istantiate a new configurator
             */
            Configurator c = new Configurator(configFile);

            /*
             * here i rebuild DB's List
             */
            if (!c.isEqualsDBList(myDBConn)) {

                // rebuild connections DBConn[]

                myDBConn = c.rebuildDBList(myDBConn);
                for (int i = 1; i < myDBConn.length; i++) {
                    if (!qbox.containsKey(myDBConn[i].getName())) {
                        Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
                        qbox.put(myDBConn[i].getName(), qboxtmp);
                    }
                }
            } // if (!c.isEqualsDBList(myDBConn)) {

            /*
             * ready to run query
             */

            for (int i = 0; i < myDBConn.length; i++) {
                Querybox actqb = qbox.get(myDBConn[i].getName());
                actqb.refresh();
                Query[] q = actqb.getQueries();

                SharedPoolDataSource spds = myDBConn[i].getSPDS();

                Hashtable<String, Integer> zabbixServers = c.getZabbixServers();
                SmartLogger.logThis(Level.DEBUG, "Ready to run DBJob for dbname ->" + myDBConn[i].getName());
                Runnable runner = new DBJob(spds, q, Constants.QUERY_LIST, zabbixServers,
                        myDBConn[i].getName());
                executor.execute(runner);

            } // for (int i = 0; i < myDBConn.length; i++) {
            Thread.sleep(60 * 1000);
            SmartLogger.logThis(Level.DEBUG, "Waking up Goood Morning");
        }
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        System.out.println("Stopping");
        e1.printStackTrace();
        stopped = true;
    }

}

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//ww w  . ja  v  a  2 s .c o m
 * @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.stimulus.archiva.extraction.MessageExtraction.java

private String prepareHTMLMessage(String baseURL, Hashtable<String, String> inl, Hashtable<String, String> imgs,
        Hashtable<String, String> nonImgs, Hashtable<String, String> ready, ArrayList<String> mimeTypes) {
    String str = (String) inl.get("text/html");
    boolean alternative = false;
    for (int i = 0; i < mimeTypes.size(); i++) {
        if (((String) mimeTypes.get(i)).toLowerCase(Locale.ENGLISH).indexOf("multipart/alternative") > -1) {
            alternative = true;/*from   w  ww.j  a  v  a2s. com*/
            break;
        }
    }
    if (!alternative && inl.containsKey("text/plain")) {
        String plain = activateURLs((String) inl.get("text/plain")).replaceAll("\r", "").replaceAll("\n",
                "<br>" + System.getProperty("line.separator")) + "<br><br>"
                + System.getProperty("line.separator") + "<hr><br>";
        int bestStart = 0;
        int next = str.toLowerCase(Locale.ENGLISH).indexOf("<body");
        if (next > 0)
            next = str.indexOf(">", next) + 1;
        if (next > 0 && next < str.length())
            bestStart = next;
        if (bestStart > 0)
            str = str.substring(0, bestStart) + plain + str.substring(bestStart);
        else
            str = plain + str;
    }

    HashSet<String> alreadyUsed = new HashSet<String>();
    Enumeration enuma = imgs.keys();

    while (enuma.hasMoreElements()) {
        String repl = (String) enuma.nextElement();
        String cidTag = (String) imgs.get(repl);
        if (cidTag.startsWith("<") && cidTag.endsWith(">")) {
            cidTag = cidTag.substring(1, cidTag.length() - 1);
        }
        if (str.indexOf("cid:" + cidTag) > -1) {
            alreadyUsed.add(repl);
        }
        String st = (String) ready.get(repl);
        str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str)
                .replaceAll(ready.get(repl));
    }
    enuma = nonImgs.keys();

    while (enuma.hasMoreElements()) {
        String repl = (String) enuma.nextElement();
        String cidTag = (String) nonImgs.get(repl);
        if (cidTag.startsWith("<") && cidTag.endsWith(">"))
            cidTag = cidTag.substring(1, cidTag.length() - 1);

        if (str.indexOf("cid:" + cidTag) > -1)
            alreadyUsed.add(repl);

        String st = (String) ready.get(repl);
        str = Pattern.compile("cid:" + cidTag, Pattern.CASE_INSENSITIVE).matcher(str)
                .replaceAll(ready.get(repl));
    }
    StringBuffer buff = new StringBuffer();
    enuma = imgs.keys();
    while (enuma.hasMoreElements()) {
        String fl = (String) enuma.nextElement();
        if (!alreadyUsed.contains(fl)) {
            fl = (String) ready.get(fl);
            if (fl.endsWith(".tif") || fl.endsWith(".tiff")) {
                buff.append(System.getProperty("line.separator") + "<BR><BR><EMBED SRC=\""
                        + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\" TYPE=\"image/tiff\">");
            } else {
                buff.append(System.getProperty("line.separator") + "<BR><BR><IMG SRC=\""
                        + baseURL.replaceAll("\\\\", "/") + "/temp/" + fl + "\">");
            }
        }
    }
    String output = "";
    int bestStart = 0;
    int next = str.toLowerCase(Locale.ENGLISH).indexOf("</body>");
    if (next > 0 && next < str.length())
        bestStart = next;
    if (bestStart > 0)
        output = str.substring(0, bestStart) + buff.toString() + str.substring(bestStart);
    else
        output = str + buff.toString();

    if (output.indexOf("charset=") < 0) {
        next = output.toLowerCase(Locale.ENGLISH).indexOf("</head>");
        if (next > 0)
            output = output.substring(0, next) + "<META http-equiv=Content-Type content=\"text/html; charset="
                    + serverEncoding + "\">" + output.substring(next);
    } else
        output = output.replaceFirst("charset=.*\"", "charset=" + serverEncoding + "\"");

    output = output.replaceAll("FONT SIZE=\\d", "FONT");
    output = output.replaceAll("font size=\\d", "font");

    return writeTempMessage(output, ".html");

}

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

/**
 * Generate a stacked bar graph representing test execution time for each 
 * product area. //from w  w w .  j av a2s  .co  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:org.openhab.binding.yeelight.internal.YeelightBinding.java

/**
 * @{inheritDoc}/*from  w  ww  . j  a v  a 2  s . c  o  m*/
 */
@Override
protected void execute() {
    // the frequently executed code (polling) goes here ...
    logger.debug("execute() method is called!");

    if (!bindingsExist()) {
        return;
    }

    Hashtable<String, YeelightGetPropsResponse> propList = new Hashtable<>();

    //devices.clear();
    discoverYeelightDevices();

    for (final YeelightBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {

            YeelightBindingConfig config = (YeelightBindingConfig) provider.getItemConfig(itemName);
            if (config == null)
                continue;

            String action = config.getAction();
            if (action.equals(TOGGLE))
                continue;

            String location = config.getLocation();
            YeelightGetPropsResponse result;

            if (!propList.containsKey(location)) {
                result = sendYeelightGetPropCommand(location);
                if (result == null)
                    continue;
                propList.put(location, result);
                logger.debug("Cached location: {}", location);
            } else {
                result = propList.get(location);
            }

            processYeelightResult(result, action, itemName);
        }
    }
}

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

/**
 * Check if all required parameters are received in <code>request</code>.
 * //  w ww.  ja  va 2s  .  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 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:org.gridchem.client.gui.charts.UsageChart.java

/**
 * Returns a dataset representing the cumulative resource usage across all
 * projects./*w  w  w .j a  v  a2 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;
}