List of usage examples for java.util HashMap get
public V get(Object key)
From source file:cooccurrence.Omer_Levy.java
/** * Method to populate the apache matrix from cooccur hashmap * @param matrixR/* ww w. j a va2 s . com*/ * @param cooccur * @param rowStrings * @param colStrings */ private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur, ArrayList<String> rowStrings, ArrayList<String> colStrings) { Iterator iter = cooccur.keySet().iterator(); while (iter.hasNext()) { String row = iter.next().toString(); int i = rowStrings.indexOf(row); HashMap<String, Double> inner = cooccur.get(row); for (String col : inner.keySet()) { int j = colStrings.indexOf(col); double val = inner.get(col); matrixR.setEntry(i, j, val); } iter.remove(); } }
From source file:foam.zizim.android.net.BoskoiHttpClient.java
/** * Upload sms to ushahidi/*from w ww. jav a2 s. c o m*/ * @param address * @return * @throws MalformedURLException * @throws IOException * TODO Think through this method and make it more generic. */ public static boolean postSmsToUshahidi(String URL, HashMap<String, String> params) throws IOException { ClientHttpRequest req = null; try { URL url = new URL(URL); req = new ClientHttpRequest(url); req.setParameter("task", params.get("task")); req.setParameter("username", params.get("username")); req.setParameter("password", params.get("password")); req.setParameter("message_from", params.get("message_from")); req.setParameter("message_description", params.get("message_description")); InputStream serverInput = req.post(); //Log.i("Send output ","There its "+GetText(serverInput)); if (Util.extractPayloadJSON(GetText(serverInput))) { return true; } } catch (MalformedURLException ex) { //fall through and return false } return false; }
From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java
private static void eliminateNames(HashSet<String> posibleNames, HashMap<String, String> actualFile) { for (String name : posibleNames) { //Check if the name is in allmost the others languages double totalLenguages = actualFile.size(); int goal = (int) (totalLenguages * 0.8); //80% of the lenguages int contains = 0; for (String lang : actualFile.keySet()) { if (actualFile.get(lang).contains(name)) { contains++;//from www . j a v a2s. c o m } } if (contains >= goal) //Eliminate the name { //System.out.println(name); for (String lang : actualFile.keySet()) { String text = actualFile.get(lang); String replacement = "(\\p{Space}|\\p{Punct})+" + name + "(\\p{Space}|\\p{Punct})+"; text = text.replaceAll(replacement, " "); actualFile.put(lang, text); } } } }
From source file:bb.mcmc.analysis.ConvergeStatUtils.java
public static HashMap<String, double[]> traceInfoToArrays(HashMap<String, ArrayList<Double>> traceInfo, int burnin) { HashMap<String, double[]> newValues = new HashMap<String, double[]>(); final Set<String> names = traceInfo.keySet(); for (String key : names) { final List<Double> t = getSubList(traceInfo.get(key), burnin); newValues.put(key, Doubles.toArray(t)); }//from w w w . j av a2 s . c o m return newValues; }
From source file:jp.mamesoft.mailsocketchat.Mail.java
static String logprint(String str) { for (int i = Mailsocketchat.logs.size() - 1; i >= 0; i--) { HashMap<String, String> log = Mailsocketchat.logs.get(i); if (Mailsocketchat.subjectname || !Mailsocketchat.push) { str = str + log.get("name") + "> "; }// w ww . j a va2 s . c o m str = str + log.get("comment"); if (log.containsKey("channel")) { str = str + log.get("channel"); } if (Mailsocketchat.logformat.equals("all")) { str = str + " (" + log.get("ip") + "; " + log.get("time") + ")"; } if (Mailsocketchat.logformat.equals("normal")) { str = str + " (" + log.get("ip"); if (!Mailsocketchat.push) { str = str + "; " + log.get("simpletime"); } str = str + ")"; } if (Mailsocketchat.logformat.equals("simple") && !Mailsocketchat.push) { str = str + " (" + log.get("simpletime") + ")"; } str = str + "\n"; if (!Mailsocketchat.push) { str = str + "\n"; } } Mailsocketchat.logs.clear(); return str; }
From source file:es.sm2.openppm.core.plugin.PluginTemplate.java
/** * Load template for plugin//w w w. j a va2s . c o m * * @param templateName * @param data * @return * @throws IOException * @throws TemplateException */ public static String getTemplate(String templateName, HashMap<String, Object> data) throws IOException, TemplateException { Logger log = LogManager.getLog(PluginTemplate.class); // Print data to logger if (log.isDebugEnabled()) { log.debug("Create Template: " + templateName); if (data != null && !data.isEmpty()) { for (String key : data.keySet()) { log.debug("Parameter: " + key + " Value: " + data.get(key)); } } } // Load template InputStream stream = PluginTemplate.class.getResourceAsStream(templateName); String teamplate = IOUtils.toString(stream); // Create loader StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate("template", teamplate); // Create configuration Configuration cfg = new Configuration(); cfg.setTemplateLoader(stringLoader); Template template = cfg.getTemplate("template"); StringWriter writer = new StringWriter(); template.process(data, writer); return writer.toString(); }
From source file:com.concursive.connect.web.webdav.WebdavManager.java
public static int validateUser(Connection db, HttpServletRequest req) throws Exception { String argHeader = req.getHeader("Authorization"); HashMap params = getAuthenticationParams(argHeader); String username = (String) params.get("username"); if (md5Helper == null) { md5Helper = MessageDigest.getInstance("MD5"); }/*w w w.j av a2 s .c om*/ int userId = -1; String password = null; PreparedStatement pst = db.prepareStatement( "SELECT user_id, webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? "); pst.setString(1, username); pst.setBoolean(2, true); ResultSet rs = pst.executeQuery(); if (rs.next()) { userId = rs.getInt("user_id"); password = rs.getString("webdav_password"); } rs.close(); pst.close(); if (userId == -1) { return userId; } String method = req.getMethod(); String uri = (String) params.get("uri"); String a2 = MD5Encoder.encode(md5Helper.digest((method + ":" + uri).getBytes())); String digest = MD5Encoder .encode(md5Helper.digest((password + ":" + params.get("nonce") + ":" + a2).getBytes())); if (!digest.equals(params.get("response"))) { userId = -1; } return userId; }
From source file:com.ms.app.web.commons.tools.DateViewTools.java
private static SimpleDateFormat getFormat(String key) { HashMap<String, SimpleDateFormat> map = formatHolder.get(); if (map == null) { map = new HashMap<String, SimpleDateFormat>(2); formatHolder.set(map);// ? }// w ww .jav a 2 s. com SimpleDateFormat simpleDateFormat = map.get(key); if (simpleDateFormat == null) { simpleDateFormat = new SimpleDateFormat(key); map.put(key, simpleDateFormat); formatHolder.set(map);// ? } return simpleDateFormat; }
From source file:nz.co.senanque.validationengine.ValidationUtils.java
/** * From http://www.apply-templates.com/en/blog?title=Getting%20unique%20values%20from%20a%20list%20in%20Java * Note that HashMap uses the Object's hash code for a unique identifier. * If this method is overridden, it is possible that HashMaps may not work properly with those Objects. * @param <T>/*from w ww . j a v a2s . c o m*/ * @param list * @return a list of unique objects from the list */ public static <T extends Object> List<T> getUniques(final List<T> list) { //Initiate the necessary variables. final List<T> uniques = new ArrayList<T>(); //We declare the map to be final and it will be garbage //collected at the end of this method's execution, making //the space used by the map temporary. final HashMap<T, T> hm = new HashMap<T, T>(); //Loop through all of the elements. for (T t : list) { //If you don't find the object in the map, it is //unique and we add it to the uniques list. if (hm.get(t) == null) { hm.put(t, t); uniques.add(t); } } return uniques; }
From source file:com.collabnet.ccf.teamforge.TFAppHandler.java
public static HashMap<String, List<TrackerFieldDO>> loadTrackerFieldsInHashMap(TrackerFieldDO[] flexFields) { HashMap<String, List<TrackerFieldDO>> fieldsMap = new HashMap<String, List<TrackerFieldDO>>(); for (TrackerFieldDO field : flexFields) { String fieldName = field.getName(); // FIXME Will we ever get two field with same name in method? if (fieldsMap.containsKey(fieldName)) { List<TrackerFieldDO> fieldsList = fieldsMap.get(fieldName); fieldsList.add(field);//from www .j a v a2s . c o m } else { List<TrackerFieldDO> fieldsList = new ArrayList<TrackerFieldDO>(); fieldsList.add(field); fieldsMap.put(fieldName, fieldsList); } } return fieldsMap; }