List of usage examples for java.lang Integer intValue
@HotSpotIntrinsicCandidate public int intValue()
From source file:com.appspot.potlachkk.controller.GiftSvc.java
@RequestMapping(value = GiftSvcApi.GIFT_SVC_PATH_GIFT, method = RequestMethod.DELETE) public @ResponseBody Void deleteGiftById(@PathVariable("id") Long id) { Gift g = gifts.findById(id);//from w ww . j a va 2 s.c o m //check if user has right to delete the gift //it would be nice to have it method level security //but id doeasn't work well with retrofit //(see description in file header) User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String name = user.getUsername(); //get logged in username if (!g.getUsername().equals(name)) { //TODO different exception throw new ResourceNotFoundException(); } //check if the gift is not last in his chain //if it is the last one remove also the chain Integer giftsInChain = chains.getGiftsSize(g.getChainId()); if (giftsInChain.intValue() == 1) { chains.delete(g.getChainId()); } gifts.delete(id); return null; }
From source file:edu.hm.muse.controller.Logincontroller.java
@RequestMapping(value = "/adminlogin.secu", method = RequestMethod.POST) public ModelAndView doAdminLogin(@RequestParam(value = "mpwd", required = false) String mpwd, @RequestParam(value = "csrftoken", required = false) String csrfParam, HttpServletResponse response, HttpSession session) {//from w w w.j av a 2 s .c o m if (null == mpwd || mpwd.isEmpty()) { throw new SuperFatalAndReallyAnnoyingException( "I can not process, because the requestparam mpwd is empty or null or something like this"); } String sql = "select count (*) from M_ADMIN where mpwd = ?"; try { String digest = calculateSHA256(new ByteArrayInputStream(mpwd.getBytes("UTF8"))); int res = 0; res = jdbcTemplate.queryForInt(sql, new Object[] { digest }, new int[] { Types.VARCHAR }); Integer csrfTokenSess = (Integer) session.getAttribute("csrftoken"); if (res != 0 && csrfParam != null && !csrfParam.isEmpty() && csrfTokenSess != null) { Integer csrfParamToken = Integer.parseInt(csrfParam); if (csrfParamToken.intValue() == csrfTokenSess.intValue()) { SecureRandom random = new SecureRandom(); int token = random.nextInt(); session.setAttribute("user", "admin"); session.setAttribute("login", true); session.setAttribute("admintoken", token); response.addCookie(new Cookie("admintoken", String.valueOf(token))); session.removeAttribute("csrftoken"); return new ModelAndView("redirect:adminintern.secu"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (ClassCastException ccastEx) { ccastEx.printStackTrace(); } catch (NumberFormatException nfoEx) { nfoEx.printStackTrace(); } catch (DataAccessException e) { throw new SuperFatalAndReallyAnnoyingException( String.format("Sorry but %sis a bad grammar or has following problem %s", sql, e.getMessage())); } ModelAndView mv = returnToAdminLogin(session); return mv; }
From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataQuestionTypeFormController.java
@RequestMapping(method = RequestMethod.POST) public String saveQuestionType(HttpServletRequest request, ModelMap map, @RequestParam(required = false) Integer id, @RequestParam(required = true) String name, @RequestParam(required = false) String description, @RequestParam(required = false) Class<? extends FacilityDataQuestionType> dataType, @RequestParam(required = false) Double minValue, @RequestParam(required = false) Double maxValue, @RequestParam(required = false) Boolean allowDecimals, @RequestParam(required = false) Integer[] optionId, @RequestParam(required = false) String[] optionName, @RequestParam(required = false) String[] optionCode, @RequestParam(required = false) String[] optionDescription) throws Exception { FacilityDataQuestionType questionType = getQuestionType(id, dataType); questionType.setName(name);//from w ww. j av a2 s . co m questionType.setDescription(description); if (questionType instanceof NumericFacilityDataQuestionType) { NumericFacilityDataQuestionType numericType = (NumericFacilityDataQuestionType) questionType; numericType.setMinValue(minValue); numericType.setMaxValue(maxValue); numericType.setAllowDecimals(allowDecimals != null && allowDecimals == Boolean.TRUE); } else if (questionType instanceof CodedFacilityDataQuestionType) { CodedFacilityDataQuestionType codedType = (CodedFacilityDataQuestionType) questionType; Map<Integer, Integer> codedOptionBreakdown = getService().getCodedOptionBreakdown(); Date now = new Date(); List<Integer> passedOptionIds = Arrays.asList(optionId); Set<Integer> removedOptionIds = new HashSet<Integer>(); // First we need to go through existing options, and delete or retire as needed for (Iterator<FacilityDataCodedOption> i = codedType.getOptions().iterator(); i.hasNext();) { FacilityDataCodedOption option = i.next(); if (!passedOptionIds.contains(option.getId())) { // In this case we need to delete or retire Integer numValues = codedOptionBreakdown.get(option.getId()); if (numValues == null || numValues.intValue() == 0) { // If no values are saved for it, we can delete i.remove(); removedOptionIds.add(option.getId()); } else { // If values exist for it, we have to retire option.setRetired(true); option.setRetiredBy(Context.getAuthenticatedUser()); option.setDateRetired(now); } } } // Now we go through passed options and update or add as needed for (int i = 0; i < optionId.length; i++) { if (optionCode[i].length() > 0 && optionName[i].length() > 0 && !removedOptionIds.contains(optionId[i])) { FacilityDataCodedOption codedOption = null; if (optionId[i] != null) { codedOption = codedType.getOptionById(optionId[i]); } else { codedOption = new FacilityDataCodedOption(); codedType.getOptions().add(codedOption); } codedOption.setName(optionName[i]); codedOption.setCode(optionCode[i]); codedOption.setDescription(optionDescription[i]); codedOption.setRetired(false); codedOption.setRetiredBy(null); codedOption.setDateRetired(null); } } } BindingResult result = new BeanPropertyBindingResult(questionType, "questionType"); new FacilityDataQuestionTypeValidator().validate(questionType, result); if (result.hasErrors()) { return "/module/facilitydata/questionTypeForm"; } Context.getService(FacilityDataService.class).saveQuestionType(questionType); return "redirect:questionType.list"; }
From source file:com.asakusafw.cleaner.log.LogMessageManager.java
/** * ID?????//from w ww . ja v a2s . co m * <p> * ??ID????????? * ???? * ??ID?????ID=xxx?=xxx, xxx, xxx? * </p> * <p> * ??????????? * ???? * </p> * @param messageId ID * @param messageArgs * @return */ public String createLogMessage(String messageId, Object... messageArgs) { Object[] messageArgsConverted = toStringMessageArgs(messageArgs); String templateStr = templateMap.get(messageId); if (templateStr == null) { String message = MessageFormat.format(MESSAGE_ID_NOT_FOUND, messageId, StringUtils.join(messageArgsConverted, ", ")); return message; } Integer index = sizeMap.get(messageId); if (index != null) { if (messageArgsConverted.length != index.intValue()) { String message = MessageFormat.format(ILLEGAL_SIZE, new Date(), messageId, StringUtils.join(messageArgsConverted, ", ")); System.err.println(message); } } return MessageFormat.format(templateStr, messageArgsConverted); }
From source file:org.syncope.core.persistence.dao.UserTest.java
@Test public void count() { Integer count = userDAO.count(EntitlementUtil.getRoleIds(entitlementDAO.findAll())); assertNotNull(count);/* w w w. j ava 2s .c om*/ assertEquals(4, count.intValue()); }
From source file:net.sourceforge.eclipsetrader.core.internal.TradingSystemRepository.java
private Integer getNextId(Integer id) { return new Integer(id.intValue() + 1); }
From source file:CountedSet.java
/** * Return the count of the specified object. * @param o the object whose count needs to be determined. * @return the count of the specified object. *//*from www . j a v a 2s. c o m*/ public int getCount(Object o) { Integer count = (Integer) cset.get(o); if (count == null) { return 0; } else { return count.intValue(); } }
From source file:net.nosleep.superanalyzer.analysis.views.GrowthView.java
private void refreshDataset() { TimeSeries series1 = new TimeSeries(Misc.getString("SONGS_IN_LIBRARY")); Hashtable addedHash = null;/* ww w . j a v a 2 s . co m*/ if (_comboBox == null) { addedHash = _analysis.getDatesAdded(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); addedHash = _analysis.getDatesAdded(item.getKind(), item.getValue()); } Vector items = new Vector(); Enumeration e = addedHash.keys(); while (e.hasMoreElements()) { Day day = (Day) e.nextElement(); Integer count = (Integer) addedHash.get(day); if (count.intValue() > 0) { items.addElement(new GrowthItem(day, count)); } } Collections.sort(items, new GrowthComparator()); double value = 0.0; for (int i = 0; i < items.size(); i++) { GrowthItem item = (GrowthItem) items.elementAt(i); value += item.Count; series1.add(item.Day, value); } _dataset.removeAllSeries(); _dataset.addSeries(series1); }
From source file:edu.utah.further.mdr.data.common.domain.asset.ResourceTypeEntity.java
/** * @param other/*from ww w . ja v a 2s.c om*/ * @return * @see edu.utah.further.mdr.api.domain.asset.Resource#copyFrom(edu.utah.further.mdr.api.domain.asset.Resource) */ @Override public ResourceType copyFrom(final BasicLookupValue other) { if (other == null) { return this; } // Identifier is not copied // Deep-copy fields this.label = other.getLabel(); final Integer otherOrder = other.getOrder(); if (otherOrder != null) { this.order = new Integer(otherOrder.intValue()); } // Deep-copy collection references but soft-copy their elements return this; }
From source file:com.bdx.rainbow.service.basic.impl.MedicineService.java
public TBasicSkuItem findDrcFromCFDA(String jgmCode) throws Exception { if (StringUtils.isBlank(jgmCode)) throw new Exception("?"); TBasicSkuItem drc = selectDrcByCode(jgmCode); if (drc != null) return drc; String url = "http://mobile.cfda.gov.cn/services/code/codeQueryCFDA?code=" + jgmCode + "&phone=EC03E7D2-7AEF-46AE-AD0D-F6F0B1804A5A"; logger.debug(url);/*w w w . j a v a 2 s . c o m*/ Map<String, String> header = new HashMap<String, String>(0); String json = HttpClientUtil.getStringResponse(url, "get", header, null, null, "utf-8"); // String json = HttpClientUtil.getStringResponseByProxy(url, "get", header, null, null, "10.10.10.78",8080,"utf-8"); System.out.println("#########################"); System.out.println("json" + json); System.out.println("#########################"); if (StringUtils.isBlank(json) == false) { try { ObjectMapper mapper = new ObjectMapper(); Map map = (Map) mapper.readValue(json, Map.class); Map infoMap = (Map) map.get("info"); Integer retcode = (Integer) infoMap.get("retcode"); if (infoMap != null && retcode != null && retcode.intValue() == 0) { drc = new TBasicSkuItem(); drc.setApprovalNum( infoMap.get("license_number") == null ? "" : infoMap.get("license_number").toString());// drc.setLastFlowTime( infoMap.get("last_time") == null ? "" : infoMap.get("last_time").toString());// drc.setFlow(infoMap.get("flow") == null ? "" : infoMap.get("flow").toString()); drc.setPkgSpec(infoMap.get("pkg_spec") == null ? "" : infoMap.get("pkg_spec").toString()); drc.setSaleTime(infoMap.get("sale_time") == null ? "" : infoMap.get("sale_time").toString()); drc.setItemName(infoMap.get("title") == null ? "" : infoMap.get("title").toString());// drc.setForm(infoMap.get("prepn_type") == null ? "" : infoMap.get("prepn_type").toString());// drc.setFormUnit(infoMap.get("prepn_unit") == null ? "" : infoMap.get("prepn_unit").toString());// drc.setPkgUnit(infoMap.get("pkg_unit") == null ? "" : infoMap.get("pkg_unit").toString()); drc.setIssueExpiry( infoMap.get("issue_expiry") == null ? "" : infoMap.get("issue_expiry").toString()); // drc.setFirstQuery(infoMap.get("first_query") ==null?"":infoMap.get("first_query").toString()); drc.setLastEnt(infoMap.get("last_ent") == null ? "" : infoMap.get("last_ent").toString()); drc.setBatchNo(infoMap.get("production_batch") == null ? "" : infoMap.get("production_batch").toString()); drc.setFlow(infoMap.get("status") == null ? "" : infoMap.get("status").toString());// drc.setSaleEnt(infoMap.get("sale_ent") == null ? "" : infoMap.get("sale_ent").toString());// drc.setThumbUrl(infoMap.get("thumb_url") == null ? "" : infoMap.get("thumb_url").toString()); drc.setItemBarcode(jgmCode);// drc.setProductionDate(infoMap.get("production_date") == null ? "" : infoMap.get("production_date").toString()); drc.setSpec( infoMap.get("specifications") == null ? "" : infoMap.get("specifications").toString());// drc.setCategory(infoMap.get("category") == null ? "" : infoMap.get("category").toString()); drc.setManufactory( infoMap.get("manufacturer") == null ? "" : infoMap.get("manufacturer").toString());// drc.setExpireDate( infoMap.get("expiry_date") == null ? "" : infoMap.get("expiry_date").toString());// logger.debug("drc ?:" + mapper.writeValueAsString(drc)); } } catch (Exception e) { e.printStackTrace(); throw e; } } if (drc != null) { insertDrugItem(drc); } return drc; }