Example usage for java.util Hashtable Hashtable

List of usage examples for java.util Hashtable Hashtable

Introduction

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

Prototype

public Hashtable() 

Source Link

Document

Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).

Usage

From source file:com.efoundry.widgets.CustomSourceConfiguration.java

/**
 * Parses the widget configuration parameter<p> 
 * /*from ww w.j a v  a2 s  . c  o  m*/
 * Please note: No exception is thrown in case the input is malformed, any malformed entries are 
 * silently ignored (but logged)<p>
 * 
 * @param input the widget input string to parse
 */
private void parseOptions(String config) {
    m_htOptions = new Hashtable<String, String>();

    String[] aParms = CmsStringUtil.splitAsArray(config, OPTION_DELIMITER);
    for (int i = 0; i < aParms.length; i++) {
        boolean bBadParamFormat = false;
        // read the parameter name
        String strParm = aParms[i];
        int nParmNameBegin = 0;
        int nParmNameEnd = strParm.indexOf(OPTION_VALUE_BEGIN);
        if (-1 != nParmNameEnd) {
            // parameter name
            String strParmName = strParm.substring(nParmNameBegin, nParmNameEnd);
            // parameter value
            int nParmValueStart = nParmNameEnd + OPTION_VALUE_BEGIN.length();
            int nParmValueEnd = strParm.indexOf(OPTION_VALUE_END, nParmValueStart);
            if (-1 != nParmValueEnd) {
                String strParmVal = strParm.substring(nParmValueStart, nParmValueEnd);

                // add the param name-value pair
                m_htOptions.put(strParmName, strParmVal);
            } else {
                bBadParamFormat = true;
            }
        } else {
            bBadParamFormat = true;
        }
        if (bBadParamFormat && LOG.isInfoEnabled()) {
            LOG.info(Messages.get().getBundle().key(Messages.ERR_MALFORMED_SELECT_OPTIONS_1, strParm));
        }
    }
}

From source file:org.vast.stt.renderer.JFreeChart.XYPlotBuilder.java

public XYPlotBuilder() {
    axisTable = new Hashtable<DataItem, Integer>();
}

From source file:com.panet.imeta.shared.SharedObjects.java

public SharedObjects(String sharedObjectsFile) throws KettleXMLException {
    try {// ww w.  j a  v a  2s.co m
        this.filename = createFilename(sharedObjectsFile);
        this.objectsMap = new Hashtable<SharedEntry, SharedObjectInterface>();

        // Extra information
        FileObject file = KettleVFS.getFileObject(filename);

        // If we have a shared file, load the content, otherwise, just keep this one empty
        if (file.exists()) {
            LogWriter.getInstance().logDetailed(Messages.getString("SharedOjects.ReadingFile.Title"),
                    Messages.getString("SharedOjects.ReadingFile.Message", "" + file));
            Document document = XMLHandler.loadXMLFile(file);
            Node sharedObjectsNode = XMLHandler.getSubNode(document, XML_TAG);
            if (sharedObjectsNode != null) {
                List<SlaveServer> privateSlaveServers = new ArrayList<SlaveServer>();
                List<DatabaseMeta> privateDatabases = new ArrayList<DatabaseMeta>();

                NodeList childNodes = sharedObjectsNode.getChildNodes();
                // First load databases & slaves
                //
                for (int i = 0; i < childNodes.getLength(); i++) {
                    Node node = childNodes.item(i);
                    String nodeName = node.getNodeName();

                    SharedObjectInterface isShared = null;

                    if (nodeName.equals(DatabaseMeta.XML_TAG)) {
                        DatabaseMeta sharedDatabaseMeta = new DatabaseMeta(node);
                        isShared = sharedDatabaseMeta;
                        privateDatabases.add(sharedDatabaseMeta);
                    } else if (nodeName.equals(SlaveServer.XML_TAG)) {
                        SlaveServer sharedSlaveServer = new SlaveServer(node);
                        isShared = sharedSlaveServer;
                        privateSlaveServers.add(sharedSlaveServer);
                    }

                    if (isShared != null) {
                        isShared.setShared(true);
                        storeObject(isShared);
                    }
                }

                // Then load the other objects that might reference databases & slaves
                //
                for (int i = 0; i < childNodes.getLength(); i++) {
                    Node node = childNodes.item(i);
                    String nodeName = node.getNodeName();

                    SharedObjectInterface isShared = null;

                    if (nodeName.equals(StepMeta.XML_TAG)) {
                        StepMeta stepMeta = new StepMeta(node, privateDatabases, null);
                        stepMeta.setDraw(false); // don't draw it, keep it in the tree.
                        isShared = stepMeta;
                    } else if (nodeName.equals(PartitionSchema.XML_TAG)) {
                        isShared = new PartitionSchema(node);
                    } else if (nodeName.equals(ClusterSchema.XML_TAG)) {
                        isShared = new ClusterSchema(node, privateSlaveServers);
                    }

                    if (isShared != null) {
                        isShared.setShared(true);
                        storeObject(isShared);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new KettleXMLException(
                Messages.getString("SharedOjects.Readingfile.UnexpectedError", sharedObjectsFile), e);
    }
}

From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UmlsCommon.LoadRRFToDB.java

private static String[] createAndLoadTables(URI rrfLocation, boolean skipNonLexGridFiles,
        boolean recalcRootOnly, String dbServer, String dbDriver, String username, String password,
        LgMessageDirectorIF md, boolean validateMode) throws Exception {
    md.info("Connecting to RRF Files");
    BufferedReader reader = getReader(rrfLocation.resolve("MRFILES.RRF"));

    md.info("Connecting to db Files");
    Connection sqlConnection = DBUtility.connectToDatabase(dbServer, dbDriver, username, password);

    GenericSQLModifier gsm = new GenericSQLModifier(sqlConnection);

    Hashtable columnTypeMap = readMRCols(rrfLocation);
    Hashtable tableColumnMap = new Hashtable();

    List tables = new ArrayList();

    if (skipNonLexGridFiles) {
        // the only tables that I need to load
        tables.add("MRCONSO");
        tables.add("MRDOC");
        tables.add("MRREL");
        tables.add("MRSAB");
        tables.add("MRRANK");

        if (!recalcRootOnly) {
            tables.add("MRDEF");
            tables.add("MRSTY");
            tables.add("MRSAT");
            tables.add("MRHIER");
        }//ww w .  jav  a  2s  . co  m
    }

    md.info("Creating SQL database tables");

    PreparedStatement create = null;
    PreparedStatement drop = null;
    String line = reader.readLine();

    int mrhierHCDCol = -1;
    while (line != null) {
        String[] vals = stringToArray(line, '|');

        // for MRFILES, all I care about is the following
        String file = vals[0];
        String tableName = file.substring(0, file.indexOf('.'));

        // if file is MRHIER, remember HCD column number (base 0)
        if ("MRHIER".equalsIgnoreCase(tableName) && vals.length > 1) {
            mrhierHCDCol = Arrays.asList(vals[2].split(",")).indexOf("HCD");
        }

        if (skipNonLexGridFiles || recalcRootOnly) {
            if (!tables.contains(tableName)) {
                line = reader.readLine();
                continue;
            }
        } else {
            if (file.indexOf('/') != -1) {
                // skip files in subfolders.
                line = reader.readLine();
                continue;
            }
            if (!tables.contains(tableName))
                tables.add(tableName);
        }

        String[] columns = stringToArray(vals[2], ',');

        tableColumnMap.put(file, columns);

        StringBuffer tableCreateSQL = new StringBuffer();
        tableCreateSQL.append("CREATE TABLE {IF NOT EXISTS} ^" + tableName + "^ (");

        for (int i = 0; i < columns.length; i++) {

            tableCreateSQL.append(" ^" + columns[i] + "^ "
                    + mapUMLSType((String) columnTypeMap.get(columns[i] + "|" + file)) + " default NULL,");
        }

        // chop the last comma
        tableCreateSQL.deleteCharAt(tableCreateSQL.length() - 1);
        tableCreateSQL.append(") {TYPE}");

        // make sure the table doesn't exist
        try {
            drop = sqlConnection.prepareStatement(gsm.modifySQL("DROP TABLE " + tableName + " {CASCADE}"));
            drop.executeUpdate();
            drop.close();
        } catch (SQLException e) {
            // most likely means that the table didn't exist.
        }

        create = sqlConnection.prepareStatement(gsm.modifySQL(tableCreateSQL.toString()));
        create.executeUpdate();

        create.close();

        line = reader.readLine();
    }
    reader.close();

    md.info("Creating indexes");

    PreparedStatement createIndex = null;

    createIndex = sqlConnection
            .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi1^ ON ^MRCONSO^ (^CUI^, ^SAB^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection
            .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi2^ ON ^MRCONSO^ (^CUI^, ^AUI^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection
            .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi3^ ON ^MRCONSO^ (^AUI^, ^CODE^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi4^ ON ^MRREL^ (^RELA^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi5^ ON ^MRREL^ (^REL^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi6^ ON ^MRREL^ (^RUI^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection
            .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi7^ ON ^MRREL^ (^SAB^, ^RELA^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi8^ ON ^MRSAB^ (^RSAB^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi9^ ON ^MRRANK^ (^SAB^)"));
    createIndex.executeUpdate();
    createIndex.close();

    createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi10^ ON ^MRRANK^ (^TTY^)"));
    createIndex.executeUpdate();
    createIndex.close();

    if (!recalcRootOnly) {
        createIndex = sqlConnection
                .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi11^ ON ^MRDEF^ (^CUI^, ^SAB^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection
                .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi12^ ON ^MRSAT^ (^METAUI^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection
                .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi13^ ON ^MRSAT^ (^CUI^, ^SAB^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection
                .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi14^ ON ^MRSAT^ (^CODE^, ^SAB^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection.prepareStatement(gsm.modifySQL("CREATE INDEX ^mi15^ ON ^MRSTY^ (^CUI^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection.prepareStatement(
                gsm.modifySQL("CREATE INDEX ^mi16^ ON ^MRHIER^ (^CUI^, ^AUI^, ^HCD^, ^SAB^, ^CXN^)"));
        createIndex.executeUpdate();
        createIndex.close();

        createIndex = sqlConnection
                .prepareStatement(gsm.modifySQL("CREATE INDEX ^mi17^ ON ^MRHIER^ (^CUI^, ^SAB^, ^CXN^)"));
        createIndex.executeUpdate();
        createIndex.close();
    }

    PreparedStatement insert = null;

    Iterator allTables = tables.iterator();
    Set rootCUIs = new HashSet();
    while (allTables.hasNext()) {
        System.gc();
        String table = (String) allTables.next();
        md.info("Loading " + table);

        boolean loadingMrHier = table.equalsIgnoreCase("MRHIER");

        StringBuffer insertSQL = new StringBuffer();

        insertSQL.append("INSERT INTO " + table + " (");

        String[] vals = (String[]) tableColumnMap.get(table + ".RRF");
        for (int i = 0; i < vals.length; i++) {
            if (gsm.getDatabaseType().equals("ACCESS") && vals[i].equals("VALUE")) {
                // reserved word in MSAccess
                insertSQL.append("\"" + vals[i] + "\", ");
            } else {
                insertSQL.append(vals[i] + ", ");
            }
        }

        // chop the last comma and space
        insertSQL.deleteCharAt(insertSQL.length() - 2);
        insertSQL.append(") VALUES (");

        for (int i = 0; i < vals.length; i++) {
            insertSQL.append("?, ");
        }

        // chop the last comma and space
        insertSQL.deleteCharAt(insertSQL.length() - 2);
        insertSQL.append(")");
        insert = sqlConnection.prepareStatement(gsm.modifySQL(insertSQL.toString()));

        URI tableURI = rrfLocation.resolve(table + ".RRF");

        if (verifyTableExists(tableURI)) {
            try {
                reader = getReader(tableURI);

                int count = 1;
                line = reader.readLine();
                boolean restrictToRootCUIs = recalcRootOnly && table.equalsIgnoreCase("MRCONSO");
                boolean restrictToRootRels = recalcRootOnly && table.equalsIgnoreCase("MRREL");
                while (line != null && line.length() > 0) {
                    // Note: If we are only using the data to recalculate
                    // root nodes,
                    // we only need CUIs defining root hierarchical terms
                    // and any related
                    // relationships.
                    if (restrictToRootCUIs && !line.contains("|SRC|RHT|")) {
                        line = reader.readLine();
                        continue;
                    }
                    String[] data = stringToArray(line, '|');

                    // If processing MRHIER, we only care about entries
                    // relevant to
                    // the specified MRHIER processing option. Many entries
                    // in this file
                    // we do not require since they can be derived from
                    // MRREL.
                    // MRHIER typically is much larger since it pre-computes
                    // the entire
                    // hierarchy, so we want to conserve time and space by
                    // loading only
                    // those entries that require special handling.
                    if (loadingMrHier && mrhierHCDCol > 0 && data.length > mrhierHCDCol
                            && StringUtils.isBlank(data[mrhierHCDCol])) {
                        line = reader.readLine();
                        continue;
                    }

                    if (restrictToRootCUIs && data.length >= 1)
                        rootCUIs.add(data[0]);
                    if (restrictToRootRels && (data.length < 5
                            || (!rootCUIs.contains(data[0]) && !rootCUIs.contains(data[4])))) {
                        line = reader.readLine();
                        continue;
                    }

                    for (int i = 0; i < vals.length; i++) {
                        insert.setString(i + 1, data[i]);
                    }
                    insert.executeUpdate();

                    count++;
                    line = reader.readLine();

                    if (validateMode && count > 100) {
                        line = null;
                    }

                    if (count % 10000 == 0) {
                        md.busy();
                    }

                    if (count % 100000 == 0) {
                        md.info("Loaded " + count + " into " + table);
                    }
                }
                reader.close();
            } catch (Exception e) {
                md.fatalAndThrowException("problem loading the table " + table, e);
            }

        } else {
            md.warn("Could not load table " + table + ". This" + "most likely means the corresponding RRF file"
                    + "was not found in the source.");
        }

        insert.close();
        System.gc();
    }

    sqlConnection.close();
    return (String[]) tables.toArray(new String[tables.size()]);
}

From source file:bide.simulation.Simulation.java

private static Hashtable<String, double[]> simRealistic() {

    double oneOverLambda = 1 / 0.5;
    double[] setupMean = new double[totalSpot];
    double[] setupDelta = new double[totalSpot];
    double[] setupPi = new double[totalSpot];
    double[] setupRho = new double[totalSpot];

    for (int i = 0; i < totalSpot; i++) {
        setupMean[i] = rd.nextGaussian(simMean, globalSd);
        if (i < 50) {
            setupDelta[i] = rd.nextExponential(oneOverLambda);
        } else {//from   w ww . j av a  2  s  . c om
            setupDelta[i] = -rd.nextExponential(oneOverLambda);
        }
        setupPi[i] = rd.nextGaussian(1, 1);
        setupRho[i] = rd.nextGaussian(0, 2);
    }

    Hashtable<String, double[]> table = new Hashtable<String, double[]>();
    table.put("setupMean", setupMean);
    table.put("setupDelta", setupDelta);
    table.put("setupPi", setupPi);
    table.put("setupRho", setupRho);
    return table;
}

From source file:Controller.ControllerImage.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request//from w  w  w .  java 2s .c om
 * @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);
                    String RealPath = getServletContext().getRealPath("/") + "upload\\" + fileName;
                    String code = (String) params.get("txtCode");
                    String name = (String) params.get("txtName");
                    String price = (String) params.get("txtPrice");
                    int a = Integer.parseInt(price);
                    String image = (String) params.get("txtImage");
                    //Update  product
                    if (fileName.equals("")) {

                        Products sp = new Products();
                        sp.Update(code, name, price, image);
                        RequestDispatcher rd = request.getRequestDispatcher("product.jsp");
                        rd.forward(request, response);

                    } else {
                        // bat dau ghi file
                        File savedFile = new File(RealPath);
                        item.write(savedFile);
                        //ket thuc ghi
                        Products sp = new Products();
                        sp.Update(code, name, price, "upload\\" + fileName);

                        RequestDispatcher rd = request.getRequestDispatcher("product.jsp");
                        rd.forward(request, response);
                    }

                } catch (Exception e) {
                    RequestDispatcher rd = request.getRequestDispatcher("InformationError.jsp");
                    rd.forward(request, response);
                }
            }

        }
    }

    this.processRequest(request, response);

}

From source file:net.aepik.alasca.core.ldap.Schema.java

/**
 * Construit un schema vide.//from   w  ww  .  ja v  a2s  .  co m
 * @param name Schema name
 * @param s Schema syntax
 */
public Schema(String name, SchemaSyntax s) {
    this.name = name;
    objets = new Hashtable<String, SchemaObject>();
    proprietes = new Properties();
    syntax = s;
    isSyntaxChanged = false;
    objectsOrder = new History();
    objectIdentifierPrefix = null;
    objectIdentifierSuffix = null;
}

From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java

/**
 * Constructor for total ion chromatogram visualizer
 *//* www .  j  av a  2 s. c  o m*/
public TICVisualizerWindow(RawDataFile dataFiles[], PlotType plotType, int msLevel, Range rtRange,
        Range mzRange, Feature[] peaks, Map<Feature, String> peakLabels) {

    super("");

    assert mzRange != null;
    assert rtRange != null;

    this.desktop = MZmineCore.getDesktop();
    this.plotType = plotType;
    this.msLevel = msLevel;
    this.ticDataSets = new Hashtable<RawDataFile, TICDataSet>();
    this.rtRange = rtRange;
    this.mzRange = mzRange;

    //  setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    ticPlot = new TICPlot(this);
    add(ticPlot, BorderLayout.CENTER);

    // toolBar = new TICToolBar(this);
    toolBar = new TICToolBar(ticPlot);
    add(toolBar, BorderLayout.EAST);

    // add all peaks
    if (peaks != null) {

        for (Feature peak : peaks) {

            if (peakLabels != null && peakLabels.containsKey(peak)) {

                final String label = peakLabels.get(peak);
                ticPlot.addLabelledPeakDataset(new PeakDataSet(peak, label), label);

            } else {

                ticPlot.addPeakDataset(new PeakDataSet(peak));
            }
        }
    }

    // add all data files
    for (RawDataFile dataFile : dataFiles) {
        addRawDataFile(dataFile);
    }

    pack();

}

From source file:edu.ku.brc.util.thumbnails.Thumbnailer.java

/**
 * /*from  ww w. j a  va  2  s.co m*/
 */
private Thumbnailer() {
    mimeTypeToGeneratorMap = new Hashtable<String, ThumbnailGeneratorIFace>();

    quality = 1f;
    maxSize = new Dimension(100, 100);
}

From source file:es.udl.asic.user.OpenLdapDirectoryProvider.java

public boolean authenticateUser(String userLogin, UserEdit edit, String password) {
    Hashtable env = new Hashtable();
    InitialDirContext ctx;/*  w w  w.j av  a 2 s. c  o m*/

    String INIT_CTX = "com.sun.jndi.ldap.LdapCtxFactory";
    String MY_HOST = getLdapHost() + ":" + getLdapPort();
    String cn;
    boolean returnVal = false;

    if (!password.equals("")) {

        env.put(Context.INITIAL_CONTEXT_FACTORY, INIT_CTX);
        env.put(Context.PROVIDER_URL, MY_HOST);
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_CREDENTIALS, "secret");

        String[] returnAttribute = { "ou" };
        SearchControls srchControls = new SearchControls();
        srchControls.setReturningAttributes(returnAttribute);
        srchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        String searchFilter = "(&(objectclass=person)(uid=" + escapeSearchFilterTerm(userLogin) + "))";

        try {
            ctx = new InitialDirContext(env);
            NamingEnumeration answer = ctx.search(getBasePath(), searchFilter, srchControls);
            String trobat = "false";

            while (answer.hasMore() && trobat.equals("false")) {

                SearchResult sr = (SearchResult) answer.next();
                String dn = sr.getName().toString() + "," + getBasePath();

                // Second binding
                Hashtable authEnv = new Hashtable();
                try {
                    authEnv.put(Context.INITIAL_CONTEXT_FACTORY, INIT_CTX);
                    authEnv.put(Context.PROVIDER_URL, MY_HOST);
                    authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
                    authEnv.put(Context.SECURITY_PRINCIPAL, sr.getName() + "," + getBasePath());
                    authEnv.put(Context.SECURITY_CREDENTIALS, password);
                    try {
                        DirContext authContext = new InitialDirContext(authEnv);
                        returnVal = true;
                        trobat = "true";
                        authContext.close();
                    } catch (AuthenticationException ae) {
                        M_log.info("Access forbidden");
                    }

                } catch (NamingException namEx) {
                    M_log.info("User doesn't exist");
                    returnVal = false;
                    namEx.printStackTrace();
                }
            }
            if (trobat.equals("false"))
                returnVal = false;

        } catch (NamingException namEx) {
            namEx.printStackTrace();
            returnVal = false;
        }
    }
    return returnVal;
}