List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:com.zimbra.cs.account.CsrfTokenKey.java
private static synchronized void refresh(boolean reload) throws ServiceException { Provisioning prov = Provisioning.getInstance(); Config config = prov.getConfig();/*from w ww. j a va2s.co m*/ // force reload if (reload) prov.reload(config); String key = config.getAttr(Provisioning.A_zimbraCsrfTokenKey); if (key == null) { prov.reload(config); key = config.getAttr(Provisioning.A_zimbraCsrfTokenKey); } // bootstrap. automatically create new random key if (key == null) { CsrfTokenKey csrfKey = new CsrfTokenKey(0, null); HashMap<String, String> attrs = new HashMap<String, String>(); attrs.put(Provisioning.A_zimbraCsrfTokenKey, csrfKey.getEncoded()); Provisioning.getInstance().modifyAttrs(config, attrs); key = config.getAttr(Provisioning.A_zimbraCsrfTokenKey); } CsrfTokenKey csrfKey = tokenCache.get(key); if (csrfKey == null) { csrfKey = new CsrfTokenKey(key); tokenCache.put(key, csrfKey); tokenCache.put(Long.toString(csrfKey.keyVersion), csrfKey); if (latestCsrfKey == null || latestCsrfKey.keyVersion < csrfKey.keyVersion) latestCsrfKey = csrfKey; } }
From source file:com.splout.db.common.SQLiteJDBCManager.java
private static List<HashMap<String, Object>> convertResultSetToList(ResultSet rs, int maxResults) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); while (rs.next() && list.size() < maxResults) { HashMap<String, Object> row = new HashMap<String, Object>(columns); for (int i = 1; i <= columns; ++i) { row.put(md.getColumnName(i), rs.getObject(i)); }//from w ww . j av a 2 s. c o m list.add(row); } if (list.size() == maxResults) { throw new SQLException("Hard limit on number of results reached (" + maxResults + "), please use a LIMIT for this query."); } return list; }
From source file:com.zimbra.cs.account.AuthTokenKey.java
private static synchronized void refresh(boolean reload) throws ServiceException { Provisioning prov = Provisioning.getInstance(); Config config = prov.getConfig();/*from w w w. j av a2s . com*/ // force reload if (reload) prov.reload(config); String[] keys = config.getMultiAttr(Provisioning.A_zimbraAuthTokenKey); if (keys.length == 0) { prov.reload(config); keys = config.getMultiAttr(Provisioning.A_zimbraAuthTokenKey); } // bootstrap. automatically create new random key if (keys.length == 0) { AuthTokenKey key = new AuthTokenKey(0, null); HashMap<String, String> attrs = new HashMap<String, String>(); attrs.put(Provisioning.A_zimbraAuthTokenKey, key.getEncoded()); Provisioning.getInstance().modifyAttrs(config, attrs); keys = config.getMultiAttr(Provisioning.A_zimbraAuthTokenKey); } for (int i = 0; i < keys.length; i++) { AuthTokenKey key = mCache.get(keys[i]); if (key == null) { key = new AuthTokenKey(keys[i]); mCache.put(keys[i], key); mCache.put(Long.toString(key.mVersion), key); if (sLatestKey == null || sLatestKey.mVersion < key.mVersion) sLatestKey = key; } } }
From source file:com.savvywits.wethepeople.RESTResultFragment.java
public static void updateResults(String results) { try {/*w ww . j a v a2s . c o m*/ JSONObject jobj = new JSONObject(results); JSONArray jarray = new JSONArray(); jarray = jobj.getJSONArray(RESULTS); int length = jarray.length(); for (int i = 0; i < length; i++) { // Use a hash map because Java does not do associative array HashMap<String, String> map = new HashMap<String, String>(); JSONObject r = jarray.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", r.getString(NAME)); map.put("party", r.getString(PARTY)); map.put("state", r.getString(STATE)); map.put("district", r.getString(DISTRICT)); map.put("address", r.getString(OFFICE_ADDRESS)); map.put("phone", r.getString(PHONE)); map.put("link", r.getString(LINK)); mReplist.add(map); } } catch (JSONException e) { Log.e(TAG, "Error parsing data [" + e.getMessage() + "] " + results); } mAdapter.notifyDataSetChanged(); }
From source file:com.xfinity.ceylon_steel.controller.CustomerController.java
public static void downloadCustomers(final Context context) { new AsyncTask<User, Void, JSONArray>() { @Override/*from w w w .j av a2 s . com*/ protected void onPreExecute() { if (UserController.progressDialog == null) { UserController.progressDialog = new ProgressDialog(context); UserController.progressDialog.setMessage("Downloading Data"); UserController.progressDialog.setCanceledOnTouchOutside(false); } if (!UserController.progressDialog.isShowing()) { UserController.progressDialog.show(); } } @Override protected JSONArray doInBackground(User... users) { try { User user = users[0]; HashMap<String, Object> parameters = new HashMap<String, Object>(); parameters.put("userId", user.getUserId()); return getJsonArray(getCustomersOfUser, parameters, context); } catch (IOException ex) { Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex); } return null; } @Override protected void onPostExecute(JSONArray result) { if (UserController.atomicInteger.decrementAndGet() == 0 && UserController.progressDialog != null && UserController.progressDialog.isShowing()) { UserController.progressDialog.dismiss(); UserController.progressDialog = null; } if (result != null) { SQLiteDatabaseHelper databaseInstance = SQLiteDatabaseHelper.getDatabaseInstance(context); SQLiteDatabase database = databaseInstance.getWritableDatabase(); SQLiteStatement compiledStatement = database .compileStatement("replace into tbl_customer(customerId,customerName) values(?,?)"); try { database.beginTransaction(); for (int i = 0; i < result.length(); i++) { JSONObject customer = result.getJSONObject(i); compiledStatement.bindAllArgsAsStrings( new String[] { Integer.toString(customer.getInt("customerId")), customer.getString("customerName") }); long response = compiledStatement.executeInsert(); if (response == -1) { return; } } database.setTransactionSuccessful(); Toast.makeText(context, "Customers downloaded successfully", Toast.LENGTH_SHORT).show(); } catch (JSONException ex) { Logger.getLogger(CustomerController.class.getName()).log(Level.SEVERE, null, ex); Toast.makeText(context, "Unable parse customers", Toast.LENGTH_SHORT).show(); } finally { database.endTransaction(); databaseInstance.close(); } } else { Toast.makeText(context, "Unable to download customers", Toast.LENGTH_SHORT).show(); } } }.execute(UserController.getAuthorizedUser(context)); }
From source file:com.all.services.ServiceInteractiveConsole.java
@SuppressWarnings("unchecked") private static void execute(String hostname, String password, String command) throws IOException, MalformedObjectNameException { HashMap env = new HashMap(); env.put("jmx.remote.credentials", new String[] { "controlRole", password }); String serviceURL = "service:jmx:rmi:///jndi/rmi://" + hostname + ":9999/jmxrmi"; JMXServiceURL url = new JMXServiceURL(serviceURL); LOG.info("Connecting to " + serviceURL); JMXConnector jmxc = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.all.services:type=ServiceMonitor"); ServiceMonitorMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, ServiceMonitorMBean.class, true); ServiceConsole.handleCommand(mbeanProxy, command); }
From source file:mailjimp.dom.request.campaign.CampaignListRequest.java
static public HashMap<String, Object> buildFilters(String campaignId, String listId, Integer folderId, Integer templateId, String status, String type, String fromName, String fromEmail, String title, String subject, Date sendTimeStart, Date sendTimeEnd, Boolean exact) { HashMap<String, Object> options = new HashMap<String, Object>(); if (campaignId != null) options.put("campaign_id", campaignId); if (listId != null) options.put("list_id", listId); if (folderId != 0) options.put("folderId", (int) folderId); if (templateId != null) options.put("template_id", templateId); if (status != null) options.put("status", status); if (type != null) options.put("type", type); if (fromName != null) options.put("from_name", fromName); if (fromEmail != null) options.put("from_email", fromEmail); if (title != null) options.put("title", title); if (subject != null) options.put("subject", subject); if (sendTimeStart != null) options.put("sendtime_start", df.print(sendTimeStart, Locale.US)); if (sendTimeEnd != null) options.put("sendtime_end", df.print(sendTimeStart, Locale.US)); if (exact != null) options.put("exact", (boolean) exact); return options; }
From source file:SageCollegeProject.guideBox.java
public static void setAllTitleURLs() { HashMap<String, String> urlsMap = new HashMap<String, String>(); for (guide_ShowObject cur : ReadAllShowsfromFile()) { urlsMap.put(cur.getTitle(), cur.getArtwork_208x117()); }// www.j a v a 2s . c o m URLMap.putAll(urlsMap); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo.java
public static Map<String, String> getSortedMap(Map<String, String> hmap, Comparator<String[]> comparator, VitroRequest vreq) {/*www. j a va2 s . co m*/ // first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size()); for (String key : hmap.keySet()) { String[] x = new String[2]; x[0] = key; x[1] = hmap.get(key); objectsToSort.add(x); } //if no comparator is passed in, utilize MapPairsComparator if (comparator == null) { comparator = new MapPairsComparator(vreq); } Collections.sort(objectsToSort, comparator); HashMap<String, String> map = new LinkedHashMap<String, String>(objectsToSort.size()); for (String[] pair : objectsToSort) { map.put(pair[0], pair[1]); } return map; }
From source file:com.ett.common.util.StringUtil.java
/** * @param map ?Map/*from w w w . j a v a 2s. co m*/ * @param key key * @param value 17 */ public static void addParamterToMap(HashMap map, String key, Object value) { log.info("?17" + key + "" + value + "HashMap17"); map.put(key, value); /*if(map.containsKey(key)) { map.remove(key); }*/ }