List of usage examples for java.util HashMap keySet
public Set<K> keySet()
From source file:longism.com.api.APIUtils.java
/** * TODO Function:Load json by type.<br> * * @param activity - to get context/*from www . java 2 s .c o m*/ * @param action - get or post or s.thing else. Define at top of class * @param data - Parameter * @param url - host of API * @param apiCallBack - call back to handle action when start, finish, success or fail * @param username - username if sever need to log in * @param password - password if sever need to log in * @date: July 07, 2015 * @author: Nguyen Long */ public static void LoadJSONByType(final Activity activity, final int action, final HashMap<String, String> data, final String url, final String username, final String password, final APICallBack apiCallBack) { activity.runOnUiThread(new Runnable() { @Override public void run() { apiCallBack.uiStart(); } }); new Thread(new Runnable() { @Override public synchronized void run() { try { HttpGet get = null; HttpPost post = null; HttpResponse response = null; String paramString = null; ArrayList<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); if (data != null) { Set<String> set = data.keySet(); for (String key : set) { BasicNameValuePair value = new BasicNameValuePair(key, data.get(key)); list.add(value); } } HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(params, TIMEOUT_TIME); HttpConnectionParams.setConnectionTimeout(params, TIMEOUT_TIME); DefaultHttpClient client = new DefaultHttpClient(params); /** * Select action to do */ switch (action) { case ACTION_GET_JSON: paramString = URLEncodedUtils.format(list, "utf-8"); get = new HttpGet(url + "?" + paramString); response = client.execute(get); break; case ACTION_POST_JSON: post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(list, "UTF-8")); response = client.execute(post); break; case ACTION_GET_JSON_WITH_AUTH: paramString = URLEncodedUtils.format(list, "utf-8"); get = new HttpGet(url + "?" + paramString); setAuthenticate(client, get, username, password); response = client.execute(get); break; case ACTION_POST_JSON_WITH_AUTH: post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(list, "UTF-8")); setAuthenticate(client, post, username, password); response = client.execute(post); break; } final StringBuilder builder = new StringBuilder(); if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { InputStream inputStream = response.getEntity().getContent(); Scanner scanner = new Scanner(inputStream); while (scanner.hasNext()) { builder.append(scanner.nextLine()); } inputStream.close(); scanner.close(); apiCallBack.success(builder.toString(), 0); } else { apiCallBack.fail(response != null && response.getStatusLine() != null ? "response null" : "" + response.getStatusLine().getStatusCode()); } } catch (final Exception e) { apiCallBack.fail(e.getMessage()); } finally { activity.runOnUiThread(new Runnable() { @Override public void run() { apiCallBack.uiEnd(); } }); } } }).start(); }
From source file:br.unicamp.ic.recod.gpsi.ml.gpsiLinearDiscriminantAnalysisClassificationAlgorithm.java
@Override public void fit(HashMap<Byte, ArrayList<double[]>> x) { VectorialMean mean;//from w w w. j a va2 s . c om this.centroids = new HashMap<>(); this.nClasses = x.size(); this.dimensionality = 0; for (byte label : x.keySet()) { if (this.dimensionality <= 0) this.dimensionality = x.get(label).get(0).length; mean = new VectorialMean(this.dimensionality); for (double[] v : x.get(label)) mean.increment(v); this.centroids.put(label, mean.getResult()); } }
From source file:io.crate.module.sql.benchmark.BulkDeleteBenchmark.java
@BenchmarkOptions(benchmarkRounds = BENCHMARK_ROUNDS, warmupRounds = 1) @Test/*from ww w . ja va 2 s . c om*/ public void testSQLBulkDelete() { Object[][] bulkArgs = new Object[ROWS][]; HashMap<String, String> ids = createSampleData(); int i = 0; for (String id : ids.keySet()) { bulkArgs[i] = new Object[] { id }; i++; } getClient(false).execute(SQLBulkAction.INSTANCE, new SQLBulkRequest(DELETE_SQL_STMT, bulkArgs)).actionGet(); refresh(client()); }
From source file:com.apricot.eating.xml.XMLParser.java
public Object getNodeObject(Node node, Class claz) { Object obj = null;//from w ww . j a v a2 s . co m try { obj = claz.newInstance(); } catch (Exception e) { } if (obj == null) return null; try { HashMap map = getAttributes(node); for (Iterator keys = map.keySet().iterator(); keys.hasNext();) { String k = (String) keys.next(); try { BeanUtils.setProperty(obj, k, map.get(k)); } catch (Exception e) { } } } catch (Exception e) { } return obj; }
From source file:com.uwsoft.editor.view.ui.box.resourcespanel.UIParticleEffectsTabMediator.java
@Override protected void initList(String searchText) { Sandbox sandbox = Sandbox.getInstance(); //Overlap2DFacade facade = Overlap2DFacade.getInstance(); ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME); HashMap<String, ParticleEffect> particles = resourceManager.getProjectParticleList(); Array<DraggableResource> itemArray = new Array<>(); for (String name : particles.keySet()) { if (!name.contains(searchText)) continue; DraggableResource draggableResource = new DraggableResource(new ParticleEffectResource(name)); draggableResource.setFactoryFunction(ItemFactory.get()::tryCreateParticleItem); itemArray.add(draggableResource); }/*from ww w . j a va 2 s . c om*/ viewComponent.setItems(itemArray); }
From source file:com.appdynamics.cloudfoundry.appdservicebroker.CredentialsHolder.java
void init(HashMap<String, JSONObject> appd_plans) { this.appd_plans_by_name = appd_plans; for (String planName : appd_plans.keySet()) { JSONObject planValue = appd_plans.get(planName); log.debug("Plan Name: " + planName + " and associated plan value: " + planValue); HashMap<String, String> appd_plan_detail = planValue; Credentials appdPlanCredentials = new Credentials(); appdPlanCredentials.setAccessKey(appd_plan_detail.get("account-access-key")); appdPlanCredentials.setAccountName(appd_plan_detail.get("account-name")); appdPlanCredentials.setControllerHost(appd_plan_detail.get("host-name")); appdPlanCredentials.setControllerPort(appd_plan_detail.get("port")); appdPlanCredentials.setIsSSLEnabled(appd_plan_detail.get("ssl-enabled")); appd_plans_map.put(planName, appdPlanCredentials); log.debug("Created appd plan : " + planName + " with credentials content: " + appdPlanCredentials); }//from w w w . j ava2 s . com }
From source file:com.uwsoft.editor.view.ui.box.resourcespanel.UILibraryItemsTabMediator.java
@Override protected void initList(String searchText) { searchText = searchText.toLowerCase(); ProjectManager projectManager = Overlap2DFacade.getInstance().retrieveProxy(ProjectManager.NAME); HashMap<String, CompositeItemVO> items = projectManager.currentProjectInfoVO.libraryItems; Array<DraggableResource> itemArray = new Array<>(); for (String key : items.keySet()) { if (!key.toLowerCase().contains(searchText)) continue; DraggableResource draggableResource = new DraggableResource(new LibraryItemResource(key)); draggableResource.setFactoryFunction(ItemFactory.get()::createItemFromLibrary); draggableResource.initDragDrop(); itemArray.add(draggableResource); }//from ww w . j a v a2s.c om viewComponent.setItems(itemArray); }
From source file:com.ibm.crail.tools.CrailFsck.java
private void printStats(HashMap<String, AtomicInteger> stats) { for (Iterator<String> iter = stats.keySet().iterator(); iter.hasNext();) { String key = iter.next(); System.out.println(key + "\t" + stats.get(key)); }//from ww w. ja v a 2s. c o m }
From source file:com.o2d.pkayjava.editor.view.ui.box.resourcespanel.UILibraryItemsTabMediator.java
@Override protected void initList(String searchText) { ProjectManager projectManager = Overlap2DFacade.getInstance().retrieveProxy(ProjectManager.NAME); HashMap<String, CompositeItemVO> items = projectManager.currentProjectInfoVO.libraryItems; Array<DraggableResource> itemArray = new Array<>(); for (String key : items.keySet()) { if (!key.contains(searchText)) continue; DraggableResource draggableResource = new DraggableResource(new LibraryItemResource(key)); draggableResource.setFactoryFunction(ItemFactory.get()::createItemFromLibrary); draggableResource.initDragDrop(); itemArray.add(draggableResource); }/* w w w. j a v a 2s. c o m*/ viewComponent.setItems(itemArray); }
From source file:net.certiv.authmgr.task.section.model.AnalyzeModel.java
private void analyzeCategories(PersistantWordsDataSource pds, HashMap<String, HashMap<String, HashMap<String, WordProbabilityPT>>> catsMap) { Set<String> catKeys = catsMap.keySet(); String categoryLabels = ""; for (Iterator<String> it = catKeys.iterator(); it.hasNext();) { categoryLabels = categoryLabels + it.next() + " "; }//from w w w.ja va 2 s. c om Log.info(this, "Category collection: " + catKeys.size() + " = " + categoryLabels); // for each category for (Iterator<String> it = catKeys.iterator(); it.hasNext();) { String category = it.next(); HashMap<String, HashMap<String, WordProbabilityPT>> partsMap = catsMap.get(category); analyzePartitions(pds, category, partsMap); } }