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:adams.ml.Dataset.java

protected String summariseNumeric(String columnname) {
    Vector<Float> vf = new Vector<>();
    Hashtable<Float, Boolean> ind = new Hashtable<>();
    int numErrors = 0;
    int missing = 0;
    int ignored = 0;
    for (int i = 0; i < count(); i++) {
        DataRow dr = get(i);//  ww w .j  av a  2s .c om
        if (dr.get(columnname) == null) {
            missing++;
            continue;
        }
        dr = getSafe(i);
        if (dr == null) {
            ignored++;
            continue;
        }
        try {
            Number val = (Number) dr.get(columnname).getData();
            vf.add(val.floatValue());
            if (ind.get(val.floatValue()) == null) {
                ind.put(val.floatValue(), true);
            }
        } catch (Exception e) {
            try {
                Float pi = Float.parseFloat(dr.getAsString(columnname));
                vf.add(pi);
            } catch (Exception e1) {
                numErrors++;
                continue;
            }
        }
    }
    double[] f = new double[vf.size()];
    for (int i = 0; i < f.length; i++) {
        f[i] = vf.get(i);
    }
    StringBuffer ret = new StringBuffer();
    ret.append("Total OK: " + vf.size() + "\n");
    ret.append("Ignored Rows: " + ignored + "\n");
    ret.append("Missing: " + missing + "\n");
    ret.append("Errors: " + numErrors + "\n");
    ret.append("Different: " + ind.size() + "\n");
    double min = StatUtils.min(f);
    double max = StatUtils.max(f);
    double mean = StatUtils.mean(f);
    double stdev = Math.sqrt(StatUtils.variance(f));
    double median = StatUtils.percentile(f, 50);
    ret.append("Min,Max: " + min + "," + max + "\n");
    ret.append("Mean: " + mean + "\n");
    ret.append("Standard Deviation: " + stdev + "\n");
    ret.append("Median: " + median + "\n");
    return (ret.toString());
}

From source file:Controller.ControllerImageCustomerIndex.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*  w  ww.  j a va 2 s  . c o  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {

    } else {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Iterator iter = items.iterator();
        Hashtable params = new Hashtable();
        String fileName = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                params.put(item.getFieldName(), item.getString());
            } else {

                try {
                    String itemName = item.getName();
                    fileName = itemName.substring(itemName.lastIndexOf("\\") + 1);
                    System.out.println("path" + fileName);
                    String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName;
                    System.out.println("Rpath" + RealPath);
                    File savedFile = new File(RealPath);
                    item.write(savedFile);
                    String username = (String) params.get("txtusername");
                    String password = (String) params.get("txpassword");
                    String hoten = (String) params.get("txthoten");
                    String gioitinh = (String) params.get("txtgioitinh");
                    String email = (String) params.get("txtemail");
                    String role = "false";
                    Customer cus = new Customer(username, password, hoten, gioitinh, email, role,
                            "upload\\" + fileName);

                    CustomerDAO.ThemKhachHang(cus);
                    RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
                    rd.forward(request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

    }

}

From source file:com.flexive.tests.browser.AdmContentTest.java

/**
 * creates a content// w w  w. j a  va2  s.co  m
 * @param typeName the type name of what to create
 * @param contents the parameters to fill in
 * @return <code>true</code> if successfull
 */
private boolean createContent(String typeName, Hashtable<String, Object> contents) {
    // http://localhost:8080/flexive/adm/content/contentEditor.jsf?action=newInstance&typeId=10&nodeId=-1
    fillLUT(typeName);
    Hashtable<String, String> param = propertyLUT.get(typeName);

    String link = CREATE_CONTENT_LINK + "typeId=" + param.get("typeId") + "&nodeId=-1";

    loadContentPage(link);
    selectFrame(Frame.Content);
    sleep(100);
    //        writeHTMLtoHD("Content");

    fillInContent(contents);

    clickAndWait("link=Create");

    return checkText("Content was created ", true, LOG);
}

From source file:eionet.acl.PersistenceDB.java

PersistenceDB(Hashtable props) throws DbNotSupportedException {

    this.props = props;
    try {//from   w  w w. java 2  s.  co m
        if (props != null) {
            if (props.containsKey("db.datasource")) {
                dataSource = (DataSource) props.get("db.datasource");
            } else {
                dbUrl = (String) props.get("db.url");
                dbDriver = (String) props.get("db.driver");
                dbUser = (String) props.get("db.user");
                dbPwd = (String) props.get("db.pwd");
            }
        }

        checkAclTables();

    } catch (MissingResourceException mre) {
        LOGGER.info("Database property not configured, assuming no database support " + mre);
        throw new DbNotSupportedException();
    } catch (DbNotSupportedException dbne) {
        LOGGER.info("Database Not supported " + dbne);
        throw dbne;
    } catch (SQLException sqle) {
        LOGGER.error("Error in database checking " + sqle);
        throw new DbNotSupportedException();
    } catch (Exception e) {
        LOGGER.error("Error in database checking " + e);
        throw new DbNotSupportedException();
    }
}

From source file:Controller.ControllerImageCustomer.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request// w  w w . j a va 2s . c o m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart) {

    } else {
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Iterator iter = items.iterator();
        Hashtable params = new Hashtable();
        String fileName = null;
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
            if (item.isFormField()) {
                params.put(item.getFieldName(), item.getString());
            } else {

                try {
                    String itemName = item.getName();
                    fileName = itemName.substring(itemName.lastIndexOf("\\") + 1);
                    System.out.println("path" + fileName);
                    String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName;
                    System.out.println("Rpath" + RealPath);
                    File savedFile = new File(RealPath);
                    item.write(savedFile);
                    String username = (String) params.get("txtusername");
                    String password = (String) params.get("txpassword");
                    String hoten = (String) params.get("txthoten");
                    String gioitinh = (String) params.get("txtgioitinh");
                    String email = (String) params.get("txtemail");
                    String role = "false";
                    String Register = (String) params.get("Register");
                    String url = "CustomerDao.jsp";
                    if (Register.equals("Register")) {
                        url = "index.jsp";
                    }
                    Customer cus = new Customer(username, password, hoten, gioitinh, email, role,
                            "upload\\" + fileName);
                    CustomerDAO.ThemKhachHang(cus);
                    RequestDispatcher rd = request.getRequestDispatcher(url);
                    rd.forward(request, response);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }

    }

}

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  w  w  .  ja va 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:net.sf.joost.plugins.traxfilter.THResolver.java

/**
 * Prepare TH instance for work//  w w w .j av a  2s  . c  o  m
 *
 * This involves setting TrAX parameters and all other stuff if needed
 *
 * @param th
 * @param params
 */
protected void prepareTh(TransformerHandler th, Hashtable params) {
    if (DEBUG)
        log.debug("prepareTh()");

    Transformer tr = th.getTransformer();

    // make sure old parameters are cleaned
    tr.clearParameters();

    // set transformation parameters
    if (!params.isEmpty()) {
        for (Enumeration e = params.keys(); e.hasMoreElements();) {
            String key = (String) e.nextElement();
            if (DEBUG)
                log.debug("prepareTh(): set parameter " + key + "=" + params.get(key));

            if (!key.startsWith(tmp_TRAX_ATTR_NS) && !key.startsWith(tmp_FILTER_ATTR_NS)) {
                // ordinary parameter, set it to the TrAX object
                tr.setParameter(key, params.get(key));
            }
        }
    }
}

From source file:com.krawler.spring.hrms.common.hrmsDocumentController.java

public ModelAndView downloadDocuments(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;/*w w w  .jav  a  2s  . c  om*/
    String details = "";
    String auditAction = "";
    try {
        String url = request.getParameter("url");
        url = StringUtil.checkForNull(url);
        String applicant = request.getParameter("applicant");
        applicant = StringUtil.checkForNull(applicant);
        Hashtable ht;
        if (applicant.equalsIgnoreCase("applicant")) {
            kmsg = hrmsExtApplDocsDAOObj.downloadDocument(url);
            ht = getExtDocumentDownloadHash(kmsg.getEntityList());
        } else {
            kmsg = documentDAOObj.downloadDocument(url);
            ht = getDocumentDownloadHash(kmsg.getEntityList());
        }

        String src = storageHandlerImplObj.GetDocStorePath();
        //            String src = "/home/trainee/";
        if (request.getParameter("mailattch") != null) {
            src = src + ht.get("svnname");
        } else {
            src = src + ht.get("userid").toString() + "/" + ht.get("svnname");
        }

        File fp = new File(src);
        byte[] buff = new byte[(int) fp.length()];
        FileInputStream fis = new FileInputStream(fp);
        int read = fis.read(buff);
        javax.activation.FileTypeMap mmap = new javax.activation.MimetypesFileTypeMap();
        response.setContentType(mmap.getContentType(src));
        response.setContentLength((int) fp.length());
        response.setHeader("Content-Disposition",
                request.getParameter("dtype") + "; filename=\"" + ht.get("Name") + "\";");
        response.getOutputStream().write(buff);
        response.getOutputStream().flush();
        response.getOutputStream().close();
        String map = ht.get("relatedto").toString();
        String refid = ht.get("recid").toString();

        myjobj.put("success", true);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
}

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

private static void dumpPart(Part p, Hashtable<String, Part> attachments, Hashtable<String, String> inlines,
        Hashtable<String, String> images, Hashtable<String, String> nonImages, ArrayList<String> mimeTypes,
        String subject) throws Exception {
    mimeTypes.add(p.getContentType());/*from  w  w  w . ja  v a 2  s .  c  o m*/
    if (!p.isMimeType("multipart/*")) {

        String disp = p.getDisposition();
        String fname = p.getFileName();
        if (fname != null) {
            try {
                fname = MimeUtility.decodeText(fname);
            } catch (Exception e) {
                logger.debug("cannot decode filename:" + e.getMessage());
            }
        }
        if ((disp != null && Compare.equalsIgnoreCase(disp, Part.ATTACHMENT)) || fname != null) {
            String filename = getFilename(subject, p);
            if (!filename.equalsIgnoreCase("winmail.dat")) {
                attachments.put(filename, p);
            }
            /*if (p.isMimeType("image/*")) {
               String str[] = p.getHeader("Content-ID");
               if (str != null) images.put(filename,str[0]);
               else images.put(filename, filename);
            }
            return;*/
        }
    }
    if (p.isMimeType("text/plain")) {
        String str = "";
        if (inlines.containsKey("text/plain"))
            str = (String) inlines.get("text/plain") + "\n\n-------------------------------\n";
        inlines.put("text/plain", str + getTextContent(p));
    } else if (p.isMimeType("text/html")) {
        inlines.put("text/html", getTextContent(p));
    } else if (p.isMimeType("text/xml")) {
        attachments.put(getFilename(subject, p), p);
    } else if (p.isMimeType("multipart/*")) {
        Multipart mp = (Multipart) p.getContent();
        for (int i = 0; i < mp.getCount(); i++)
            dumpPart(mp.getBodyPart(i), attachments, inlines, images, nonImages, mimeTypes, subject);
    } else if (p.isMimeType("message/rfc822")) {
        dumpPart((Part) p.getContent(), attachments, inlines, images, nonImages, mimeTypes, subject);
    } else if (p.isMimeType("application/ms-tnef")) {
        Part tnefpart = TNEFMime.convert(null, p, false);
        if (tnefpart != null) {
            dumpPart((Part) tnefpart, attachments, inlines, images, nonImages, mimeTypes, subject);
        }
    } else if (p.isMimeType("application/*")) {
        String filename = getFilename("application", p);
        attachments.put(filename, p);
        String str[] = p.getHeader("Content-ID");
        if (str != null)
            nonImages.put(filename, str[0]);
    } else if (p.isMimeType("image/*")) {
        String fileName = getFilename("image", p);
        attachments.put(fileName, p);
        String str[] = p.getHeader("Content-ID");
        if (str != null)
            images.put(fileName, str[0]);
        else
            images.put(fileName, fileName);
    } else {
        String contentType = p.getContentType();
        Object o = p.getContent();
        if (o instanceof String) {
            String str = "";
            if (inlines.containsKey("text/plain"))
                str = (String) inlines.get("text/plain") + "\n\n-------------------------------\n";
            inlines.put(contentType, str + (String) o);
        } else {
            String fileName = getFilenameFromContentType("attach", contentType);
            attachments.put(fileName, p);
        }
    }
}

From source file:mypackage.FeedlyClient.java

public FeedlyClient() {
     _app = (MyApp) UiApplication.getUiApplication();

     _feedlyapi = new FeedlyAPI(this, client_id, client_secret, sandbox);

     _network = new Network(this);
     _connectionFactory = _network.selectTransport();

     ////w ww. j  ava2  s.  c o m
     //?@foCX??
     //
     // Get the code signing key associated with "ACME"
     codeSigningKey = CodeSigningKey.get(CodeModuleManager.getModuleHandle("GreenFeedReader"), "ACME");

     //PersistentStore.destroyPersistentObject(PERSISTENT_OBJECT_KEY);
     //return;

     _persist = PersistentStore.getPersistentObject(PERSISTENT_OBJECT_KEY);

     // ?NnbVe?[u`?????B
     synchronized (_persist) {
         if (_persist.getContents(codeSigningKey) == null) {
             Hashtable _tmp_ht = new Hashtable();
             _tmp_ht.put("id", "");
             _tmp_ht.put("access_token", "");
             _tmp_ht.put("refresh_token", "");
             _tmp_ht.put("expires_in", new Integer(0));
             _tmp_ht.put("update", new Long(0));

             _persist.setContents(new ControlledAccess(_tmp_ht, codeSigningKey));
             PersistentObject.commit(_persist);
         }
     }

     // WJ
     Hashtable _tmp_ht = (Hashtable) _persist.getContents(codeSigningKey);
     this.id = (String) _tmp_ht.get("id");
     this.access_token = (String) _tmp_ht.get("access_token");
     this.refresh_token = (String) _tmp_ht.get("refresh_token");
     this.expires_in = ((Integer) _tmp_ht.get("expires_in")).intValue();
     this.update = ((Long) _tmp_ht.get("update")).longValue();

     //
     // ?XeCg?
     //
     // HomeXeCg??B
     _homeState = new State_Home(this);
     _currentState = _homeState;
 }