List of usage examples for java.lang NumberFormatException toString
public String toString()
From source file:com.mec.Services.EstablecimientosService.java
private void setGeoAndConexiones(EstablecimientoPost establecimiento) { establecimiento.getLocalizacion().forEach((loc) -> { loc.setConexiones(conexionesEstablecimientosDAO.getByCueAnexo(establecimiento.getCue(), Short.parseShort(loc.getAnexo()))); loc.setElectricidad(electricidadEstablecimientosDAO.getByCueAnexo(establecimiento.getCue(), Short.parseShort(loc.getAnexo()))); loc.getDomicilios().forEach((dom) -> { try { dom.setGeo(geoDAO.getByCueAnexo(Integer.parseInt(establecimiento.getCue()), Integer.parseInt(loc.getAnexo()))); } catch (NumberFormatException e) { System.out.println("NumberFormatException: " + e.toString()); }/*w ww. java 2s .c om*/ }); }); }
From source file:org.wikipedia.nirvana.nirvanabot.pagesfetcher.PageListProcessorSlow.java
public HashSet<String> getIgnorePages(NirvanaWiki wiki, HashSet<String> ignorePages) throws IOException, ServiceError { HashSet<String> ignore = ignorePages; if (ignore == null) ignore = new HashSet<String>(); for (String category : categoriesToIgnore) { //log.info("Processing data of " + category); String line;//from w ww. j a va2s. c o m String pageList = this.pageListsToIgnore.get(category); if (pageList.startsWith("ERROR : MYSQL error")) { log.error("Invalid service output: " + StringTools.trancateTo(pageList, 100)); throw new ServiceError("Invalid output of service: " + service.getName()); } BufferedReader br = new BufferedReader(new StringReader(pageList)); for (int j = 0; j < service.SKIP_LINES; j++) br.readLine(); Pattern p = Pattern.compile(LINE_RULE); int j = 0; while ((line = br.readLine()) != null) { j++; if (line.isEmpty()) continue; if (j < LINES_TO_CHECK && !p.matcher(line).matches()) { log.error("Invalid service output line: " + line); throw new ServiceError("Invalid output of service: " + service.getName()); } String[] groups = line.split("\t"); if (groups[service.NS_POS].equals(String.valueOf(this.namespace))) { String title = groups[service.TITLE_POS].replace('_', ' '); ignore.add(title); } else if (groups[service.NS_POS].equals(String.valueOf(Wiki.USER_NAMESPACE)) && namespace != Wiki.USER_NAMESPACE) { long revId = 0; if (service.REVID_POS >= 0) { try { revId = Long.parseLong(groups[service.REVID_POS]); } catch (NumberFormatException e) { log.error(e.toString()); continue; } Revision r = wiki.getRevision(revId); String title = r.getPage(); ignore.add(title); } } } } return ignore; }
From source file:cn.code.notes.gtask.data.SqlData.java
public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) { mDiffDataValues.remove(DataColumns.ID); }//from w w w . j ava 2 s. c o m mDiffDataValues.put(DataColumns.NOTE_ID, noteId); Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues); try { mDataId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } } else { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null); } else { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { String.valueOf(noteId), String.valueOf(version) }); } if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } mDiffDataValues.clear(); mIsCreate = false; }
From source file:org.generationcp.breeding.manager.crossingmanager.SelectGermplasmListTreeComponent.java
public void displayGermplasmListDetails(int germplasmListId) throws InternationalizableException { try {/* w w w.j a v a 2 s . c o m*/ displayGermplasmListInfo(germplasmListId); } catch (NumberFormatException e) { LOG.error(e.toString() + "\n" + e.getStackTrace()); e.printStackTrace(); MessageNotifier.showWarning(messageSource.getMessage(Message.ERROR_INVALID_FORMAT), messageSource.getMessage(Message.ERROR_IN_NUMBER_FORMAT), Position.MIDDLE_CENTER); } catch (MiddlewareQueryException e) { LOG.error(e.toString() + "\n" + e.getStackTrace()); throw new InternationalizableException(e, Message.ERROR_DATABASE, Message.ERROR_IN_CREATING_GERMPLASMLIST_DETAILS_WINDOW); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.bamloader.LoaderBAM.java
private BAMFile getBamFileBean(final String[] rowData) throws Exception { int maxColumns = (BAMLoaderConstants.isExtendedBAMFile()) ? 10 : 7; if (rowData.length != maxColumns) { throw new Exception("Contains data for " + rowData.length + " columns"); }//from ww w . j a v a 2s .c om BAMFile bf = new BAMFile(); int index = (BAMLoaderConstants.isExtendedBAMFile()) ? 1 : 0; bf.setBiospecimenId(getAliquotId(rowData[index++])); bf.setFileNameBAM(rowData[index++]); bf.setDiseaseId(Integer.parseInt(rowData[index++])); bf.setCenterId(Integer.parseInt(rowData[index++])); try { bf.setFileSizeBAM(Long.parseLong(rowData[index++])); } catch (NumberFormatException nfe) { logger.info(nfe.toString()); bf.setFileSizeBAM(0L); } bf.setDateReceived(format.parse(rowData[index++])); bf.setDatatypeBAMId(Integer.parseInt(rowData[index++])); if (BAMLoaderConstants.isExtendedBAMFile()) { bf.setAnalysisId(rowData[0]); bf.setAnalyteCode(rowData[index++]); bf.setLibraryStrategy(rowData[index]); } return bf; }
From source file:net.longfalcon.web.SearchController.java
@RequestMapping("/search/{searchToken}") public String searchView(@PathVariable("searchToken") String search, @RequestParam(value = "t", required = false) String categories, @RequestParam(value = "g", required = false) String groupName, @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset, @RequestParam(value = "ob", required = false) String orderBy, Model model) throws NoSuchResourceException { List<Integer> categoryIds = new ArrayList<>(); if (ValidatorUtil.isNotNull(categories)) { String[] categoryIdStrings = categories.split(","); for (String categoryIdString : categoryIdStrings) { try { int categoryId = Integer.parseInt(categoryIdString); Category category = categoryService.getCategory(categoryId); if (category != null) { categoryIds.add(categoryId); } else { throw new NoSuchResourceException(); }/*from ww w.j ava2 s .co m*/ } catch (NumberFormatException nfe) { _log.warn(categoryIdString + " is not a number " + nfe.toString()); } } } long groupId = -1; if (ValidatorUtil.isNotNull(groupName)) { Group group = groupDAO.getGroupByName(groupName); if (group != null) { groupId = group.getId(); } } User user = userDAO.findByUserId(getUserId()); if (user != null) { model.addAttribute("lastVisit", user.getLastLogin()); } List<Integer> userExCats = userExCatDAO.getUserExCatIds(getUserId()); List<Release> releaseList = new ArrayList<>(); int pagerTotalItems = 0; if (ValidatorUtil.isNotNull(search)) { pagerTotalItems = Math .toIntExact(searchService.getSearchCount(search, categoryIds, -1, userExCats, groupId)); if (ValidatorUtil.isNull(orderBy)) { releaseList = searchService.getSearchReleases(search, categoryIds, -1, userExCats, groupId, "postDate", true, offset, PAGE_SIZE); } else { String propertyName = getOrderByProperty(orderBy); boolean descending = getOrderByOrder(orderBy); if (ValidatorUtil.isNotNull(propertyName)) { releaseList = searchService.getSearchReleases(search, categoryIds, -1, userExCats, groupId, propertyName, descending, offset, PAGE_SIZE); } } } model.addAttribute("search", search); model.addAttribute("searchCategories", categories); model.addAttribute("groupName", groupName); model.addAttribute("releaseList", releaseList); model.addAttribute("pagerTotalItems", pagerTotalItems); model.addAttribute("pagerOffset", offset); model.addAttribute("pagerItemsPerPage", PAGE_SIZE); model.addAttribute("orderBy", orderBy); model.addAttribute("now", new Date()); return "search"; }
From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java
@Override public int getIntValue(String key) throws QTasteDataException { try {//from w w w . j a va2 s .com return Integer.parseInt(getValue(key)); } catch (NumberFormatException e) { throw new QTasteDataException(e.toString() + " while parsing integer data " + key, e); } }
From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java
@Override public double getDoubleValue(String key) throws QTasteDataException { try {/*w w w . j av a 2 s. co m*/ return Double.parseDouble(getValue(key)); } catch (NumberFormatException e) { throw new QTasteDataException(e.toString() + " while parsing double data " + key, e); } }
From source file:org.mule.transport.jms.filters.JmsPropertyFilter.java
public boolean accept(MuleMessage message) { if (StringUtils.isBlank(propertyName)) { logger.warn("No property name was specified"); return false; }/* w ww. jav a2s .c o m*/ if (StringUtils.isBlank(expression) && pattern == null) { logger.warn("Either no expression or pattern was specified"); return false; } if (message.getPayload() instanceof javax.jms.Message) { try { Message m = (javax.jms.Message) message.getPayload(); if (StringUtils.isBlank(propertyClass)) { Object object = m.getObjectProperty(propertyName); if (object == null) { return false; } String value = object.toString(); if (pattern != null) { return pattern.matcher(value).find(); } else { return value.equals(expression); } } else if (propertyClass.equals("java.lang.String")) { String value = m.getStringProperty(propertyName); if (value == null) { return false; } if (pattern != null) { return pattern.matcher(value).find(); } else { return value.equals(expression); } } else if (propertyClass.equals("java.lang.Integer")) { int value = m.getIntProperty(propertyName); int match = Integer.parseInt(expression); return (value == match); } else if (propertyClass.equals("java.lang.Short")) { short value = m.getShortProperty(propertyName); short match = Short.parseShort(expression); return (value == match); } } catch (NumberFormatException nfe) { logger.warn("Unable to convert expression " + expression + " to " + propertyClass + ": " + nfe.toString()); } catch (Exception e) { logger.warn("Error filtering on property " + propertyName + ": " + e.toString()); } } else { logger.warn("Expected a payload of javax.jms.Message but instead received " + ClassUtils.getSimpleName(message.getPayload().getClass())); } return false; }
From source file:org.apache.jmeter.save.CSVSaveService.java
/** * Make a SampleResult given a set of tokens * // www . j a va2 s . co m * @param parts * tokens parsed from the input * @param saveConfig * the save configuration (may be updated) * @param lineNumber the line number (for error reporting) * @return the sample result * * @throws JMeterError */ private static SampleEvent makeResultFromDelimitedString(final String[] parts, final SampleSaveConfiguration saveConfig, // may be updated final long lineNumber) { SampleResult result = null; String hostname = "";// $NON-NLS-1$ long timeStamp = 0; long elapsed = 0; String text = null; String field = null; // Save the name for error reporting int i = 0; try { if (saveConfig.saveTimestamp()) { field = TIME_STAMP; text = parts[i++]; if (saveConfig.printMilliseconds()) { try { timeStamp = Long.parseLong(text); // see if this works } catch (NumberFormatException e) { // it did not, let's try some other formats log.warn(e.toString()); boolean foundMatch = false; for (String fmt : DATE_FORMAT_STRINGS) { SimpleDateFormat dateFormat = new SimpleDateFormat(fmt); dateFormat.setLenient(false); try { Date stamp = dateFormat.parse(text); timeStamp = stamp.getTime(); // method is only ever called from one thread at a time // so it's OK to use a static DateFormat log.warn("Setting date format to: " + fmt); saveConfig.setFormatter(dateFormat); foundMatch = true; break; } catch (ParseException e1) { log.info(text + " did not match " + fmt); } } if (!foundMatch) { throw new ParseException("No date-time format found matching " + text, -1); } } } else if (saveConfig.formatter() != null) { Date stamp = saveConfig.formatter().parse(text); timeStamp = stamp.getTime(); } else { // can this happen? final String msg = "Unknown timestamp format"; log.warn(msg); throw new JMeterError(msg); } } if (saveConfig.saveTime()) { field = CSV_ELAPSED; text = parts[i++]; elapsed = Long.parseLong(text); } if (saveConfig.saveSampleCount()) { result = new StatisticalSampleResult(timeStamp, elapsed); } else { result = new SampleResult(timeStamp, elapsed); } if (saveConfig.saveLabel()) { field = LABEL; text = parts[i++]; result.setSampleLabel(text); } if (saveConfig.saveCode()) { field = RESPONSE_CODE; text = parts[i++]; result.setResponseCode(text); } if (saveConfig.saveMessage()) { field = RESPONSE_MESSAGE; text = parts[i++]; result.setResponseMessage(text); } if (saveConfig.saveThreadName()) { field = THREAD_NAME; text = parts[i++]; result.setThreadName(text); } if (saveConfig.saveDataType()) { field = DATA_TYPE; text = parts[i++]; result.setDataType(text); } if (saveConfig.saveSuccess()) { field = SUCCESSFUL; text = parts[i++]; result.setSuccessful(Boolean.valueOf(text).booleanValue()); } if (saveConfig.saveAssertionResultsFailureMessage()) { i++; // TODO - should this be restored? } if (saveConfig.saveBytes()) { field = CSV_BYTES; text = parts[i++]; result.setBytes(Integer.parseInt(text)); } if (saveConfig.saveThreadCounts()) { field = CSV_THREAD_COUNT1; text = parts[i++]; result.setGroupThreads(Integer.parseInt(text)); field = CSV_THREAD_COUNT2; text = parts[i++]; result.setAllThreads(Integer.parseInt(text)); } if (saveConfig.saveUrl()) { i++; // TODO: should this be restored? } if (saveConfig.saveFileName()) { field = CSV_FILENAME; text = parts[i++]; result.setResultFileName(text); } if (saveConfig.saveLatency()) { field = CSV_LATENCY; text = parts[i++]; result.setLatency(Long.parseLong(text)); } if (saveConfig.saveEncoding()) { field = CSV_ENCODING; text = parts[i++]; result.setEncodingAndType(text); } if (saveConfig.saveSampleCount()) { field = CSV_SAMPLE_COUNT; text = parts[i++]; result.setSampleCount(Integer.parseInt(text)); field = CSV_ERROR_COUNT; text = parts[i++]; result.setErrorCount(Integer.parseInt(text)); } if (saveConfig.saveHostname()) { field = CSV_HOSTNAME; hostname = parts[i++]; } if (saveConfig.saveIdleTime()) { field = CSV_IDLETIME; text = parts[i++]; result.setIdleTime(Long.parseLong(text)); } if (saveConfig.saveConnectTime()) { field = CSV_CONNECT_TIME; text = parts[i++]; result.setConnectTime(Long.parseLong(text)); } if (i + saveConfig.getVarCount() < parts.length) { log.warn("Line: " + lineNumber + ". Found " + parts.length + " fields, expected " + i + ". Extra fields have been ignored."); } } catch (NumberFormatException | ParseException e) { log.warn("Error parsing field '" + field + "' at line " + lineNumber + " " + e); throw new JMeterError(e); } catch (ArrayIndexOutOfBoundsException e) { log.warn("Insufficient columns to parse field '" + field + "' at line " + lineNumber); throw new JMeterError(e); } return new SampleEvent(result, "", hostname); }