List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:eu.riscoss.dataproviders.providers.FossologyDataProvider.java
private String getLicenseTypeForLicense(HashMap<String, Collection<String>> licensesMap, String license) { for (String l : licensesMap.keySet()) { //if (license.toLowerCase().contains(l.toLowerCase())) { //attention: order matters in the file! (e.g. to parse GPL/LGPL correctly) if (matchesOneOf(licensesMap.get(l), license)) return l; }// w w w . ja va 2 s . c o m //DEBUG - add missing licenses to licenses file! System.err.println("WARNING: getLicenseTypeForLicense() #Unknown license: " + license + ". Try to add it to LicensesCfg."); return UNKNOWN_LICENSE_TYPE; }
From source file:edu.ku.brc.specify.config.FixDBAfterLogin.java
/** * @param tblToFldHash/*from w w w.ja va 2 s . c om*/ * @param doingCount * @return */ private static int processTableDefaultDates(final HashMap<DBTableInfo, List<FormCellFieldIFace>> tblToFldHash, final boolean doingCount) { int totalCount = 0; for (DBTableInfo ti : tblToFldHash.keySet()) { //log.debug("processTableDefaultDates - Fixing table "+ti.getName()); for (FormCellFieldIFace fci : tblToFldHash.get(ti)) { String[] names = fci.getFieldNames(); if (names != null && names.length > 0 && names.length < 3) { Class<?> dataClass = null; String fldName = null; if (fci.getUiType() == FormCellFieldIFace.FieldType.plugin) // assumes plugin { String pluginName = fci.getProperty("name"); if (StringUtils.isNotEmpty(pluginName) && pluginName.equals("PartialDateUI")) { String dataField = fci.getProperty("df"); if (StringUtils.isNotEmpty(dataField)) { fldName = dataField; dataClass = java.util.Calendar.class; } } } else { fldName = names[0]; } DBFieldInfo fi = ti.getFieldByName(fldName); if (fi != null) { if (dataClass == null) { dataClass = fi.getDataClass(); } if (dataClass == java.util.Calendar.class) { //log.debug("processTableDefaultDates - Fixing field "+fi.getColumn()); String sql = String.format( "SELECT COUNT(*) FROM %s WHERE %s IS NULL AND TimestampCreated IS NOT NULL AND TimestampCreated > TIMESTAMP('2008-06-01 00:00:00')", ti.getName(), fi.getColumn()); int cnt = BasicSQLUtils.getCountAsInt(sql); if (cnt > 0) { if (doingCount) { totalCount += cnt; } else { totalCount += fixTableDefaultDates(ti, fi); } } } } } } } log.debug("processTableDefaultDates - Fixed " + totalCount + " Records."); return 0; }
From source file:com.samknows.measurement.test.TestExecutor.java
public void executeTest(TestDescription td, TestResult result) { try {//from w w w . j av a 2s. co m List<Param> params = tc.paramsManager.prepareParams(td.params); executingTest = TestFactory.create(td.type, params); if (executingTest != null) { getPartialResult(); Logger.d(TestExecutor.class, "start to execute test: " + td.displayName); showNotification(tc.getString(R.string.ntf_running_test) + td.displayName); //execute the test in a new thread and kill it it it doesn't terminate after //Constants.WAIT_TEST_BEFORE_ABORT Thread t = new Thread(new Runnable() { @Override public void run() { executingTest.execute(); } }); t.start(); t.join(Constants.WAIT_TEST_BEFORE_ABORT); if (t.isAlive()) { Logger.e(this, "Test is still runnuing after " + Constants.WAIT_TEST_BEFORE_ABORT / 1000 + " seconds."); t.interrupt(); t = null; } else { lastTestBytes = executingTest.getNetUsage(); result.isSuccess = executingTest.isSuccessful(); String out = executingTest.getOutputString(); result.addTestString(out); rc.addTest(executingTest.getJSONResult()); // HACK TO INCLUDE THE JUDPJITTER RESULTS if (td.type.equalsIgnoreCase("latency")) { String[] judp = executingTest.getOutputFields(); DCSStringBuilder jjitter = new DCSStringBuilder(); String jitter = "" + (Integer.parseInt(judp[5]) - Integer.parseInt(judp[6])); String sent = "" + (Integer.parseInt(judp[9]) + Integer.parseInt(judp[10])); String received = "" + (Integer.parseInt(judp[9]) - Integer.parseInt(judp[10])); jjitter.append("JUDPJITTER"); jjitter.append(judp[1]); // TIMESTAMP jjitter.append(judp[2]); // STATUS jjitter.append(judp[3]); // TARGET jjitter.append(judp[4]); // TARGET IP ADDRESS jjitter.append(128); // PACKETSIZE jjitter.append(0); // BITRATE jjitter.append(0); // DURATION jjitter.append(sent); // PACKETS SENT UP jjitter.append(sent); // PACKETS SENT DOWN jjitter.append(received); // PACKETS RECEIVED UP jjitter.append(received); // PACKETS RECEIVED DOWN jjitter.append(jitter); // JITTER UP jjitter.append(jitter); // JITTER DOWN jjitter.append(judp[5]); // AVERAGE RTT result.addTestString(jjitter.build()); } if (result.isSuccess) { tc.paramsManager.processOutParams(out, td.outParamsDescription); if (executingTest.getHumanReadable() != null) { HashMap<String, String> last_values = executingTest.getHumanReadable().getValues(); for (String key : last_values.keySet()) { String value = last_values.get(key); Logger.d(TestExecutor.class, "last_" + key + " " + value); AppSettings.getInstance().saveString("last_" + key, value); } } } Logger.d(TAG, "finished execution test: " + td.type); } } else { Logger.e(TAG, "Can't find test for: " + td.type, new RuntimeException()); result.isSuccess = false; } } catch (Throwable e) { Logger.e(this, "Error in executing the test. ", e); result.isSuccess = false; } finally { cancelNotification(); } }
From source file:com.yahoo.ycsb.db.RedisClient.java
@Override public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) { Set<String> keys; if (cluster) { keys = jedisCluster.zrangeByScore(INDEX_KEY, hash(startkey), Double.POSITIVE_INFINITY, 0, recordcount); } else {//from www . j ava2 s .co m keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey), Double.POSITIVE_INFINITY, 0, recordcount); } HashMap<String, ByteIterator> values; for (String key : keys) { values = new HashMap<String, ByteIterator>(); for (String st : values.keySet()) { values.put(st, decompress(values.get(st))); } read(table, key, fields, values); result.add(values); } return 0; }
From source file:ffx.potential.parameters.TorsionType.java
/** * Remap new atom classes to known internal ones. * * @param typeMap a lookup between new atom types and known atom types. * @return//www. j a v a 2s . c o m */ public TorsionType patchClasses(HashMap<AtomType, AtomType> typeMap) { int count = 0; int len = atomClasses.length; /** * Look for new TorsionTypes that contain 1 to 3 mapped atom classes. */ for (AtomType newType : typeMap.keySet()) { for (int i = 0; i < len; i++) { if (atomClasses[i] == newType.atomClass) { count++; } } } /** * If found, create a new TorsionType that bridges to known classes. */ if (count == 1 || count == 2 || count == 3) { int newClasses[] = Arrays.copyOf(atomClasses, len); for (AtomType newType : typeMap.keySet()) { for (int i = 0; i < len; i++) { if (atomClasses[i] == newType.atomClass) { AtomType knownType = typeMap.get(newType); newClasses[i] = knownType.atomClass; } } } return new TorsionType(newClasses, amplitude, phase, periodicity); } return null; }
From source file:com.android.volley.stack.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HashMap<String, String> map = new HashMap<String, String>(); if (!TextUtils.isEmpty(mUserAgent)) { map.put(HTTP.USER_AGENT, mUserAgent); }/* w ww .java 2 s. co m*/ map.putAll(request.getHeaders()); URL parsedUrl = new URL(request.getUrl()); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } setConnectionParametersForRequest(connection, request); int responseCode = connection.getResponseCode(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), connection.getResponseCode(), connection.getResponseMessage()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } return response; }
From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java
/** * This finds all possible alignments between word1 and word2. * @param word1//from ww w .j av a 2 s .co m * @param word2 * @param maxSubstringLength1 * @param maxSubstringLength2 * @param internTable * @param normalization * @return */ public static HashMap<Production, Double> FindAlignments(String word1, String word2, int maxSubstringLength1, int maxSubstringLength2, InternDictionary<String> internTable, NormalizationMode normalization) { HashMap<Production, Double> alignments = new HashMap<>(); // this populates the alignments hashmap. // FIXME: why not assign to alignments here? // FIXME: why is it boolean? Is the value ever false? What does it mean? HashSet<Production> memoizationtable = new HashSet<>(); FindAlignments(word1, word2, maxSubstringLength1, maxSubstringLength2, alignments, memoizationtable); // FIXME: probably don't need this? What about interning?? HashMap<Production, Double> result = new HashMap<>(alignments.size()); for (Production key : alignments.keySet()) { result.put(new Production(internTable.Intern(key.getFirst()), internTable.Intern(key.getSecond())), 1.0); } return Normalize(word1, word2, result, internTable, normalization); }
From source file:com.facebook.tsdb.tsdash.server.model.Metric.java
@SuppressWarnings("unchecked") public JSONObject toJSONObject() { JSONObject topObj = new JSONObject(); topObj.put("name", name); HashMap<String, HashSet<String>> tagsSet = getTagsSet(); topObj.put("tags", encodeTagsSet(tagsSet)); topObj.put("commontags", encodeCommonTags(getCommonTags(tagsSet.keySet()))); return topObj; }
From source file:com.android.datacloud.Entity.java
/** * Carga los valores creando un cursor.l *//*from w ww .jav a2 s . c o m*/ protected void loadData() { HttpGet request = new HttpGet(DataCloud.getInstance().getURLLoadData(mTable, mId)); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = client.execute(request); String ent = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(ent); HashMap<String, Object> attribs = mAttributes; Object[] attributeNames = attribs.keySet().toArray(); int attributeCount = attributeNames.length; for (int i = 0; i < attributeCount; i++) { String attributeName = attributeNames[i].toString(); Field f = getTableObject().getField(attributeName); if (f.getType().equals("text") || f.getType().equals("string-identifier") || f.getType().equals("drawable-identifier")) attribs.put(attributeName, jsonObject.getJSONObject("user").getString(attributeName)); else if (f.getType().equals("int")) attribs.put(attributeName, jsonObject.getJSONObject("user").getInt(attributeName)); else if (f.getType().equals("foreign-key")) attribs.put(attributeName, jsonObject.getJSONObject("user").getInt(attributeName)); else if (f.getType().equals("real")) attribs.put(attributeName, jsonObject.getJSONObject("user").getDouble(attributeName)); else attribs.put(attributeName, jsonObject.getJSONObject("user").getString(attributeName)); } errorLoad = false; } catch (Exception e) { e.printStackTrace(); errorLoad = true; } }
From source file:com.esri.geoevent.solutions.processor.eventjoiner.EventJoinerProcessor.java
private void ConstructGeoEventDef(HashMap<String, GeoEvent> rec) throws Exception { try {/*w w w . j a v a 2 s . c o m*/ fldMgr = new HashMap<String, FieldItem>(); Set<String> keys = rec.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String key = it.next(); GeoEvent evt = rec.get(key); List<FieldDefinition> fldDefs = evt.getGeoEventDefinition().getFieldDefinitions(); for (FieldDefinition fldDef : fldDefs) { String fldName = fldDef.getName(); FieldType type = fldDef.getType(); if (fldMgr.containsKey(fldName)) { FieldItem item = fldMgr.get(fldName); if (!fldDef.getTags().isEmpty()) item.appendTags(fldDef.getTags()); item.advance(); } else { FieldItem item = new FieldItem(); item.setId(fldName); item.setType(type); if (!fldDef.getTags().isEmpty()) item.appendTags(fldDef.getTags()); item.advance(); fldMgr.put(fldName, item); } } } Set<String> fldKeys = fldMgr.keySet(); Iterator<String> fldIt = fldKeys.iterator(); List<FieldDefinition> mergedFldDef = new ArrayList<FieldDefinition>(); while (fldIt.hasNext()) { String fldName = fldIt.next(); FieldItem item = fldMgr.get(fldName); FieldType type; FieldType fldtype = item.getType(); ArrayList<String> tags = item.getTags(); if (tags.contains("TRACK_ID")) { tags.remove("TRACK_ID"); } FieldDefinition fd = null; if (item.getCount() > 1) { if (fldName.equals(joinfield)) { tags.add("JOIN_ID"); tags.add("TRACK_ID"); String[] tagarr = new String[tags.size()]; tagarr = tags.toArray(tagarr); fd = new DefaultFieldDefinition(fldName, fldtype, (String[]) tagarr); } else { type = FieldType.Group; String[] groupedTag = { "GROUPED" }; fd = new DefaultFieldDefinition(fldName, type, groupedTag); for (Integer i = 0; i < item.getCount(); ++i) { String childName = defList.get(i); FieldDefinition child = null; if (tags.isEmpty()) { child = new DefaultFieldDefinition(childName, fldtype); } else { String[] tagarr = new String[tags.size()]; tagarr = tags.toArray(tagarr); child = new DefaultFieldDefinition(childName, fldtype, tagarr); } fd.addChild(child); } } } else { type = fldtype; if (!tags.isEmpty()) { fd = new DefaultFieldDefinition(fldName, fldtype, (String[]) tags.toArray()); } else { fd = new DefaultFieldDefinition(fldName, fldtype); } } mergedFldDef.add(fd); } outDef = new DefaultGeoEventDefinition(); outDef.setFieldDefinitions(mergedFldDef); outDef.setName(outdefname); outDef.setOwner(definition.getUri().toString()); Collection<GeoEventDefinition> eventDefs = manager.searchGeoEventDefinitionByName(outdefname); Iterator<GeoEventDefinition> eventDefIt = eventDefs.iterator(); while (eventDefIt.hasNext()) { GeoEventDefinition currentDef = eventDefIt.next(); manager.deleteGeoEventDefinition(currentDef.getGuid()); } manager.addGeoEventDefinition(outDef); } catch (ConfigurationException e) { LOG.error(e.getMessage()); throw (e); } catch (GeoEventDefinitionManagerException e) { LOG.error(e.getMessage()); throw (e); } catch (Exception e) { LOG.error(e.getMessage()); throw (e); } }