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:com.softlayer.messaging.messagequeue.client.Client.java

/**
 * Set the value of a custom HTTP header
 * //from   ww w .j  a  va  2 s .co  m
 * @param header
 *            the custom HTTP header to set the value for, for example
 *            <code>X-MyApp-MyHeader</code>
 * @param value
 *            the value of the custom HTTP header to set
 */
public static void setCustomHttpHeader(Hashtable<String, String> params, ClientResource client) {

    Map<String, Object> reqAttribs = client.getRequestAttributes();
    Form headers = (Form) reqAttribs.get(RESTLET_HTTP_HEADERS);
    if (headers == null) {
        headers = new Form();
        reqAttribs.put(RESTLET_HTTP_HEADERS, headers);
    }

    Enumeration<String> en = params.keys();
    while (en.hasMoreElements()) {
        String header = en.nextElement();
        String value = params.get(header);
        headers.add(header, value);
    }
}

From source file:com.ibm.watson.movieapp.dialog.rest.SearchTheMovieDbProxyResource.java

/**
 * Builds the URI from the URI parameter hash
 * <p>//from www.j  a v a2  s  .  com
 * This will append each of the {key, value} pairs in uriParamsHash to the URI.
 * 
 * @param uriParamsHash the hashtable containing parameters to be added to the URI for making the call to TMDB
 * @return URI for making the HTTP call to TMDB API
 * @throws URISyntaxException if the uri being built is in the incorrect format
 */
private static URI buildUriStringFromParamsHash(Hashtable<String, String> uriParamsHash, String path)
        throws URISyntaxException {
    URIBuilder urib = new URIBuilder();
    urib.setScheme("http"); //$NON-NLS-1$
    urib.setHost(TMDB_BASE_URL);
    urib.setPath(path);
    urib.addParameter("api_key", themoviedbapikey); //$NON-NLS-1$
    if (uriParamsHash != null) {
        Set<String> keys = uriParamsHash.keySet();
        for (String key : keys) {
            urib.addParameter(key, uriParamsHash.get(key));
        }
    }
    return urib.build();
}

From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java

/**
 * Transforms the Vector of the RepositoryType parameters into a RepositoryType Object.<br>
 * Structure of the parameters:<br>
 * Vector[name, uriFormat]/*from w ww .  j a  v a 2s . c om*/
 * </p>
 *
 * @param xmlRpcParameters a {@link java.util.Vector} object.
 * @return the RepositoryType.
 */
public static RepositoryType toRepositoryType(Vector<Object> xmlRpcParameters) {
    RepositoryType repositoryType = null;
    if (!xmlRpcParameters.isEmpty()) {
        repositoryType = RepositoryType.newInstance((String) xmlRpcParameters.get(REPOSITORY_TYPE_NAME_IDX));

        @SuppressWarnings("unchecked")
        Hashtable<String, String> params = (Hashtable<String, String>) xmlRpcParameters
                .get(REPOSITORY_TYPE_REPOCLASSES_IDX);
        for (String env : params.keySet())
            repositoryType.registerClassForEnvironment(params.get(env), EnvironmentType.newInstance(env));

        repositoryType.setDocumentUrlFormat(
                toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_TYPE_NAME_FORMAT_IDX)));
        repositoryType
                .setTestUrlFormat(toNullIfEmpty((String) xmlRpcParameters.get(REPOSITORY_TYPE_URI_FORMAT_IDX)));
    }

    return repositoryType;
}

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

/**
 * Create a chart representing the number patches grouped by time interval.
 * The data passed in the hashtable is a list of the time intervals and
 * the value is the number of patch requests for each interval.
 *
 * @param  data   Hashtable cnotaining the time intervals and corresponding counts
 * @param  label  Count label/*from w w  w  .  j a v  a 2  s.  co  m*/
 *
 * @return Bar chart representing the interval and count information
 */
public static final JFreeChart getPatchesByIntervalChart(Hashtable<CMnTimeInterval, Integer> data,
        String label) {
    JFreeChart chart = null;

    String title = "Patches per " + label;
    String nameLabel = label;
    String valueLabel = "Patches";

    // Sort the data by date
    Vector<CMnTimeInterval> intervals = new Vector<CMnTimeInterval>();
    Enumeration intervalList = data.keys();
    while (intervalList.hasMoreElements()) {
        intervals.add((CMnTimeInterval) intervalList.nextElement());
    }
    Collections.sort(intervals);

    // Populate the dataset with data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator keyIter = intervals.iterator();
    while (keyIter.hasNext()) {
        CMnTimeInterval interval = (CMnTimeInterval) keyIter.next();
        Integer value = data.get(interval);
        dataset.addValue(value, valueLabel, interval.getName());
    }

    // Create the chart
    chart = ChartFactory.createBarChart(title, /*title*/
            nameLabel, /*categoryAxisLabel*/
            valueLabel, /*valueAxisLabel*/
            dataset, /*dataset*/
            PlotOrientation.VERTICAL, /*orientation*/
            false, /*legend*/
            false, /*tooltips*/
            false /*urls*/
    );

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

    // Set the chart colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setShadowVisible(false);
    final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    renderer.setSeriesPaint(0, gp);

    // Set the label orientation
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:net.daimonin.client3d.editor.main.Editor3D.java

/**
* Builds image groups/categories by file name, creates and writes the XML
* containing all images with their attributes.
* 
* @param fileNameImageSet Name of resulting PNG.
* @param fileNameXML Name of the XML.//from w  w w . j a  v a2  s .  c  o  m
* @throws IOException IOException.
*/
private static void writeXML(final String fileNameImageSet, final String fileNameXML) throws IOException {

    // group ImageSetImages by name/category.
    // the left side of the image file name up to the '_' is taken as the
    // category
    Hashtable<String, List<ImageSetImage>> names = new Hashtable<String, List<ImageSetImage>>();
    for (int i = 0; i < images.size(); i++) {
        if (!names.containsKey(images.get(i).getName())) {
            List<ImageSetImage> values = new ArrayList<ImageSetImage>();
            values.add(images.get(i));
            names.put(images.get(i).getName(), values);
        } else {
            names.get(images.get(i).getName()).add(images.get(i));
        }
    }

    // check if every category has a default state (except FontExtensions)
    Enumeration<String> keys2 = names.keys();
    while (keys2.hasMoreElements()) {
        List<ImageSetImage> img2 = names.get(keys2.nextElement());
        if (!"fontextensions".equals(img2.get(0).getName())) {
            boolean hasDefault = false;
            for (int i = 0; i < img2.size(); i++) {
                if ("default".equals(img2.get(i).getState().toLowerCase())) {
                    hasDefault = true;
                }
            }
            if (!hasDefault) {
                printError("WARNING: image category '" + img2.get(0).getName()
                        + "' has no image with a default state!");
            }
        }
    }

    // create the XML structure
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ImageSet").addAttribute("file", fileNameImageSet);

    List<ImageSetImage> fntex = names.get("fontextensions");
    if (fntex != null) {
        Element category = root.addElement("ImageFntExt").addAttribute("name", fntex.get(0).getName());
        for (int i = 0; i < fntex.size(); i++) {
            category.addElement("State").addAttribute("name", fntex.get(i).getState())
                    .addAttribute("posX", String.valueOf(fntex.get(i).getPosX() + fntex.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(fntex.get(i).getPosY() + fntex.get(i).getBorderSize()))
                    .addAttribute("width", String.valueOf(fntex.get(i).getWidth()))
                    .addAttribute("height", String.valueOf(fntex.get(i).getHeight()));
        }
        names.remove("fontextensions");
    }

    List<ImageSetImage> mouse = names.get("mousecursor");
    if (mouse != null) {
        Element category = root.addElement("Image").addAttribute("name", mouse.get(0).getName())
                .addAttribute("width", String.valueOf(mouse.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(mouse.get(0).getImage().getHeight()))
                .addAttribute("alpha", mouse.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < mouse.size(); i++) {
            checkImageSameDimension(mouse.get(0), mouse.get(i),
                    "Images of same category have different dimension");
            checkImageSameAlpha(mouse.get(0), mouse.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", mouse.get(i).getState())
                    .addAttribute("posX", String.valueOf(mouse.get(i).getPosX() + mouse.get(i).getBorderSize()))
                    .addAttribute("posY",
                            String.valueOf(mouse.get(i).getPosY() + mouse.get(i).getBorderSize()));
        }
        names.remove("mousecursor");
    }

    Enumeration<String> keys = names.keys();
    while (keys.hasMoreElements()) {
        List<ImageSetImage> img = names.get(keys.nextElement());
        Element category = root.addElement("Image").addAttribute("name", img.get(0).getName())
                .addAttribute("width", String.valueOf(img.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(img.get(0).getImage().getHeight()))
                .addAttribute("alpha", img.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < img.size(); i++) {
            checkImageSameDimension(img.get(0), img.get(i), "Images of same category have different dimension");
            checkImageSameAlpha(img.get(0), img.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", img.get(i).getState())
                    .addAttribute("posX", String.valueOf(img.get(i).getPosX() + img.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(img.get(i).getPosY() + img.get(i).getBorderSize()));
        }
    }

    // write the XML
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(fileNameXML), format);
    writer.write(document);
    writer.close();
    printInfo(System.getProperty("user.dir") + "/" + imagesetxml + " created");
}

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

/**
 * Generate a pie graph representing average test counts for each type of test for 
 * all builds in the list. //from w  ww. j a v a 2s  .  c  om
 *
 * @param   builds  List of builds 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageTestCountChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

    // Collect the average of all test types 
    Hashtable countAvg = new Hashtable();

    DefaultPieDataset dataset = new DefaultPieDataset();
    if ((builds != null) && (builds.size() > 0)) {

        // Collect build metrics for each of the builds in the list 
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            // Process the build metrics for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Hashtable testSummary = build.getTestSummary();
            if ((testSummary != null) && (testSummary.size() > 0)) {
                Enumeration keys = testSummary.keys();
                while (keys.hasMoreElements()) {
                    String testType = (String) keys.nextElement();
                    CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType);

                    Integer avgValue = null;
                    if (countAvg.containsKey(testType)) {
                        Integer oldAvg = (Integer) countAvg.get(testType);
                        avgValue = oldAvg + tests.getTotalCount();
                    } else {
                        avgValue = tests.getTotalCount();
                    }
                    countAvg.put(testType, avgValue);

                }
            }

        } // while list has elements

        // Populate the data set with the average values for each metric
        Enumeration keys = countAvg.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Integer total = (Integer) countAvg.get(key);
            Integer avg = new Integer(total.intValue() / builds.size());
            dataset.setValue(key, avg);
        }

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Avg Test Count by Type", dataset, true, true, false);

    // get a reference to the plot for further customization...
    PiePlot plot = (PiePlot) chart.getPlot();
    chartFormatter.formatTypeChart(plot, "tests");

    return chart;
}

From source file:eionet.gdem.web.struts.hosts.HostDetailsAction.java

@Override
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request,
        HttpServletResponse httpServletResponse) {
    ActionMessages errors = new ActionMessages();
    DynaValidatorForm hostForm = (DynaValidatorForm) actionForm;
    String hostId = (String) hostForm.get("id");

    try {//w  w  w  .  ja  va 2 s. c o m
        if (checkPermission(request, Names.ACL_HOST_PATH, "u")) {
            Vector hosts = hostDao.getHosts(hostId);

            if (hosts != null) {
                Hashtable host = (Hashtable) hosts.get(0);
                hostForm.set("id", host.get("host_id"));
                hostForm.set("host", host.get("host_name"));
                hostForm.set("username", host.get("user_name"));
                hostForm.set("password", host.get("pwd"));
            }
        } else {
            errors.add(ActionMessages.GLOBAL_MESSAGE,
                    new ActionMessage("error.unoperm", translate(actionMapping, request, "label.hosts")));
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.exception.unknown"));
    }

    if (errors.size() > 0) {
        // request.getSession().setAttribute("dcm.errors", errors);
        saveErrors(request, errors);
        return actionMapping.getInputForward();
    }
    return actionMapping.findForward("success");
}

From source file:UndoableToggleApp4.java

public void restoreState(Hashtable ht) {
    Boolean b1 = (Boolean) ht.get(tog);
    if (b1 != null)
        tog.setSelected(b1.booleanValue());
    Boolean b2 = (Boolean) ht.get(cb);
    if (b2 != null)
        cb.setSelected(b2.booleanValue());
    Boolean b3 = (Boolean) ht.get(radio);
    if (b3 != null)
        radio.setSelected(b3.booleanValue());
}

From source file:UndoableDrawingPanel2.java

public void restoreState(Hashtable state) {
    Polygon polygon = (Polygon) state.get(POLYGON_KEY);
    if (polygon != null) {
        setPolygon(polygon);/* w  w w. j  a  v a 2  s  .co  m*/
    }
}

From source file:com.liusoft.dlog4j.upload.SecurityFCKUploadServlet.java

/**
 * ?WAP/*from  w w  w  . ja va2s . com*/
 */
protected void makeOutput(HttpServletRequest req, HttpServletResponse res, Hashtable params, String msg)
        throws IOException {
    String toPage = (String) params.get("toPage");
    if (StringUtils.isEmpty(toPage)) {
        super.makeOutput(req, res, params, msg);
    } else {
        res.sendRedirect(req.getContextPath() + toPage);
    }
}