List of usage examples for java.util HashMap put
public V put(K key, V value)
From source file:net.bioclipse.dbxp.business.DbxpManager.java
public static Map<String, String> authenticate() throws IOException, NoSuchAlgorithmException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(userName, password)); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); HashMap<String, String> formvars = new HashMap<String, String>(); formvars.put("deviceID", getDeviceId()); HttpResponse response = postValues(formvars, baseApiUrl + "authenticate"); BufferedReader stdInput = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String json = ""; String s = ""; while ((s = stdInput.readLine()) != null) { json += s;//from w ww . ja v a 2s . c om } Gson gson = new Gson(); Map<String, String> loginData = gson.fromJson(json, new TypeToken<Map<String, String>>() { }.getType()); token = loginData.get("token"); sequence = Integer.valueOf(loginData.get("sequence")); return loginData; }
From source file:bammerbom.ultimatecore.bukkit.UltimateConverter.java
public static void convert() { if (r.getCnfg().contains("Tp.TpaCancelDelay")) { try {//from w ww . j a v a 2s .co m r.log(ChatColor.DARK_RED + "-----------------------------------------------"); r.log("WARNING!!!"); r.log("UltimateCore is converting to 2.x ..."); r.log("Everything except HOMES and WARPS is lost!"); r.log("UltimateCore will make a backup for you: "); r.log(ChatColor.DARK_RED + "-----------------------------------------------"); Thread.sleep(10000L); r.log("Creating backup..."); FileUtil.copy(r.getUC().getDataFolder(), new File(r.getUC().getDataFolder().getParentFile(), "UltimateCore (Backup from 1.x)")); r.log("Converting..."); HashMap<UUID, HashMap<String, Location>> homes = new HashMap<>(); for (OfflinePlayer pl : r.getOfflinePlayers()) { Config conf = UC.getPlayer(pl).getPlayerConfig(); HashMap<String, Location> hom = new HashMap<>(); if (conf.contains("homes")) { for (String str : conf.getConfigurationSection("homes").getKeys(false)) { hom.put(str, LocationUtil.convertStringToLocation(conf.getString("homes." + str))); } homes.put(pl.getUniqueId(), hom); } } Config conf = new Config(UltimateFileLoader.DFwarps); HashMap<String, Location> warps = new HashMap<>(); if (conf.contains("warps")) { for (String str : conf.getConfigurationSection("warps").getKeys(false)) { warps.put(str, LocationUtil.convertStringToLocation(conf.getString("warps." + str))); } } FileUtils.deleteDirectory(r.getUC().getDataFolder()); UltimateFileLoader.Enable(); UC.getServer().setWarps(warps); for (UUID u : homes.keySet()) { UC.getPlayer(u).setHomes(homes.get(u)); } r.log("Converting complete!"); r.log(ChatColor.DARK_RED + "-----------------------------------------------"); } catch (InterruptedException | IOException ex) { ErrorLogger.log(ex, "Failed to convert from 1.x"); } } }
From source file:bammerbom.ultimatecore.spongeapi.UltimateConverter.java
public static void convert() { if (r.getCnfg().contains("Tp.TpaCancelDelay")) { try {//from w w w.j a va2 s. co m r.log(TextColors.DARK_RED + "-----------------------------------------------"); r.log("WARNING!!!"); r.log("UltimateCore is converting to 2.x ..."); r.log("Everything except HOMES and WARPS is lost!"); r.log("UltimateCore will make a backup for you: "); r.log(TextColors.DARK_RED + "-----------------------------------------------"); Thread.sleep(10000L); r.log("Creating backup..."); FileUtil.copy(r.getUC().getDataFolder(), new File(r.getUC().getDataFolder().getParentFile(), "UltimateCore (Backup from 1.x)")); r.log("Converting..."); HashMap<UUID, HashMap<String, RLocation>> homes = new HashMap<>(); for (User pl : r.getOfflinePlayers()) { Config conf = UC.getPlayer(pl).getPlayerConfig(); HashMap<String, RLocation> hom = new HashMap<>(); if (conf.contains("homes")) { for (String str : conf.getConfigurationSection("homes").getKeys(false)) { hom.put(str, LocationUtil.convertStringToLocation(conf.getString("homes." + str))); } homes.put(pl.getUniqueId(), hom); } } Config conf = new Config(UltimateFileLoader.DFwarps); HashMap<String, RLocation> warps = new HashMap<>(); if (conf.contains("warps")) { for (String str : conf.getConfigurationSection("warps").getKeys(false)) { warps.put(str, LocationUtil.convertStringToLocation(conf.getString("warps." + str))); } } FileUtils.deleteDirectory(r.getUC().getDataFolder()); UltimateFileLoader.Enable(); UC.getServer().setWarps(warps); for (UUID u : homes.keySet()) { UC.getPlayer(u).setHomes(homes.get(u)); } r.log("Converting complete!"); r.log(TextColors.DARK_RED + "-----------------------------------------------"); } catch (InterruptedException | IOException ex) { ErrorLogger.log(ex, "Failed to convert from 1.x"); } } }
From source file:org.epics.archiverappliance.utils.ui.URIUtils.java
/** * Parse the query string of a URI (typically used in archiver config strings) and return these as a name value pair hashmap. * We do not handle multiple values for the same param in this call; we simply replace previous names. * @param uri URI/*w w w.j a v a 2 s . c om*/ * @return HashMap Parse the query string * @throws IOException   */ public static HashMap<String, String> parseQueryString(URI uri) throws IOException { HashMap<String, String> ret = new HashMap<String, String>(); if (uri == null) return ret; List<NameValuePair> nvs = URLEncodedUtils.parse(uri, "UTF-8"); if (nvs == null) return ret; for (NameValuePair nv : nvs) { ret.put(nv.getName(), nv.getValue()); } return ret; }
From source file:io.lqd.sdk.model.LQValue.java
public static HashMap<String, LQValue> convertToHashMap(ArrayList<LQValue> values) { HashMap<String, LQValue> hashMap = new HashMap<String, LQValue>(); for (LQValue value : values) { if (value.getValue() != null) { if (value.getVariable().getName() != null) { hashMap.put(value.getVariable().getName(), value); }/* ww w . j a v a 2s. com*/ } } return hashMap; }
From source file:com.groupon.odo.proxylib.Utils.java
public static HashMap<String, Object> getJQGridJSON(Object[] rows, String rowName, int offset, int totalRows, int requestedRows) { HashMap<String, Object> returnVal = new HashMap<String, Object>(); double totalPages = Math.ceil((double) totalRows / (double) requestedRows); returnVal.put("records", totalRows); returnVal.put("total", totalPages); returnVal.put("page", offset / requestedRows + 1); returnVal.put(rowName, rows);/*from w ww . java 2 s . c o m*/ return returnVal; }
From source file:com.mycompany.craftdemo.utility.java
public static void send(long phno, double price, double profit, String domain, String company) { HashMap<String, String> domainMap = new HashMap<>(); domainMap.put("TMobile", "tmomail.net "); domainMap.put("ATT", "txt.att.net"); domainMap.put("Sprint", "messaging.sprintpcs.com"); domainMap.put("Verizon", "vtext.com"); String to = phno + "@" + domainMap.get(domain); //change accordingly // Sender's email ID needs to be mentioned String from = "uni5prince@gmail.com"; //change accordingly final String username = "uni5prince"; //change accordingly final String password = "savageph8893"; //change accordingly // Assuming you are sending email through relay.jangosmtp.net String host = "smtp.gmail.com"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "587"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }//from w w w . j a va 2 s.c om }); try { // Create a default MimeMessage object. Message message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Prices have gone up!!"); // Now set the actual message message.setText("Hello Jane, Stock prices for " + company + " has reached to $" + price + " with profit of $" + profit); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException e) { throw new RuntimeException(e); } }
From source file:jp.mamesoft.mailsocketchat.Mailsocketchat.java
static void Logperse(JSONObject jsondata) { if (!jsondata.isNull("comment")) { String name = jsondata.getString("name"); String comment = jsondata.getString("comment"); String ip = jsondata.getString("ip"); String time_js = jsondata.getString("time"); Pattern time_p = Pattern.compile("([0-9]{4}).([0-9]{2}).([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})"); Matcher time_m = time_p.matcher(time_js); String time = ""; String simpletime = ""; if (time_m.find()) { int year = Integer.parseInt(time_m.group(1)); int month = Integer.parseInt(time_m.group(2)); int day = Integer.parseInt(time_m.group(3)); int hour = Integer.parseInt(time_m.group(4)); int min = Integer.parseInt(time_m.group(5)); int sec = Integer.parseInt(time_m.group(6)); hour = hour + 9;/* w w w . jav a 2 s . c o m*/ if (hour >= 24) { hour = hour - 24; day = day + 1; } time = String.format("%1$04d", year) + "-" + String.format("%1$02d", month) + "-" + String.format("%1$02d", day) + " " + String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); simpletime = String.format("%1$02d", hour) + ":" + String.format("%1$02d", min) + ":" + String.format("%1$02d", sec); } String channel = ""; HashMap<String, String> log = new HashMap<String, String>(); log.put("name", name); log.put("_id", jsondata.getString("_id")); log.put("comment", comment); log.put("ip", ip); log.put("time", time); log.put("simpletime", simpletime); if (!jsondata.isNull("response")) { log.put("res", jsondata.getString("response")); } else { log.put("res", ""); } if (!jsondata.isNull("channel")) { HashSet<String> channels_hash = new HashSet<String>(); for (int i = 0; i < jsondata.getJSONArray("channel").length(); i++) { channels_hash.add(jsondata.getJSONArray("channel").getString(i)); } String channels[] = (String[]) channels_hash.toArray(new String[0]); for (int i = 0; i < channels.length; i++) { channel = channel + " #" + channels[i]; } log.put("channel", channel); } if (push) { logs.add(log); Mail.Send(address, 1); } else { logs.add(log); } } }
From source file:mpimp.assemblxweb.util.J5Caller.java
public static void callDesignAssemblyScript(AssemblXWebModel model, TranscriptionalUnit currentTranscriptionalUnit) throws Exception { Object result = null;//from w w w . j av a 2s . c o m currentTranscriptionalUnit.setJ5ErrorMessage(""); currentTranscriptionalUnit.setJ5FaultString(""); try { String inputFileDirectory = model.getWorkingDirectory() + File.separator + currentTranscriptionalUnit.getTuDirectoryName() + File.separator + AssemblXWebProperties.getInstance().getProperty("parameterFileDirectory"); String masterFilesDirectory = model.getPathToMasterFilesDirectory(); HashMap<String, String> parameterMap = new HashMap<String, String>(); parameterMap.put("j5_session_id", model.getJ5SessionId()); parameterMap.put("reuse_j5_parameters_file", "FALSE"); String j5ParametersFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getJ5ParametersFileName(); parameterMap.put("encoded_j5_parameters_file", J5FileUtils.encodeFileBase64(j5ParametersFileName)); parameterMap.put("reuse_sequences_list_file", "FALSE"); String sequencesListFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getSequencesListFileName(); parameterMap.put("encoded_sequences_list_file", J5FileUtils.encodeFileBase64(sequencesListFileName)); parameterMap.put("reuse_zipped_sequences_file", "FALSE"); String zippedSequencesFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getZippedSequencesFileName(); parameterMap.put("encoded_zipped_sequences_file", J5FileUtils.encodeFileBase64(zippedSequencesFileName)); parameterMap.put("reuse_parts_list_file", "FALSE"); String partsListFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getPartsListFileName(); parameterMap.put("encoded_parts_list_file", J5FileUtils.encodeFileBase64(partsListFileName)); parameterMap.put("reuse_target_part_order_list_file", "FALSE"); String targetPartsOrderListFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getTargetPartOrderListFileName(); parameterMap.put("encoded_target_part_order_list_file", J5FileUtils.encodeFileBase64(targetPartsOrderListFileName)); parameterMap.put("reuse_eugene_rules_list_file", "FALSE"); String eugeneRulesListFileName = inputFileDirectory + File.separator + currentTranscriptionalUnit.getEugeneRulesListFileName(); parameterMap.put("encoded_eugene_rules_list_file", J5FileUtils.encodeFileBase64(eugeneRulesListFileName)); parameterMap.put("reuse_master_plasmids_file", "FALSE"); String masterPlasmidsFilePath = masterFilesDirectory + File.separator + AssemblXWebProperties.getInstance().getProperty("masterPlasmidsListFileName"); parameterMap.put("encoded_master_plasmids_file ", J5FileUtils.encodeFileBase64(masterPlasmidsFilePath)); parameterMap.put("master_plasmids_list_filename", AssemblXWebProperties.getInstance().getProperty("masterPlasmidsListFileName")); if (currentTranscriptionalUnit.getIsMockAssembly() == false) { parameterMap.put("reuse_master_oligos_file", "FALSE"); String masterOligosListFilePath = masterFilesDirectory + File.separator + AssemblXWebProperties.getInstance().getProperty("masterOligosListFileName"); parameterMap.put("encoded_master_oligos_file", J5FileUtils.encodeFileBase64(masterOligosListFilePath)); parameterMap.put("master_oligos_list_filename", AssemblXWebProperties.getInstance().getProperty("masterOligosListFileName")); parameterMap.put("reuse_master_direct_syntheses_file", "FALSE"); String masterDirectSynthesisListFilePath = masterFilesDirectory + File.separator + AssemblXWebProperties.getInstance().getProperty("masterDirectSynthesisListFileName"); parameterMap.put("encoded_master_direct_syntheses_file", J5FileUtils.encodeFileBase64(masterDirectSynthesisListFilePath)); parameterMap.put("master_direct_syntheses_list_filename", AssemblXWebProperties.getInstance().getProperty("masterDirectSynthesisListFileName")); } parameterMap.put("assembly_method", AssemblXWebConstants.getAssemblyMethod(currentTranscriptionalUnit.getAssemblyMethod())); XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setServerURL(new URL("https://j5.jbei.org/bin/j5_xml_rpc.pl")); XmlRpcClient client = new XmlRpcClient(); client.setConfig(config); Object[] params = new Object[] { parameterMap }; result = client.execute("DesignAssembly", params); if (result instanceof HashMap) { @SuppressWarnings("unchecked") String faultString = ((Map<String, String>) result).get("faultString"); if (faultString != null) { currentTranscriptionalUnit.setJ5FaultString(faultString); } @SuppressWarnings("unchecked") String errorMessage = ((Map<String, String>) result).get("error_message"); if (errorMessage != null) { currentTranscriptionalUnit.setJ5ErrorMessage(errorMessage); } @SuppressWarnings("unchecked") String outputFileName = ((Map<String, String>) result).get("output_filename"); String outputFilePath = model.getWorkingDirectory() + File.separator + currentTranscriptionalUnit.getTuDirectoryName() + File.separator + outputFileName; Path path = Paths.get(outputFilePath); @SuppressWarnings("unchecked") byte[] outputFile = Base64.decodeBase64(((Map<String, String>) result).get("encoded_output_file")); Files.write(path, outputFile); String resultDirectoryName = outputFileName.replace(".zip", ""); currentTranscriptionalUnit.setResultDirectoryName(resultDirectoryName); } } catch (Exception e) { String message = "Generating of design assembly by J5 failed. Reason: " + e.getMessage() + ". You may also check if j5 (https://j5.jbei.org/) is available at all."; throw new AssemblXException(message, J5Caller.class); } }
From source file:org.bonitasoft.engine.test.BonitaTestEngine.java
public static BonitaTestEngine remoteHttp(String url, String name) { HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("server.url", url); parameters.put("application.name", name); APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP, parameters); return new BonitaTestEngine(false, false); }