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:com.salas.bbservice.service.forum.ForumHandler.java

/**
 * Returns the list of forums available for posting. The map contains
 * Forum-ID to Forum-Name mapping./*www  . ja  v  a 2s  . c om*/
 *
 * @return list of available forums.
 */
public Hashtable getForums() {
    IForumDao forumDao = getForumDao();

    Hashtable forums = new Hashtable();
    List forumsList = forumDao.listForums();
    for (int i = 0; i < forumsList.size(); i++) {
        Forum forum = (Forum) forumsList.get(i);
        forums.put(Integer.toString(forum.getId()), forum.getName());
    }

    return forums;
}

From source file:info.novatec.testit.livingdoc.repository.FileSystemRepository.java

private List<Object> toHierarchyNodeVector(File file) {
    List<Object> vector = new Vector<Object>();
    vector.add(0, URIUtil.relativize(root.getAbsolutePath(), file.getAbsolutePath()));
    vector.add(1, !file.isDirectory());//w  w  w.jav a 2  s  . c  om
    vector.add(2, false);

    Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
    if (file.isDirectory() && file.listFiles() != null) {
        for (File node : file.listFiles(NOT_HIDDEN)) {
            hashtable.put(node.getName(), toHierarchyNodeVector(node));
        }
    }

    vector.add(3, hashtable);
    return vector;
}

From source file:Main.java

  public Main() {
  try {/*from   w w  w .  j a v  a2  s . co  m*/
    SyncFactory.registerProvider("MySyncProvider");
    Hashtable env = new Hashtable();
    env.put(SyncFactory.ROWSET_SYNC_PROVIDER, "MySyncProvider");
    crs = new CachedRowSetImpl(env);
    crs.execute(); // load data from custom RowSetReader

    System.out.println("Fetching from RowSet...");
    while (crs.next()) {
      displayData();
    }

    if (crs.isAfterLast() == true) {
      System.out.println("We have reached the end");
      System.out.println("crs row: " + crs.getRow());
    }

    System.out.println("And now backwards...");

    while (crs.previous()) {
      displayData();
    } // end while previous

    if (crs.isBeforeFirst()) {
      System.out.println("We have reached the start");
    }

    crs.first();
    if (crs.isFirst()) {
      System.out.println("We have moved to first");
    }

    System.out.println("crs row: " + crs.getRow());

    if (!crs.isBeforeFirst()) {
      System.out.println("We aren't before the first row.");
    }

    crs.last();
    if (crs.isLast()) {
      System.out.println("...and now we have moved to the last");
    }

    System.out.println("crs row: " + crs.getRow());

    if (!crs.isAfterLast()) {
      System.out.println("we aren't after the last.");
    }

  } catch (SQLException e) {
    e.printStackTrace();
    System.err.println("SQLException: " + e.getMessage());
  }
}

From source file:com.cloudbase.datacommands.CBSearchCondition.java

/**
 * Creates a new search condition for geographical searches. This looks for documents within a given boundary box
 * defined by the coordinates of its North-Eastern and South-Western corners.
 * @param NECorner The coordinates for the north eastern corner
 * @param SWCorner The coordinates for the south western corner
 *///from   w  w w  .ja va 2  s.co  m
public CBSearchCondition(BlackBerryLocation NECorner, BlackBerryLocation SWCorner) {
    Vector box = new Vector();
    Vector NECornerList = new Vector();
    NECornerList.addElement(Double.toString((NECorner.getQualifiedCoordinates().getLatitude())));
    NECornerList.addElement(Double.toString((NECorner.getQualifiedCoordinates().getLongitude())));
    Vector SWCornerList = new Vector();
    SWCornerList.addElement(Double.toString((SWCorner.getQualifiedCoordinates().getLatitude())));
    SWCornerList.addElement(Double.toString((SWCorner.getQualifiedCoordinates().getLongitude())));
    box.addElement(SWCornerList);
    box.addElement(NECornerList);

    Hashtable boxCondition = new Hashtable();
    boxCondition.put("$box", box);

    Hashtable searchQuery = new Hashtable();
    searchQuery.put("$within", boxCondition);

    this.setField("cb_location");
    this.setOperator(CBSearchConditionOperator.CBOperatorEqual);
    this.setValue(searchQuery);
    this.limit = -1;

    this.setCommandType(CBDataAggregationCommandType.CBDataAggregationMatch);
}

From source file:com.stratelia.silverpeas.versioning.jcr.impl.AbstractJcrTestCase.java

@Resource
public void setDataSource(DataSource datasource) {
    this.datasource = datasource;
    try {//from  w ww  .  j  a  v a 2  s.  com
        prepareJndi();
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        InitialContext ic = new InitialContext(env);
        Properties properties = new Properties();
        properties.load(PathTestUtil.class.getClassLoader().getResourceAsStream("jdbc.properties"));
        // Construct BasicDataSource reference
        Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory",
                null);
        ref.add(new StringRefAddr("driverClassName",
                properties.getProperty("driverClassName", "org.postgresql.Driver")));
        ref.add(new StringRefAddr("url",
                properties.getProperty("url", "jdbc:postgresql://localhost:5432/postgres")));
        ref.add(new StringRefAddr("username", properties.getProperty("username", "postgres")));
        ref.add(new StringRefAddr("password", properties.getProperty("password", "postgres")));
        ref.add(new StringRefAddr("maxActive", "4"));
        ref.add(new StringRefAddr("maxWait", "5000"));
        ref.add(new StringRefAddr("removeAbandoned", "true"));
        ref.add(new StringRefAddr("removeAbandonedTimeout", "5000"));
        rebind(ic, JNDINames.DATABASE_DATASOURCE, ref);
        rebind(ic, JNDINames.ADMIN_DATASOURCE, ref);
    } catch (NamingException nex) {
        nex.printStackTrace();
    } catch (IOException nex) {
        nex.printStackTrace();
    }
}

From source file:components.SliderDemo2.java

public SliderDemo2() {
    super(new BorderLayout());

    delay = 1000 / FPS_INIT;/*from ww w.  j  a  v a 2  s.co m*/

    //Create the slider.
    JSlider framesPerSecond = new JSlider(JSlider.VERTICAL, FPS_MIN, FPS_MAX, FPS_INIT);
    framesPerSecond.addChangeListener(this);
    framesPerSecond.setMajorTickSpacing(10);
    framesPerSecond.setPaintTicks(true);

    //Create the label table.
    Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
    //PENDING: could use images, but we don't have any good ones.
    labelTable.put(new Integer(0), new JLabel("Stop"));
    //new JLabel(createImageIcon("images/stop.gif")) );
    labelTable.put(new Integer(FPS_MAX / 10), new JLabel("Slow"));
    //new JLabel(createImageIcon("images/slow.gif")) );
    labelTable.put(new Integer(FPS_MAX), new JLabel("Fast"));
    //new JLabel(createImageIcon("images/fast.gif")) );
    framesPerSecond.setLabelTable(labelTable);

    framesPerSecond.setPaintLabels(true);
    framesPerSecond.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));

    //Create the label that displays the animation.
    picture = new JLabel();
    picture.setHorizontalAlignment(JLabel.CENTER);
    picture.setAlignmentX(Component.CENTER_ALIGNMENT);
    picture.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    updatePicture(0); //display first frame

    //Put everything together.
    add(framesPerSecond, BorderLayout.LINE_START);
    add(picture, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Set up a timer that calls this object's action handler.
    timer = new Timer(delay, this);
    timer.setInitialDelay(delay * 7); //We pause animation twice per cycle
                                      //by restarting the timer
    timer.setCoalesce(true);
}

From source file:org.acein.wish.WishRequest.java

public WishRequest(WishSession session, String method, String path, Hashtable<String, String> params) {
    this.session = session;
    this.method = method;
    this.path = path;
    params.put("access_token", session.getAccessToken());

    if (session.getMerchantId() != null) {
        params.put("merchant_id", session.getMerchantId());
    }//w  w w  .  ja  va 2s .  c om
    this.params = params;
}

From source file:com.duroty.application.files.actions.DownloadFileAction.java

/**
 * DOCUMENT ME!//from   ww w  . j ava 2s .  c o  m
 *
 * @param request DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected Hashtable getContextProperties(HttpServletRequest request) {
    Hashtable props = (Hashtable) SessionManager.getObject(Constants.CONTEXT_PROPERTIES, request);

    if (props == null) {
        props = new Hashtable();

        props.put(Context.INITIAL_CONTEXT_FACTORY,
                Configuration.properties.getProperty(Configuration.JNDI_INITIAL_CONTEXT_FACTORY));
        props.put(Context.URL_PKG_PREFIXES,
                Configuration.properties.getProperty(Configuration.JNDI_URL_PKG_PREFIXES));
        props.put(Context.PROVIDER_URL, Configuration.properties.getProperty(Configuration.JNDI_PROVIDER_URL));

        Principal principal = request.getUserPrincipal();
        props.put(Context.SECURITY_PRINCIPAL, principal.getName());
        props.put(Context.SECURITY_CREDENTIALS, SessionManager.getObject(Constants.JAAS_PASSWORD, request));

        props.put(Context.SECURITY_PROTOCOL,
                Configuration.properties.getProperty(Configuration.SECURITY_PROTOCOL));

        SessionManager.setObject(Constants.CONTEXT_PROPERTIES, props, request);
    }

    return props;
}

From source file:com.stratuscom.harvester.deployer.FolderBasedAppRunner.java

private void registerApplication(ServiceLifeCycle deployedApp) throws MalformedObjectNameException,
        InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(com.stratuscom.harvester.Strings.NAME, deployedApp.getName());
    ObjectName oName = new ObjectName(com.stratuscom.harvester.Strings.CONTAINER_JMX_DOMAIN, props);
    mbeanRegistrar.getMbeanServer().registerMBean(deployedApp, oName);
}

From source file:com.openmeap.json.JSONObjectBuilderTest.java

public void testToJSON() throws Exception {
    RootClass root = new RootClass();
    root.setDoubleValue(Double.valueOf("3.14"));
    root.setLongValue(new Long(Long.parseLong("1000")));
    root.setIntegerValue(new Integer(Integer.parseInt("2000")));
    root.setStringValue("value");
    root.setStringArrayValue(new String[] { "value1", "value2" });
    root.setChild(new BranchClass());
    root.getChild().setTypeOne(Types.TWO);
    root.getChild().setTypeTwo(Types.ONE);
    root.getChild().setString("child_string");

    Hashtable table = new Hashtable();
    table.put("key1", "value1");
    table.put("key2", new Long(1000));
    table.put("key3", new Integer(1000));
    root.setHashTable(table);//  w  w w . j a  v a 2s  .com

    Vector vector = new Vector();
    vector.add(Long.valueOf(1));
    vector.add(Long.valueOf(2));
    vector.add(Long.valueOf(3));
    root.setVector(vector);

    JSONObjectBuilder builder = new JSONObjectBuilder();
    JSONObject jsonObj = builder.toJSON(root);
    System.out.println(jsonObj.toString());
    Assert.assertEquals(
            "{\"stringValue\":\"value\",\"vector\":[1,2,3],\"integerValue\":2000,"
                    + "\"stringArrayValue\":[\"value1\",\"value2\"],"
                    + "\"hashTable\":{\"key3\":1000,\"key2\":1000,\"key1\":\"value1\"},"
                    + "\"doubleValue\":\"3.14\",\"longValue\":1000,"
                    + "\"child\":{\"string\":\"child_string\",\"typeTwo\":\"ONE\",\"typeOne\":\"TWO\"}}",
            jsonObj.toString());
    RootClass afterRoundTrip = (RootClass) builder.fromJSON(jsonObj, new RootClass());
    Assert.assertEquals(builder.toJSON(afterRoundTrip).toString(), jsonObj.toString());
}