List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:com.fatsecret.platform.utils.ServingUtility.java
/** * Returns food nutrient values according to serving sizes * /*from w w w. j a v a 2 s. com*/ * @param json json object representing nutritional information of the food * @return food nutrient values according to serving sizes */ public static Serving parseServingFromJSONObject(JSONObject json) { Serving serving = new Serving(); try { Long servingId = Long.parseLong(json.getString("serving_id")); serving.setServingId(servingId); } catch (Exception ignore) { } try { String servingDescription = json.getString("serving_description"); serving.setServingDescription(servingDescription); } catch (Exception ignore) { } try { String servingUrl = json.getString("serving_url"); serving.setServingUrl(servingUrl); } catch (Exception ignore) { } try { String metricServingAmountString = json.getString("metric_serving_amount"); BigDecimal metricServingAmount = new BigDecimal(metricServingAmountString); serving.setMetricServingAmount(metricServingAmount); } catch (Exception ignore) { } try { String metricServingUnit = json.getString("metric_serving_unit"); serving.setMetricServingUnit(metricServingUnit); } catch (Exception ignore) { } try { String numberOfUnitsString = json.getString("number_of_units"); BigDecimal numberOfUnits = new BigDecimal(numberOfUnitsString); serving.setNumberOfUnits(numberOfUnits); } catch (Exception ignore) { } try { String measurementDescription = json.getString("measurement_description"); serving.setMeasurementDescription(measurementDescription); } catch (Exception ignore) { } try { String caloriesString = json.getString("calories"); BigDecimal calories = new BigDecimal(caloriesString); serving.setCalories(calories); } catch (Exception ignore) { } try { String carbohydrateString = json.getString("carbohydrate"); BigDecimal carbohydrate = new BigDecimal(carbohydrateString); serving.setCarbohydrate(carbohydrate); } catch (Exception ignore) { } try { String proteinString = json.getString("protein"); BigDecimal protein = new BigDecimal(proteinString); serving.setProtein(protein); } catch (Exception ignore) { } try { String fatString = json.getString("fat"); BigDecimal fat = new BigDecimal(fatString); serving.setFat(fat); } catch (Exception ignore) { } try { String saturatedFatString = json.getString("saturated_fat"); BigDecimal saturatedFat = new BigDecimal(saturatedFatString); serving.setSaturatedFat(saturatedFat); } catch (Exception ignore) { } try { String polyunsaturatedFatString = json.getString("polyunsaturated_fat"); BigDecimal polyunsaturatedFat = new BigDecimal(polyunsaturatedFatString); serving.setPolyunsaturatedFat(polyunsaturatedFat); } catch (Exception ignore) { } try { String monounsaturatedFatString = json.getString("monounsaturated_fat"); BigDecimal monounsaturatedFat = new BigDecimal(monounsaturatedFatString); serving.setMonounsaturatedFat(monounsaturatedFat); } catch (Exception ignore) { } try { String transFatString = json.getString("trans_fat"); BigDecimal transFat = new BigDecimal(transFatString); serving.setTransFat(transFat); } catch (Exception ignore) { } try { String cholesterolString = json.getString("cholesterol"); BigDecimal cholesterol = new BigDecimal(cholesterolString); serving.setCholesterol(cholesterol); } catch (Exception ignore) { } try { String sodiumString = json.getString("sodium"); BigDecimal sodium = new BigDecimal(sodiumString); serving.setSodium(sodium); } catch (Exception ignore) { } try { String potassiumString = json.getString("potassium"); BigDecimal potassium = new BigDecimal(potassiumString); serving.setPotassium(potassium); } catch (Exception ignore) { } try { String fiberString = json.getString("fiber"); BigDecimal fiber = new BigDecimal(fiberString); serving.setFiber(fiber); } catch (Exception ignore) { } try { String sugarString = json.getString("sugar"); BigDecimal sugar = new BigDecimal(sugarString); serving.setSugar(sugar); } catch (Exception ignore) { } try { String vitaminAString = json.getString("vitamin_a"); BigDecimal vitaminA = new BigDecimal(vitaminAString); serving.setVitaminA(vitaminA); } catch (Exception ignore) { } try { String vitaminCString = json.getString("vitamin_c"); BigDecimal vitaminC = new BigDecimal(vitaminCString); serving.setVitaminC(vitaminC); } catch (Exception ignore) { } try { String calciumString = json.getString("calcium"); BigDecimal calcium = new BigDecimal(calciumString); serving.setCalcium(calcium); } catch (Exception ignore) { } try { String ironString = json.getString("iron"); BigDecimal iron = new BigDecimal(ironString); serving.setIron(iron); } catch (Exception ignore) { } return serving; }
From source file:controllers.user.FriendsApp.java
/** * ?/*w w w . j a v a 2s. c o m*/ * @return */ @Transactional public static Result addFriend() { DynamicForm requestData = Form.form().bindFromRequest(); String friendId = requestData.get("friendId"); String messageId = requestData.get("messageId"); if (StringUtils.isBlank(friendId)) { return ok("{\"status\":\"0\",\"error\":\"?friendId?\"}"); } if (StringUtils.isBlank(messageId)) { return ok("{\"status\":\"0\",\"error\":\"?messageId?\"}"); } User me = User.getFromSession(session()); User friend = User.findById(Long.parseLong(friendId)); if (friend == null) { return ok("{\"status\":\"0\",\"error\":\"???\"}"); } Boolean flag = FriendsService.addFriend(me, friend); //? Boolean flag2 = FriendsService.addFriend(friend, me); //? ObjectNodeResult result = null; if (flag && flag2) { result = new ObjectNodeResult(ObjectNodeResult.STATUS_SUCCESS); } else { result = new ObjectNodeResult(ObjectNodeResult.STATUS_FAILED); } MessageService.pushMsgAgreeFriends(me, friend); MessageService.handlerMessage(Long.parseLong(messageId)); // ??? return ok(result.getObjectNode()); }
From source file:com.nokia.example.lwuit.rlinks.model.CommentThing.java
/** * Create a CommentThing from a JSON data String. * * @param obj JSONObject containing data for the Comment * @return A CommentThing object//w ww .jav a2 s .com * @throws JSONException If the given JSONObject can't be parsed */ public static CommentThing fromJson(JSONObject obj) throws JSONException { CommentThing thing = new CommentThing(); thing.setAuthor(obj.optString("author")); thing.setBody(HtmlEntityDecoder.decode(obj.optString("body"))); // Comments have a created date, 'More' items don't if (obj.has("created_utc")) { try { // "1329913184.0" -> "13299131840000" String dateStr = obj.getString("created_utc").substring(0, 9) + "0000"; thing.setCreated(new Date(Long.parseLong(dateStr))); } catch (Exception e) { System.out.println("Couldn't set date: " + e.getMessage()); } } thing.setId(obj.optString("id")); thing.setName(obj.optString("name")); thing.setScore(obj.optInt("ups"), obj.optInt("downs")); // 'Likes' can be true, false or null; map that to 1, -1, and 0 thing.setVote(obj.isNull("likes") ? 0 : obj.getBoolean("likes") ? 1 : -1); // Set child IDs. These are used for dynamically fetching more replies // to a comment. JSONArray childrenArray = obj.optJSONArray("children"); if (childrenArray != null) { int len = childrenArray.length(); String[] childIds = new String[len]; for (int i = 0; i < len; i++) { childIds[i] = childrenArray.getString(i); } thing.setChildIds(childIds); } return thing; }
From source file:net.longfalcon.newsj.util.NntpUtil.java
/** * Parse a response line from {@link #retrieveArticleInfo(long, long)}. * * @param line a response line/*w w w . ja va 2s. co m*/ * @return the parsed {@link Article}, if unparseable then isDummy() * will be true, and the subject will contain the raw info. * @since 3.0 */ public static Article parseArticleEntry(String line) { // Extract the article information // Mandatory format (from NNTP RFC 2980) is : // articleNumber\tSubject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count Article article = new Article(); article.setSubject(line); // in case parsing fails String parts[] = line.split("\t"); if (parts.length > 6) { int i = 0; try { article.setArticleNumber(Long.parseLong(parts[i++])); article.setSubject(parts[i++]); article.setFrom(parts[i++]); article.setDate(parts[i++]); article.setArticleId(parts[i++]); article.addReference(parts[i++]); } catch (NumberFormatException e) { // ignored, already handled } } return article; }
From source file:com.wineaccess.wineryOWS.WineryOwsAdapterHelper.java
/** * this method is to create the winery historical ows data * @param addWineryOwsPO//from ww w. jav a2 s . c om * return map the output map */ public static Map<String, Object> addUpdateWineryOwsData(final AddUpdateWineryOwsPO addUpdateWineryOwsPO) { logger.info("start add/update winery historical Ows data"); final Map<String, Object> output = new ConcurrentHashMap<String, Object>(); Response response = null; final WineryHistoricalOwsData historicalOwsData = WineryOwsDataRepository .getOwsDataByWineryId(Long.parseLong(addUpdateWineryOwsPO.getWineryid())); if (historicalOwsData != null) { if (isValidDates(addUpdateWineryOwsPO)) { populateOwsDataModelFromPO(addUpdateWineryOwsPO, historicalOwsData); WineryOwsDataRepository.update(historicalOwsData); AddUpdateWineryOwsVO addUpdateWineryOwsVO = new AddUpdateWineryOwsVO( SystemErrorCode.WINERY_OWS_UPDATE_SUCCESS_TEXT); addUpdateWineryOwsVO.setId(historicalOwsData.getId()); addUpdateWineryOwsVO.setWineryId(historicalOwsData.getWineryid()); response = new com.wineaccess.response.SuccessResponse(addUpdateWineryOwsVO, SUCCESS_CODE); } else { response = ApplicationUtils.errorMessageGenerate( WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR, WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR_TEXT, SUCCESS_CODE); } } else { if (isValidDates(addUpdateWineryOwsPO)) { final WineryModel wineryModel = WineryRepository .getWineryById(Long.parseLong(addUpdateWineryOwsPO.getWineryid())); if (wineryModel != null) { try { WineryHistoricalOwsData wineryHistoricalOwsData = new WineryHistoricalOwsData(); populateOwsDataModelFromPO(addUpdateWineryOwsPO, wineryHistoricalOwsData); WineryOwsDataRepository.save(wineryHistoricalOwsData); AddUpdateWineryOwsVO addWineryOwsVO = new AddUpdateWineryOwsVO( SystemErrorCode.WINERY_OWS_ADD_SUCCESS_TEXT); addWineryOwsVO.setId(wineryHistoricalOwsData.getId()); addWineryOwsVO.setWineryId(wineryHistoricalOwsData.getWineryid()); response = new com.wineaccess.response.SuccessResponse(addWineryOwsVO, SUCCESS_CODE); } catch (Exception e) { logger.error("Some error occured " + e.getMessage(), e); } } else { response = ApplicationUtils.errorMessageGenerate( WineaccessErrorCodes.SystemErrorCode.WINERY_NOT_FOUND_OWS, WineaccessErrorCodes.SystemErrorCode.WINERY_NOT_FOUND_OWS_TEXT, SUCCESS_CODE); } } else { response = ApplicationUtils.errorMessageGenerate( WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR, WineaccessErrorCodes.SystemErrorCode.WINERY_DATE_ERROR_TEXT, SUCCESS_CODE); } } output.put(OUPUT_PARAM_KEY, response); logger.info("exit add/update winery historical Ows data"); return output; }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID.//from ww w.j ava 2s .c om */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:br.ufg.calendario.converters.RegionalConverter.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { try {//from ww w . j a v a2 s . co m Regional regional = regionalDao.buscarPorId(Long.parseLong(value)); return regional; } catch (NumberFormatException e) { return null; } }
From source file:cz.strmik.cmmitool.web.controller.propertyeditor.ModelEditor.java
@Override public void setAsText(String text) { if (StringUtils.isEmpty(text)) { setValue(null);/*from ww w . j a v a2s . c o m*/ } else { setValue(modelDao.read(Long.parseLong(text))); } }
From source file:com.mycompany.CRMFly.Converters.TaskConverter.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { Long id = Long.parseLong(value.split(" ")[0]); return taskBean.getTaskForId(id); }
From source file:br.ufg.calendario.converters.CalendarioConverter.java
@Override public Object getAsObject(FacesContext context, UIComponent component, String value) { try {/*from w ww . j a v a2s.co m*/ Calendario calendario = calendarioDao.buscarPorId(Long.parseLong(value)); return calendario; } catch (NumberFormatException e) { return null; } }