Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

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

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:expect4j.ExpectUtils.java

/**
 * Creates an SSH session to the given server on a custom TCP port
 * using the provided credentials.  This is equivalent to Expect's
 * <code>spawn ssh $hostname</code>.
 *
 * @param hostname the DNS or IP address of the remote server
 * @param username the account name to use when authenticating
 * @param password the account password to use when authenticating
 * @param port the TCP port for the SSH service
 * @return the controlling Expect4j instance
 * @throws Exception on a variety of errors
 *//*from   w  w  w . j av a 2s  .  c om*/
public static Expect4j SSH(String hostname, String username, String password, int port) throws Exception {
    logger.debug("Creating SSH session with " + hostname + ":" + port + " as " + username);

    JSch jsch = new JSch();

    //jsch.setKnownHosts("/home/foo/.ssh/known_hosts");

    Session session = jsch.getSession(username, hostname, port);
    if (password != null) {
        logger.trace("Setting the Jsch password to the one provided (not shown)");
        session.setPassword(password);
    }

    java.util.Hashtable config = new java.util.Hashtable();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.setDaemonThread(true);
    session.connect(3 * 1000); // making a connection with timeout.

    ChannelShell channel = (ChannelShell) session.openChannel("shell");

    //channel.setInputStream(System.in);
    //channel.setOutputStream(System.out);

    channel.setPtyType("vt102");

    Hashtable env = new Hashtable();
    //env.put("LANG", "ja_JP.eucJP");
    channel.setEnv(env);

    Expect4j expect = new Expect4j(channel.getInputStream(), channel.getOutputStream());

    channel.connect(5 * 1000);

    return expect;
}

From source file:bide.simulation.Simulation.java

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

    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);
        setupPi[i] = rd.nextGaussian(1, 1);
    }//from w  w  w.j  a v  a 2 s .c  o  m
    Arrays.fill(setupDelta, 0);
    Arrays.fill(setupRho, 0);

    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: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 {//ww w  .  j  av  a2s  .c  o m
            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:bide.simulation.Simulation.java

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

    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  w  w .  j a v  a2s.  c o  m*/
            setupDelta[i] = -rd.nextExponential(oneOverLambda);
        }
        setupPi[i] = rd.nextUniform(-1, 3);
        setupRho[i] = rd.nextUniform(-2, 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:no.smint.anthropos.ldap.LDAP.java

/**
 * Binds anonymously to the LDAP server. Returns a <code>Hashtable</code> to use for searching etc.
 * @return <code>Hashtable</code> with the binding to the server.
 *//*from  w w  w  .  j  av a2s.  com*/
public static Hashtable<String, Object> config() {
    Hashtable<String, Object> env = new Hashtable<String, Object>();

    //Connection details
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, host);
    env.put(Context.SECURITY_AUTHENTICATION, "none");

    //Optional for testing purposes
    //env.put(Context.SECURITY_AUTHENTICATION, "simple");
    //env.put(Context.SECURITY_PRINCIPAL, "uid=birgith.do,ou=System Users,dc=studentmeidene,dc=no");
    //env.put(Context.SECURITY_CREDENTIALS, "overrated rapid machine");
    return env;
}

From source file:bide.simulation.Simulation.java

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

    double oneOverLambda = 1.0 / (1.0 / 1.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);
            setupRho[i] = rd.nextGaussian(-3, 0.25);
        } else {/*ww  w.  j a va 2  s.c o m*/
            setupDelta[i] = -rd.nextExponential(oneOverLambda);
            setupRho[i] = rd.nextGaussian(2, 0.25);
        }
        setupPi[i] = rd.nextGaussian(1, 0.25);

    }

    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:Main.java

public static Hashtable<String, Boolean> StringToHashTable(String msg) {
    Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>();

    // Removing trailing brackets and split the string
    msg = msg.replace("{", "").replace("}", "");
    String[] items = msg.split(",");
    for (String item : items) {
        String contentName = item.split("=")[0].trim();
        String contentValue = item.split("=")[1].trim();

        // Put pair to hash table
        hash.put(contentName, Boolean.valueOf(contentValue));
    }/*from  www. jav  a  2  s . co  m*/

    return hash;
}

From source file:com.datasalt.utils.commons.URLUtils.java

/**
   Extract parameters from a url so that Ning (or other crawling utilities) 
   can properly encode them if necessary. This was necesssary for facebook requests, 
   which are bundled with "next urls" that have funny characters in them such as this 
           // w w  w.j av  a  2s. c o m
   "122524694445860|7fc6dd5fe13b43c09dad009d.1-1056745212|An3Xub_HEDRsGxVPkmy71VdkFhQ"
 * @param url
 */
public static Hashtable<String, String> extractParameters(String url) {
    Hashtable<String, String> pars = new Hashtable<String, String>();
    if (!url.contains("?")) {
        log.warn("WARNING : URL HAS NO PARAMETERS ! " + url);
        return pars;
    }
    String parameters = StringUtils.substringAfter(url, "?");
    for (String pairs : parameters.split("&")) {
        String[] nv = pairs.split("=");
        pars.put(nv[0], nv[1]);
    }
    return pars;
}

From source file:Main.java

public static Hashtable<String, String> getChildHash(Element elem) {
    if (elem == null)
        return null;
    NodeList nl = elem.getChildNodes();
    if (nl == null)
        return null;
    Hashtable<String, String> retlist = new Hashtable<String, String>(nl.getLength());
    for (int n = 0; n < nl.getLength(); n++) {
        Node child = nl.item(n);/*w w w  . jav  a  2s.  c  o  m*/
        if (child instanceof Element) {
            Element element = (Element) child;
            String key = element.getTagName();
            String value = getSimpleElementText(element);
            retlist.put(key, value);
        }
    }
    if (retlist.size() == 0)
        return null;
    return retlist;
}

From source file:Main.java

static public void fillHashtable(NodeList list, Hashtable<String, String> fillIn) {
    for (int curElemNum = 0; curElemNum < list.getLength(); curElemNum++) {
        if (list.item(curElemNum).getNodeType() != Node.ELEMENT_NODE)
            continue;
        Element curValue = (Element) list.item(curElemNum);
        String valueName = curValue.getNodeName();
        String value = curValue.getFirstChild().getNodeValue();
        fillIn.put(valueName, value);
    }/*from  w  w w  .  j  av  a2  s.  co m*/
}