List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:com.oDesk.api.OAuthClient.java
/** * Send signed POST OAuth request//from www.jav a 2 s . c o m * * @param url Relative URL * @param type Type of HTTP request (HTTP method) * @param params Hash of parameters * @throws JSONException If JSON object is invalid or request was abnormal * @return {@link JSONObject} JSON Object that contains data from response * */ private JSONObject sendPostRequest(String url, Integer type, HashMap<String, String> params) throws JSONException { String fullUrl = getFullUrl(url); HttpPost request = new HttpPost(fullUrl); switch (type) { case METHOD_PUT: case METHOD_DELETE: // assign overload value String oValue; if (type == METHOD_PUT) { oValue = "put"; } else { oValue = "delete"; } params.put(OVERLOAD_PARAM, oValue); case METHOD_POST: break; default: throw new RuntimeException("Wrong http method requested"); } // doing post request using json to avoid issue with urlencoded symbols JSONObject json = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { json.put(entry.getKey(), entry.getValue()); } request.setHeader("Content-Type", "application/json"); try { request.setEntity(new StringEntity(json.toString())); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // sign request try { mOAuthConsumer.sign(request); } catch (OAuthException e) { e.printStackTrace(); } return oDeskRestClient.getJSONObject(request, type, params); }
From source file:com.Upwork.api.OAuthClient.java
/** * Send signed POST OAuth request//from w w w . j ava2s . c o m * * @param url Relative URL * @param type Type of HTTP request (HTTP method) * @param params Hash of parameters * @throws JSONException If JSON object is invalid or request was abnormal * @return {@link JSONObject} JSON Object that contains data from response * */ private JSONObject sendPostRequest(String url, Integer type, HashMap<String, String> params) throws JSONException { String fullUrl = getFullUrl(url); HttpPost request = new HttpPost(fullUrl); switch (type) { case METHOD_PUT: case METHOD_DELETE: // assign overload value String oValue; if (type == METHOD_PUT) { oValue = "put"; } else { oValue = "delete"; } params.put(OVERLOAD_PARAM, oValue); case METHOD_POST: break; default: throw new RuntimeException("Wrong http method requested"); } // doing post request using json to avoid issue with urlencoded symbols JSONObject json = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { json.put(entry.getKey(), entry.getValue()); } request.setHeader("Content-Type", "application/json"); try { request.setEntity(new StringEntity(json.toString())); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // sign request try { mOAuthConsumer.sign(request); } catch (OAuthException e) { e.printStackTrace(); } return UpworkRestClient.getJSONObject(request, type, params); }
From source file:gob.dp.simco.reporte.controller.ReporteGeneralController.java
private static HashMap sortByValues(HashMap map) { List list = new LinkedList(map.entrySet()); // Defined Custom Comparator here Collections.sort(list, new Comparator() { @Override//from ww w . ja v a2 s .c o m public int compare(Object o1, Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue()); } }); // Here I am copying the sorted list in HashMap // using LinkedHashMap to preserve the insertion order HashMap sortedHashMap = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); sortedHashMap.put(entry.getKey(), entry.getValue()); } return sortedHashMap; }
From source file:dao.EventCommentDao.java
public List<Event> getEventsForWorkReport(Integer status, Date dateFrom, Date dateTo, Long userId, Long campaignId, Long pkId) { HashMap<String, Object> paramMap = new HashMap(); String hql = "select distinct ec.event from EventComment ec where ec.campaignId=:campaignId and ec.insertDate>=:dateFrom and ec.insertDate<=:dateTo and ec.cabinet.pkId=:pkId"; if (userId != null) { hql += " and ec.author.userId=:userId"; paramMap.put("userId", userId); }/*from w w w . ja va 2 s . c o m*/ if (status != null) { hql += " and ec.type=:status"; paramMap.put("status", status); } else { hql += " and (ec.type=4 or ec.type=5 or ec.type=1)"; } hql += " order by ec.event.setStatusDate"; Query query = getCurrentSession().createQuery(hql); query.setParameter("campaignId", campaignId); query.setParameter("pkId", pkId); query.setParameter("dateFrom", DateAdapter.getDateFromString(DateAdapter.getDateInMysql(dateFrom))); query.setParameter("dateTo", DateAdapter.getDateFromString(DateAdapter.getDateInMysql(dateTo))); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { query.setParameter(entry.getKey(), entry.getValue()); } return query.list(); }
From source file:com.jvoid.products.product.service.ProductsMasterService.java
public int updateProduct(ProductsMaster productsMaster) { int status = 1; int productId = productsMaster.getId(); Product product = new Product(); product.setId(productId);// w ww . ja v a 2 s. c om product.setSku(productsMaster.getSku()); product.setHasOptions(productsMaster.getHasMoreOption()); product.setRequiredOptions(productsMaster.getRequiredOption()); product.setUpdatedOn(Utilities.getCurrentDateTime()); productService.updateproduct(product); List<Entities> listAttributes = this.entitiesService.listAttributes(); HashMap<Integer, String> attrs = getAttributesList(listAttributes, "Product"); System.out.println("LIST ATTR:" + listAttributes.toString()); for (Entry<Integer, String> entry : attrs.entrySet()) { Integer attrId = entry.getKey(); String attrValue = entry.getValue(); ProductEntityValues productAttributeValues = this.productEntityValuesService .getProductAttributeValuesByProductIdAndAttributeId(productId, attrId); if (null != productAttributeValues) { System.out.println("PRODUCT ATTR VALUES:" + productAttributeValues.toString()); ProductEntityValues prodAttrValue = new ProductEntityValues(); prodAttrValue.setProductId(productId); prodAttrValue.setAttributeId(attrId); prodAttrValue.setLanguage("enUS"); prodAttrValue.setId(productAttributeValues.getId()); prodAttrValue.setValue(productsMaster.toAttributedHashMap().get(attrValue)); productEntityValuesService.updateProductAttributeValues(prodAttrValue); //System.out.println("custAttrValue-->"+prodAttrValue.toString()); } } return status; }
From source file:com.cloudera.kitten.appmaster.params.lua.WorkflowParameters.java
public WorkflowParameters(String script, String jobName, Configuration conf, Map<String, Object> extras, Map<String, URI> localToUris) throws Exception { this.env = new HashMap<String, LuaWrapper>(); HashMap<String, String> operators = new HashMap<String, String>(); workflow = Utils.unmarshall(script); materializedWorkflow = new MaterializedWorkflow1("test", "/tmp"); materializedWorkflow.readFromWorkflowDictionary(workflow); LOG.info(materializedWorkflow.getTargets().get(0).toStringRecursive()); for (OperatorDictionary op : workflow.getOperators()) { if (op.getIsOperator().equals("true") && op.getStatus().equals("warn")) { operators.put(op.getName(), op.getName() + ".lua"); }//from w w w. j a v a 2 s . com } for (OperatorDictionary op : workflow.getOperators()) { if (op.getStatus().equals("warn") && op.getInput().isEmpty()) { op.setStatus("running"); workflow.setOutputsRunning(op.getName()); } } LOG.info("Operators: " + operators); int i = 0; for (Entry<String, String> e : operators.entrySet()) { LuaWrapper l = new LuaWrapper(e.getValue(), loadExtras(extras)).getTable("operator"); if (i == 0) this.e0 = l; i++; this.env.put(e.getKey(), l); } this.conf = conf; this.localToUris = localToUris; this.hostname = NetUtils.getHostname(); this.jobName = jobName; }
From source file:forge.game.combat.Combat.java
public void dealAssignedDamage() { // This function handles both Regular and First Strike combat assignment final HashMap<Card, Integer> defMap = defendingDamageMap; final HashMap<GameEntity, CardCollection> wasDamaged = new HashMap<GameEntity, CardCollection>(); final Map<Card, Integer> damageDealtThisCombat = new HashMap<Card, Integer>(); for (final Entry<Card, Integer> entry : defMap.entrySet()) { GameEntity defender = getDefenderByAttacker(entry.getKey()); if (defender instanceof Player) { // player if (((Player) defender).addCombatDamage(entry.getValue(), entry.getKey())) { if (wasDamaged.containsKey(defender)) { wasDamaged.get(defender).add(entry.getKey()); } else { CardCollection l = new CardCollection(); l.add(entry.getKey()); wasDamaged.put(defender, l); }/*from w w w . jav a 2 s .c om*/ damageDealtThisCombat.put(entry.getKey(), entry.getValue()); } } else if (defender instanceof Card) { // planeswalker if (((Card) defender).getController().addCombatDamage(entry.getValue(), entry.getKey())) { if (wasDamaged.containsKey(defender)) { wasDamaged.get(defender).add(entry.getKey()); } else { CardCollection l = new CardCollection(); l.add(entry.getKey()); wasDamaged.put(defender, l); } } } } // this can be much better below here... final CardCollection combatants = new CardCollection(); combatants.addAll(getAttackers()); combatants.addAll(getAllBlockers()); combatants.addAll(getDefendingPlaneswalkers()); Card c; for (int i = 0; i < combatants.size(); i++) { c = combatants.get(i); // if no assigned damage to resolve, move to next if (c.getTotalAssignedDamage() == 0) { continue; } final Map<Card, Integer> assignedDamageMap = c.getAssignedDamageMap(); final HashMap<Card, Integer> damageMap = new HashMap<Card, Integer>(); for (final Entry<Card, Integer> entry : assignedDamageMap.entrySet()) { final Card crd = entry.getKey(); damageMap.put(crd, entry.getValue()); if (entry.getValue() > 0) { if (damageDealtThisCombat.containsKey(crd)) { damageDealtThisCombat.put(crd, damageDealtThisCombat.get(crd) + entry.getValue()); } else { damageDealtThisCombat.put(crd, entry.getValue()); } } } c.addCombatDamage(damageMap); damageMap.clear(); c.clearAssignedDamage(); } // Run triggers for (final GameEntity ge : wasDamaged.keySet()) { final HashMap<String, Object> runParams = new HashMap<String, Object>(); runParams.put("DamageSources", wasDamaged.get(ge)); runParams.put("DamageTarget", ge); ge.getGame().getTriggerHandler().runTrigger(TriggerType.CombatDamageDoneOnce, runParams, false); } // This was deeper before, but that resulted in the stack entry acting like before. // when ... deals combat damage to one or more for (final Card damageSource : dealtDamageTo.keySet()) { final HashMap<String, Object> runParams = new HashMap<String, Object>(); int dealtDamage = damageDealtThisCombat.containsKey(damageSource) ? damageDealtThisCombat.get(damageSource) : 0; runParams.put("DamageSource", damageSource); runParams.put("DamageTargets", dealtDamageTo.get(damageSource)); runParams.put("DamageAmount", dealtDamage); damageSource.getGame().getTriggerHandler().runTrigger(TriggerType.DealtCombatDamageOnce, runParams, false); } dealtDamageToThisCombat.putAll(dealtDamageTo); dealtDamageTo.clear(); }
From source file:it.polito.tellmefirst.web.rest.clients.ClientEpub.java
/** * Classify an Epub document./* w ww. j a v a 2 s . co m*/ * * @param file the input file * @param fileName the input filename * @param url the url of the resource * @param numOfTopics number of topics to be returned * @param lang the language of the text to be classified ("italian" or "english") * @return A HashMap in which the key is a string with the title of the chapter and the value * is a list of the results of the classification process */ public ArrayList<String[]> classifyEpub(File file, String fileName, String url, int numOfTopics, String lang) throws TMFVisibleException { LOG.debug("[classifyEpub] - BEGIN"); if (!(file != null && fileName.toLowerCase().endsWith(".epub") || urlIsEpub(url))) { throw new TMFVisibleException("Resource not valid: only epub files allowed."); } File epubFile; if (url != null) { epubFile = fromURLtoFile(url); } else { epubFile = file; } ArrayList<String[]> results; results = new ArrayList<>(); HashMap<String, String> parserResults = new LinkedHashMap<>(); try { parserResults = parseEpub(epubFile); } catch (IOException e) { LOG.error("[classifyEpub] - EXCEPTION: ", e); throw new TMFVisibleException("The Epub parser cannot read the file."); } HashMap<String, List<ClassifyOutput>> classificationResults = new LinkedHashMap<>(); Set set = parserResults.entrySet(); Iterator i = set.iterator(); while (i.hasNext()) { Map.Entry me = (Map.Entry) i.next(); Text text = new Text((me.getValue().toString())); LOG.debug("* Title of the chapter"); LOG.debug(me.getKey().toString()); LOG.debug("* Text of the chapter"); LOG.debug(me.getValue().toString().substring(0, 100)); String textString = text.getText(); int totalNumWords = TMFUtils.countWords(textString); LOG.debug("TOTAL WORDS: " + totalNumWords); try { if (totalNumWords > 1000) { LOG.debug("Text contains " + totalNumWords + " words. We'll use Classify for long texts."); List<String[]> chapterResults = classifier.classify(textString, numOfTopics); classificationResults.put(me.getKey().toString(), jsonAdapter(chapterResults)); } else { LOG.debug("Text contains " + totalNumWords + " words. We'll use Classify for short texts."); List<String[]> chapterResults = classifier.classifyShortText(textString, numOfTopics); classificationResults.put(me.getKey().toString(), jsonAdapter(chapterResults)); } } catch (Exception e) { LOG.error("[classifyEpub] - EXCEPTION: ", e); throw new TMFVisibleException("Unable to extract topics from specified text."); } } ArrayList<ClassifyOutput> classifyOutputListSorted = sortResults(classificationResults); for (int k = 0; k < numOfTopics; k++) { String[] arrayOfFields = new String[6]; arrayOfFields[0] = classifyOutputListSorted.get(k).getUri(); arrayOfFields[1] = classifyOutputListSorted.get(k).getLabel(); arrayOfFields[2] = classifyOutputListSorted.get(k).getTitle(); arrayOfFields[3] = classifyOutputListSorted.get(k).getScore(); arrayOfFields[4] = classifyOutputListSorted.get(k).getMergedTypes(); arrayOfFields[5] = classifyOutputListSorted.get(k).getImage(); results.add(arrayOfFields); } LOG.debug("[classifyEpub] - END"); return results; }
From source file:com.yanbang.portal.controller.PortalController.java
/** * ??//from w w w.j a v a 2 s.com * * @param request * @param response * @return * @throws Exception */ @SuppressWarnings("rawtypes") @RequestMapping(params = "action=portalLeft") public ModelAndView portalBottom(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); SysUser user = (SysUser) this.getLoginUser(request); Collection<SysRole> rolelist = portalBiz.findRolesByUserCode(user.getUserCode()); String soft_licence = portalBiz.getLicences(); UserCompareBiz usercom = UserCompareBiz.getInstance(); usercom.setAddress(portalBiz.getServerAddr()); if (usercom.validaeAddress() || ValidateLicense.isLicenceNoExpired(soft_licence)) { rolelist = portalBiz.findRolesByUserCode(user.getUserCode()); } else { if (ValidateLicense.isLicenceDateExpired(soft_licence)) { rolelist = new ArrayList<SysRole>(); } else { rolelist = portalBiz.findRolesByUserCode(user.getUserCode()); } } // ?? HashMap<Long, SysMenu> totalMenuList = new HashMap<Long, SysMenu>(); // ?? TreeMap<Long, SysMenu> firstMenuMap = new TreeMap<Long, SysMenu>(); // ?? for (SysRole role : rolelist) { Collection<SysMenu> menulist = portalBiz.findMenusByListId(role.getRoleMenus()); for (SysMenu menu : menulist) { totalMenuList.put(menu.getMenuId(), menu); if (menu.getMenuGrade() == 1) { firstMenuMap.put(menu.getMenuOrder(), menu); } } } // =========================================== String strTotalMenusIds = "-1"; Iterator iterTotal = totalMenuList.entrySet().iterator(); while (iterTotal.hasNext()) { Map.Entry entry = (Map.Entry) iterTotal.next(); SysMenu menu = (SysMenu) entry.getValue(); strTotalMenusIds = strTotalMenusIds + "," + menu.getMenuId(); } // ============================================ Iterator iter = firstMenuMap.entrySet().iterator(); ArrayList<SysMenu> menulist = new ArrayList<SysMenu>(); // ??? while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); SysMenu menu1 = (SysMenu) entry.getValue(); MenuModel menuModel1 = new MenuModel(); menuModel1.setMenuId(menu1.getMenuId()); menuModel1.setMenuName(menu1.getMenuName()); menuModel1.setMenuURL(menu1.getMenuURL()); menuModel1.setMenuParentId(menu1.getMenuParentId()); menuModel1.setMenuGrade(menu1.getMenuGrade()); menuModel1.setMenuTarget(menu1.getMenuTarget()); // ---------------------------------------------------------- // ??? Collection<SysMenu> menu2list = portalBiz.findAllChildMenus(menu1.getMenuId(), strTotalMenusIds); if (menu2list != null) { ArrayList<MenuModel> menu2RetList = new ArrayList<MenuModel>(); for (SysMenu menu2 : menu2list) { MenuModel menuModel2 = new MenuModel(); menuModel2.setMenuId(menu2.getMenuId()); menuModel2.setMenuName(menu2.getMenuName()); menuModel2.setMenuURL(menu2.getMenuURL()); menuModel2.setMenuParentId(menu2.getMenuParentId()); menuModel2.setMenuGrade(menu2.getMenuGrade()); menuModel2.setMenuTarget(menu2.getMenuTarget()); // ??? Collection<SysMenu> menu3list = portalBiz.findAllChildMenus(menu2.getMenuId(), strTotalMenusIds); if (menu3list != null) { ArrayList<MenuModel> menu3RetList = new ArrayList<MenuModel>(); for (SysMenu menu3 : menu3list) { MenuModel menuModel3 = new MenuModel(); menuModel3.setMenuId(menu3.getMenuId()); menuModel3.setMenuName(menu3.getMenuName()); menuModel3.setMenuURL(menu3.getMenuURL()); menuModel3.setMenuParentId(menu3.getMenuParentId()); menuModel3.setMenuGrade(menu3.getMenuGrade()); menuModel3.setMenuTarget(menu3.getMenuTarget()); menu3RetList.add(menuModel3); } menuModel2.setChildMenuList(menu3RetList); } menu2RetList.add(menuModel2); } menuModel1.setChildMenuList(menu2RetList); } // ---------------------------------------------------------- menulist.add(menuModel1); } map.put("menulist", menulist); return new ModelAndView("portal/portalLeft", map); }