List of usage examples for java.util HashMap get
public V get(Object key)
From source file:bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation.java
private static String result(MSnSpectrum msms, double precursorTolerance, HashSet<DBEntry> peptideAndMass, double fragmentTolerance, int correctionFactor, boolean hasAllPossCharge) throws IllegalArgumentException, IOException, MzMLUnmarshallerException { String res = ""; HashMap<Peptide, Boolean> allSelectedPeps = getSelectedTheoPeps(msms, precursorTolerance, peptideAndMass); // select peptides within a given precursor tolerance int scoredPeps = allSelectedPeps.size(); ArrayList<Identify> sequestResults = new ArrayList<Identify>(), andromedaResults = new ArrayList<Identify>(); // for every peptide... calculate each score... for (Peptide selectedPep : allSelectedPeps.keySet()) { Identify toCalculateSequest = new Identify(msms, selectedPep, fragmentTolerance, true, allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge), toCalculateAndromeda = new Identify(msms, selectedPep, fragmentTolerance, false, allSelectedPeps.get(selectedPep), scoredPeps, correctionFactor, hasAllPossCharge); if (toCalculateSequest.getScore() != Double.NEGATIVE_INFINITY) { sequestResults.add(toCalculateSequest); andromedaResults.add(toCalculateAndromeda); }/*from ww w . j a v a 2s . c o m*/ } if (!sequestResults.isEmpty()) { HashSet<Identify> theBestSEQUESTResults = getBestResult(sequestResults), theBestAndromedaResults = getBestResult(andromedaResults); res = printInfo(theBestAndromedaResults, theBestSEQUESTResults); } return res; }
From source file:fr.lissi.belilif.om2m.rest.WebServiceActions.java
/** * Checks if is reachable.//from www . j a v a2s. com * * @param uri the uri * @param headers the headers * @return true, if is reachable */ public static boolean isReachable(String uri, HashMap<String, String> headers) { try { HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection myURLConnection = (HttpURLConnection) new URL(uri).openConnection(); myURLConnection.setRequestMethod("HEAD"); for (String key : headers.keySet()) { myURLConnection.setRequestProperty("Authorization", headers.get(key)); } LOGGER.info(myURLConnection.getResponseCode() + " / " + myURLConnection.toString()); return (myURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:LineageSimulator.java
public static HashMap<Mutation.SNV, String> getBinaryProfile( HashMap<Mutation.SNV, double[]> multiSampleFrequencies, int numSamples) { HashMap<Mutation.SNV, String> snvProfiles = new HashMap<Mutation.SNV, String>(); for (Mutation.SNV snv : multiSampleFrequencies.keySet()) { String profile = ""; for (int i = 0; i < numSamples; i++) { if (multiSampleFrequencies.get(snv)[i] == 0) { profile += "0"; } else { profile += "1"; }/*from w ww . ja va 2s. com*/ } snvProfiles.put(snv, profile); } return snvProfiles; }
From source file:org.ofbiz.party.tool.SmsSimpleClient.java
/** * ??http POSThttp?// w w w . j a va2 s . c o m * * @param urlstr url * @return */ public static String doPostRequest(String urlstr, HashMap<String, String> content) { HttpClient client = new DefaultHttpClient(); client.getParams().setIntParameter("http.socket.timeout", 10000); client.getParams().setIntParameter("http.connection.timeout", 5000); List<NameValuePair> ls = new ArrayList<NameValuePair>(); for (String key : content.keySet()) { NameValuePair param = new BasicNameValuePair(key, content.get(key)); ls.add(param); } HttpEntity entity = null; String entityContent = null; try { HttpPost httpPost = new HttpPost(urlstr.toString()); UrlEncodedFormEntity uefe = new UrlEncodedFormEntity(ls, "UTF-8"); httpPost.setEntity(uefe); HttpResponse httpResponse = client.execute(httpPost); entityContent = EntityUtils.toString(httpResponse.getEntity()); } catch (Exception e) { Debug.logError(e, module); } finally { if (entity != null) { try { entity.consumeContent(); } catch (Exception e) { Debug.logError(e, module); } } } return entityContent; }
From source file:com.vertica.hadoop.VerticaOutputFormat.java
/** * Optionally called at the end of a job to optimize any newly created and * loaded tables. Useful for new tables with more than 100k records. * /*from ww w. j a va2 s. c o m*/ * @param conf * @throws Exception */ public static void optimize(Configuration conf) throws Exception { VerticaConfiguration vtconfig = new VerticaConfiguration(conf); Connection conn = vtconfig.getConnection(true); // TODO: consider more tables and skip tables with non-temp projections Relation vTable = new Relation(vtconfig.getOutputTableName()); Statement stmt = conn.createStatement(); ResultSet rs = null; HashSet<String> tablesWithTemp = new HashSet<String>(); //for now just add the single output table tablesWithTemp.add(vTable.getQualifiedName().toString()); // map from table name to set of projection names HashMap<String, Collection<String>> tableProj = new HashMap<String, Collection<String>>(); rs = stmt.executeQuery("select projection_schema, anchor_table_name, projection_name from projections;"); while (rs.next()) { String ptable = rs.getString(1) + "." + rs.getString(2); if (!tableProj.containsKey(ptable)) { tableProj.put(ptable, new HashSet<String>()); } tableProj.get(ptable).add(rs.getString(3)); } for (String table : tablesWithTemp) { if (!tableProj.containsKey(table)) { throw new RuntimeException("Cannot optimize table with no data: " + table); } } String designName = (new Integer(conn.hashCode())).toString(); stmt.execute("select dbd_create_workspace('" + designName + "')"); stmt.execute("select dbd_create_design('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_add_design_tables('" + designName + "', '" + vTable.getQualifiedName().toString() + "')"); stmt.execute("select dbd_populate_design('" + designName + "', '" + designName + "')"); //Execute stmt.execute("select dbd_create_deployment('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_add_deployment_design('" + designName + "', '" + designName + "', '" + designName + "')"); stmt.execute("select dbd_add_deployment_drop('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_execute_deployment('" + designName + "', '" + designName + "')"); //Cleanup stmt.execute("select dbd_drop_deployment('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_remove_design('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_drop_design('" + designName + "', '" + designName + "')"); stmt.execute("select dbd_drop_workspace('" + designName + "')"); }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
/** * changes a mapping keyType1->keyType2->value to * keyType2->keyType1->value/* w w w . j a v a 2 s. c o m*/ * * @param tariffSubscriptions * @return */ public static <K1, K2, V> HashMap<K2, HashMap<K1, V>> revertKeyMapping( HashMap<K1, HashMap<K2, V>> twoLevelMap) { HashMap<K2, HashMap<K1, V>> result = new HashMap<K2, HashMap<K1, V>>(); for (Entry<K1, HashMap<K2, V>> entry : twoLevelMap.entrySet()) { K1 key1 = entry.getKey(); HashMap<K2, V> keyvals = entry.getValue(); for (Entry<K2, V> e : keyvals.entrySet()) { K2 key2 = e.getKey(); V value = e.getValue(); HashMap<K1, V> current = result.get(key2); if (current == null) { current = new HashMap<K1, V>(); result.put(key2, current); } current.put(key1, value); } } return result; }
From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java
/** * @param allWords//from w w w .j a va 2 s . c o m * the List of all Words pulled in from the constructor * @return a Map of all Words keyed by their length */ protected static HashMap<Integer, ArrayList<Word>> mapByWordLength(List<Word> allWords) { if (allWords == null || allWords.isEmpty()) { throw new IllegalArgumentException( "Error mapping Words by length. The supplied List of Words cannot be null or empty."); } HashMap<Integer, ArrayList<Word>> byWordLength = new HashMap<Integer, ArrayList<Word>>(); for (Word w : allWords) { Integer length = w.getId().getWord().length(); // Add the part of speech to the map if it doesn't exist if (!byWordLength.containsKey(length)) { byWordLength.put(length, new ArrayList<Word>()); } /* * Add the word to the map by reference a number of times equal to * the frequency value */ for (int i = 0; i < w.getFrequencyWeight(); i++) { byWordLength.get(length).add(w); } } return byWordLength; }
From source file:marytts.server.http.MivoqSynthesisRequestHandler.java
private static String toOldStyleEffectsString(HashMap<String, ParamParser> registry, HashMap<String, Object> effects_values) { StringBuilder sb = new StringBuilder(); for (String name : effects_values.keySet()) { Object param = effects_values.get(name); if (param != null) { ParamParser parser = registry.get(name); if (parser != null) { param = parser.limit(param); String s = parser.toOldStyleString(param); if (s != null) { if (sb.length() > 0) { sb.append('+'); }//from w w w . j a v a 2 s . c o m sb.append(s); } } } } return sb.toString(); }
From source file:Main.java
public static HashMap<Integer, HashMap<Integer, Integer>> getAvailableTime(HashMap<Date, Date> bookedTimes, Date date) {//w w w . j ava 2 s .c o m HashMap<Integer, HashMap<Integer, Integer>> availableTime = createFullAvailableTime(); HashMap<Date, Date> bookedTimeInOneDate = getBookedTimeInOneDate(bookedTimes, date); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); for (Date keyBooked : bookedTimeInOneDate.keySet()) { startCalendar.setTime(keyBooked); int startHour = startCalendar.get(Calendar.HOUR_OF_DAY); for (int hourIndex = 0; hourIndex < 24; hourIndex++) { if (hourIndex == startHour) { int startMinute = startCalendar.get(Calendar.MINUTE); int endMinute; endCalendar.setTime(bookedTimeInOneDate.get(keyBooked)); int endHour = endCalendar.get(Calendar.HOUR_OF_DAY); //startHour = endHour = hourIndex if (endHour == hourIndex) { endMinute = endCalendar.get(Calendar.MINUTE); removeMinute(startMinute, endMinute, hourIndex, availableTime); } //startHour = hourIndex != endHour else { for (int i = hourIndex; i < endHour + 1; i++) { if (i == hourIndex) { if (startMinute == 0) { availableTime.remove(startHour); } else { removeMinute(startMinute, 59, hourIndex, availableTime); } } else if (i == endHour) { endMinute = endCalendar.get(Calendar.MINUTE); if (endMinute == 59) { availableTime.remove(endHour); } else { removeMinute(0, endMinute, endHour, availableTime); } } else { availableTime.remove(i); } } } } } } return availableTime; }
From source file:jsave.Utils.java
public static HashMap<String, Object> read_typedesc(final RandomAccessFile raf) throws IOException, Exception { HashMap<String, Object> typedesc = new HashMap<>(); typedesc.put("typecode", read_long(raf)); typedesc.put("varflags", read_long(raf)); if (2 == ((int) typedesc.get("varflags") & 2)) { throw new Exception("System variables not implemented"); }//from w w w. jav a2s . co m typedesc.put("array", ((int) typedesc.get("varflags") & 4) == 4); typedesc.put("structure", ((int) typedesc.get("varflags") & 32) == 32); if ((boolean) typedesc.get("structure")) { typedesc.put("array_desc", read_arraydesc(raf)); typedesc.put("struct_desc", read_structdesc(raf)); } else if ((boolean) typedesc.get("array")) { typedesc.put("array_desc", read_arraydesc(raf)); } return typedesc; }