List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:it.acubelab.smaph.entityfilters.LibSvmEntityFilter.java
private static boolean checkFeatures(HashMap<String, Double> features) { if (getOrDefault(features, "is_s1", 0.0) + getOrDefault(features, "is_s2", 0.0) + getOrDefault(features, "is_s3", 0.0) + getOrDefault(features, "is_s4", 0.0) + getOrDefault(features, "is_s5", 0.0) != 1) return false; boolean found = false; for (String sourcePrefix : new String[] { "s1_", "s2_", "s3_", "s5_" }) { int sourceFtrCount = 0; for (String ftrName : features.keySet()) if (ftrName.startsWith(sourcePrefix)) sourceFtrCount++;/*w w w .j av a 2 s . com*/ if (sourcePrefix.equals("s1_")) found = sourceFtrCount == 9 && features.size() == sourceFtrCount + 1; if (sourcePrefix.equals("s2_")) found = sourceFtrCount == 8 && features.size() == sourceFtrCount + 1; if (sourcePrefix.equals("s3_")) found = sourceFtrCount == 8 && features.size() == sourceFtrCount + 1; if (sourcePrefix.equals("s4_")) found = sourceFtrCount == 0 && features.size() == sourceFtrCount + 1; if (sourcePrefix.equals("s5_")) found = sourceFtrCount == 8 && features.size() == sourceFtrCount + 1; if (found) return true; } return false; }
From source file:org.grameenfoundation.consulteca.utils.HttpHelpers.java
/** * Gets a common headers url parameter string starting with ? * * @return the url parameter string with common headers. *///from ww w . j a v a 2 s. com public static String getCommonParameters() { // Add common Headers to the parameter string HashMap<String, String> commonHeaders = HttpHelpers.getCommonHeaders(); String commonParameters = ""; Set<String> keys = commonHeaders.keySet(); Boolean isFirst = true; for (String key : keys) { if (isFirst) { commonParameters += "?"; isFirst = false; } else { commonParameters += "&"; } commonParameters += key + "=" + URLEncoder.encode(commonHeaders.get(key)); } return commonParameters; }
From source file:edu.utexas.cs.tactex.utils.BrokerUtils.java
/** * creates a copy of the map, but where keys are Double * instead of Integer. /* www. j a v a 2s. co m*/ * * @param customer2tariffSubscriptions * @return * */ public static HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> initializePredictedFromCurrentSubscriptions( HashMap<CustomerInfo, HashMap<TariffSpecification, Integer>> customer2tariffSubscriptions) { HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> predicted = new HashMap<CustomerInfo, HashMap<TariffSpecification, Double>>(); for (CustomerInfo customer : customer2tariffSubscriptions.keySet()) { HashMap<TariffSpecification, Integer> oldmap = customer2tariffSubscriptions.get(customer); HashMap<TariffSpecification, Double> newmap = initializeDoubleSubsMap(oldmap); // copy construct predicted.put(customer, newmap); } return predicted; }
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"; }/* www . ja va 2 s . com*/ } snvProfiles.put(snv, profile); } return snvProfiles; }
From source file:fr.lissi.belilif.om2m.rest.WebServiceActions.java
/** * Do get./*from w w w.j a v a2 s . c om*/ * * @param uri * the uri * @param headers * the headers * @return the string * @throws ClientProtocolException * the client protocol exception * @throws IOException * Signals that an I/O exception has occurred. * @throws HttpResponseException * the http response exception */ public static HttpGetSimpleResp doGet(String uri, HashMap<String, String> headers) throws ClientProtocolException, IOException, HttpResponseException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGetSimpleResp resp = new HttpGetSimpleResp(); try { HttpGet httpGet = new HttpGet(uri); for (String key : headers.keySet()) { httpGet.addHeader(key, headers.get(key)); } CloseableHttpResponse response = httpclient.execute(httpGet); resp.setStatusCode(response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { try { HttpEntity entity = response.getEntity(); if (entity != null) { // TODO to use for performance in the future // ResponseHandler<String> handler = new BasicResponseHandler(); resp.setResult(new BasicResponseHandler().handleResponse(response)); } EntityUtils.consume(entity); } finally { response.close(); } } else { // TODO optimiz (repeating code) throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } finally { httpclient.close(); } return resp; }
From source file:gov.tva.sparky.util.indexer.IndexingAgent.java
public static void Index_HDFS_File(String strHdfsPath) throws Exception { LOG.info("Indexing File: " + strHdfsPath); long lBytesUploaded = 0; int iBucketsUpdated = 0; boolean bExistsAlreadyInRegistry = false; String strHBaseRegistryFileID = ""; int iHBaseRegistryFileID = -1; HistorianArchiveLookupTable oLookupTable = new HistorianArchiveLookupTable(); try {/* w w w .ja v a2 s. c om*/ strHBaseRegistryFileID = oLookupTable.Lookup_FileID_byPath(strHdfsPath); System.out.println("Found File ID: " + strHBaseRegistryFileID + " For Path: " + strHdfsPath); bExistsAlreadyInRegistry = true; } catch (Exception e) { bExistsAlreadyInRegistry = false; } // if its not already registered, register it if (!bExistsAlreadyInRegistry) { try { HistorianArchiveLookupTable.InsertEntryInto_Hbase_LookupTables(strHdfsPath); strHBaseRegistryFileID = oLookupTable.Lookup_FileID_byPath(strHdfsPath); iHBaseRegistryFileID = HistorianArchiveLookupTableEntry.GetIntFromBytes(strHBaseRegistryFileID); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); strHBaseRegistryFileID = ""; } } if (strHBaseRegistryFileID.equals("") || iHBaseRegistryFileID < 0) { throw new Exception("Unable to register hdfs file in Index Registry!"); } // We need to group each range of block pointers into buckets FileIndex archive_index = new FileIndex(strHdfsPath, iHBaseRegistryFileID); HashMap<String, PriorityQueue<HDFSPointBlockPointer>> map = archive_index.GetKeyMap(); //int iPass = 0; Set<String> Keys = map.keySet(); Iterator It = Keys.iterator(); while (It.hasNext()) { // if (It.hasNext()) { String key_str = (String) (It.next()); IndexBucket oBucket = new IndexBucket(map.get(key_str)); lBytesUploaded += oBucket.GetSerializedByteSize(); HBaseRestInterface.Update_HDFS_FileIndex(oBucket); iBucketsUpdated++; } // log summary stats... LOG.info("Indexer > Summary > Total Bytes Uploaded: " + lBytesUploaded + ", Buckets Updated: " + iBucketsUpdated); }
From source file:fr.lissi.belilif.om2m.rest.WebServiceActions.java
/** * Do delete.//from w ww . j a v a2 s.c om * * @param uri the uri * @param headers the headers * @return the http get simple resp * @throws ClientProtocolException the client protocol exception * @throws IOException Signals that an I/O exception has occurred. * @throws HttpResponseException the http response exception */ public static HttpGetSimpleResp doDelete(String uri, HashMap<String, String> headers) throws ClientProtocolException, IOException, HttpResponseException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGetSimpleResp resp = new HttpGetSimpleResp(); try { HttpDelete httpDelete = new HttpDelete(uri); for (String key : headers.keySet()) { httpDelete.addHeader(key, headers.get(key)); } CloseableHttpResponse response = httpclient.execute(httpDelete); resp.setStatusCode(response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { try { HttpEntity entity = response.getEntity(); if (entity != null) { // TODO to use for performance in the future resp.setResult(new BasicResponseHandler().handleResponse(response)); } EntityUtils.consume(entity); } finally { response.close(); } } else { // TODO optimiz (repeating code) throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } finally { httpclient.close(); } return resp; }
From source file:br.net.fabiozumbi12.RedProtect.hooks.MojangUUIDs.java
public static String getName(String UUID) { try {//from www .ja v a 2 s.c o m URL url = new URL("https://api.mojang.com/user/profiles/" + UUID.replaceAll("-", "") + "/names"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line = in.readLine(); if (line == null) { return null; } JSONArray array = (JSONArray) new JSONParser().parse(line); HashMap<Long, String> names = new HashMap<Long, String>(); String name = ""; for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; if (jsonProfile.containsKey("changedToAt")) { names.put((long) jsonProfile.get("changedToAt"), (String) jsonProfile.get("name")); continue; } name = (String) jsonProfile.get("name"); } if (!names.isEmpty()) { Long key = Collections.max(names.keySet()); return names.get(key); } else { return name; } } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:mml.handler.scratch.Scratch.java
/** * Get a version that may or may not be in scratch. If not put it there. * @param docid the docid //www . j a v a2 s. com * @param version the desired single version or null if default * @param dbase the database it is in * @return a ScratchVersion object or null * @throws MMLException */ public static ScratchVersion getVersion(String docid, String version, String dbase) throws MMLException { try { ScratchVersion sv = null; if (version != null) sv = getScratchVersion(docid, version, dbase); if (sv == null) { EcdosisMVD mvd = doGetMVD(dbase, docid); if (mvd != null) { if (version == null) version = mvd.getVersion1(); String base = Layers.stripLayer(version); HashMap<String, char[]> layers = new HashMap<String, char[]>(); int numVersions = mvd.numVersions(); for (int i = 1; i <= numVersions; i++) { String vName = mvd.getVersionId((short) i); if (vName.lastIndexOf(base) == 0) layers.put(vName, mvd.getVersion(i)); } if (!layers.isEmpty()) { Set<String> keys = layers.keySet(); String[] arr = new String[keys.size()]; keys.toArray(arr); Arrays.sort(arr); String[] all = mvd.getAllVersions(); short id = mvd.getVersionId(version); String longName = mvd.getVersionLongName(id); sv = new ScratchVersion(base, longName, docid, dbase, null, false); for (int i = 0; i < arr.length; i++) { String updatedName = Layers.upgradeLayerName(all, arr[i]); sv.addLayer(layers.get(arr[i]), ScratchVersion.layerNumber(updatedName)); } // save it for next time Connection conn = Connector.getConnection(); conn.putToDb(Database.SCRATCH, dbase, docid, version, sv.toJSON()); return sv; } } return null; } else return sv; } catch (DbException e) { throw new MMLException(e); } }
From source file:eu.eexcess.ddb.recommender.PartnerConnector.java
/** * Opens a HTTP connection, gets the response and converts into to a String. * /*from w w w . j a v a 2 s . co m*/ * @param urlStr Servers URL * @param properties Keys and values for HTTP request properties * @return Servers response * @throws IOException If connection could not be established or response code is !=200 */ public static String httpGet(String urlStr, HashMap<String, String> properties) throws IOException { if (properties == null) { properties = new HashMap<String, String>(); } // open HTTP connection with URL URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // set properties if any do exist for (String key : properties.keySet()) { conn.setRequestProperty(key, properties.get(key)); } // test if request was successful (status 200) if (conn.getResponseCode() != 200) { throw new IOException(conn.getResponseMessage()); } // buffer the result into a string InputStreamReader isr = new InputStreamReader(conn.getInputStream(), "UTF-8"); BufferedReader br = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); } br.close(); isr.close(); conn.disconnect(); return sb.toString(); }