List of usage examples for java.lang NumberFormatException getMessage
public String getMessage()
From source file:gdsc.smlm.ij.plugins.PeakFit.java
/** * Show a dialog to configure the fit solver. The updated settings are saved to the settings file. An error * message is shown if the dialog is cancelled or the configuration is invalid. * /*from ww w. j a v a2 s .c o m*/ * @param settings * @param filename * @param extraOptions * True if extra configuration options should be allowed * @return True if the configuration succeeded */ public static boolean configureFitSolver(GlobalSettings settings, String filename, boolean extraOptions) { FitConfiguration fitConfig = settings.getFitEngineConfiguration().getFitConfiguration(); Calibration calibration = settings.getCalibration(); if (fitConfig.getFitSolver() == FitSolver.MLE) { GenericDialog gd = new GenericDialog(TITLE); gd.addMessage("Maximum Likelihood Estimation requires additional parameters"); gd.addNumericField("Camera_bias (ADUs)", calibration.bias, 2); gd.addCheckbox("Model_camera_noise", fitConfig.isModelCamera()); gd.addNumericField("Read_noise (ADUs)", calibration.readNoise, 2); gd.addNumericField("Gain (ADU/photon)", calibration.gain, 2); gd.addCheckbox("EM-CCD", calibration.emCCD); String[] searchNames = SettingsManager .getNames((Object[]) MaximumLikelihoodFitter.SearchMethod.values()); gd.addChoice("Search_method", searchNames, searchNames[fitConfig.getSearchMethod().ordinal()]); gd.addStringField("Relative_threshold", "" + fitConfig.getRelativeThreshold()); gd.addStringField("Absolute_threshold", "" + fitConfig.getAbsoluteThreshold()); gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0); gd.addNumericField("Max_function_evaluations", fitConfig.getMaxFunctionEvaluations(), 0); if (extraOptions) gd.addCheckbox("Gradient_line_minimisation", fitConfig.isGradientLineMinimisation()); gd.showDialog(); if (gd.wasCanceled()) return false; calibration.bias = Math.abs(gd.getNextNumber()); fitConfig.setModelCamera(gd.getNextBoolean()); calibration.readNoise = Math.abs(gd.getNextNumber()); calibration.gain = Math.abs(gd.getNextNumber()); calibration.emCCD = gd.getNextBoolean(); fitConfig.setBias(calibration.bias); fitConfig.setReadNoise(calibration.readNoise); fitConfig.setGain(calibration.gain); fitConfig.setEmCCD(calibration.emCCD); fitConfig.setSearchMethod(gd.getNextChoiceIndex()); try { fitConfig.setRelativeThreshold(Math.abs(Double.parseDouble(gd.getNextString()))); fitConfig.setAbsoluteThreshold(Math.abs(Double.parseDouble(gd.getNextString()))); } catch (NumberFormatException e) { fitConfig.setRelativeThreshold(0); fitConfig.setAbsoluteThreshold(0); } fitConfig.setMaxIterations((int) gd.getNextNumber()); fitConfig.setMaxFunctionEvaluations((int) gd.getNextNumber()); if (extraOptions) fitConfig.setGradientLineMinimisation(gd.getNextBoolean()); else // This option is for the Conjugate Gradient optimiser and makes it less stable fitConfig.setGradientLineMinimisation(false); if (filename != null) SettingsManager.saveSettings(settings, filename); try { Parameters.isAboveZero("Relative threshold", fitConfig.getRelativeThreshold()); Parameters.isAboveZero("Absolute threshold", fitConfig.getAbsoluteThreshold()); Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations()); Parameters.isAboveZero("Max function evaluations", fitConfig.getMaxFunctionEvaluations()); fitConfig.getFunctionSolver(); } catch (IllegalArgumentException e) { IJ.error(TITLE, e.getMessage()); return false; } } else if (fitConfig.getFitSolver() == FitSolver.LVM || fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) { // Collect options for LVM fitting GenericDialog gd = new GenericDialog(TITLE); gd.addMessage("LVM requires additional parameters"); String[] criteriaNames = SettingsManager.getNames((Object[]) FitCriteria.values()); gd.addChoice("Fit_criteria", criteriaNames, criteriaNames[fitConfig.getFitCriteria().ordinal()]); gd.addNumericField("Significant_digits", fitConfig.getSignificantDigits(), 0); gd.addNumericField("Coord_delta", fitConfig.getDelta(), 4); gd.addNumericField("Lambda", fitConfig.getLambda(), 4); if (extraOptions) gd.addNumericField("Min_iterations", fitConfig.getMinIterations(), 0); gd.addNumericField("Max_iterations", fitConfig.getMaxIterations(), 0); // Extra parameters are needed for the weighted LVM if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) { gd.addMessage("Weighted LVM fitting requires a CCD camera noise model"); gd.addNumericField("Read_noise (ADUs)", calibration.readNoise, 2); gd.addNumericField("Camera_bias (ADUs)", calibration.bias, 2); } gd.showDialog(); if (gd.wasCanceled()) return false; fitConfig.setFitCriteria(gd.getNextChoiceIndex()); fitConfig.setSignificantDigits((int) gd.getNextNumber()); fitConfig.setDelta(gd.getNextNumber()); fitConfig.setLambda(gd.getNextNumber()); if (extraOptions) fitConfig.setMinIterations((int) gd.getNextNumber()); fitConfig.setMaxIterations((int) gd.getNextNumber()); if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) { calibration.readNoise = Math.abs(gd.getNextNumber()); calibration.bias = Math.abs(gd.getNextNumber()); fitConfig.setNoiseModel(CameraNoiseModel.createNoiseModel(calibration.readNoise, calibration.bias, calibration.emCCD)); } if (filename != null) SettingsManager.saveSettings(settings, filename); try { Parameters.isAboveZero("Significant digits", fitConfig.getSignificantDigits()); Parameters.isAboveZero("Delta", fitConfig.getDelta()); Parameters.isAboveZero("Lambda", fitConfig.getLambda()); Parameters.isAboveZero("Max iterations", fitConfig.getMaxIterations()); } catch (IllegalArgumentException e) { IJ.error(TITLE, e.getMessage()); return false; } } else if (fitConfig.getFitSolver() == FitSolver.LVM_QUASI_NEWTON) { // No options yet for Apache LVM fitting. Save options for consistency if (filename != null) SettingsManager.saveSettings(settings, filename); } return true; }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
public static void mergeBatchClassFieldFromDTO(BatchClassField batchClassField, BatchClassFieldDTO batchClassFieldDTO) { batchClassField.setDataType(batchClassFieldDTO.getDataType()); batchClassField.setIdentifier(batchClassFieldDTO.getIdentifier()); batchClassField.setName(batchClassFieldDTO.getName()); try {/*from w w w . j a v a 2 s . co m*/ int fieldOrderNumber = Integer.parseInt(batchClassFieldDTO.getFieldOrderNumber()); batchClassField.setFieldOrderNumber(fieldOrderNumber); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } batchClassField.setDescription(batchClassFieldDTO.getDescription()); batchClassField.setValidationPattern(batchClassFieldDTO.getValidationPattern()); batchClassField.setSampleValue(batchClassFieldDTO.getSampleValue()); batchClassField.setFieldOptionValueList(batchClassFieldDTO.getFieldOptionValueList()); }
From source file:gsn.wrappers.general.CSVHandler.java
public TreeMap<String, Serializable> convertTo(String[] formats, String[] fields, String nullValues[], String[] values, char separator) { TreeMap<String, Serializable> streamElement = new TreeMap<String, Serializable>( new CaseInsensitiveComparator()); for (String field : fields) streamElement.put(field, null);/* w w w . j a v a 2s . c om*/ HashMap<String, String> timeStampFormats = new HashMap<String, String>(); for (int i = 0; i < Math.min(fields.length, values.length); i++) { if (isNull(nullValues, values[i])) { continue; } else if (formats[i].equalsIgnoreCase("numeric")) { try { streamElement.put(fields[i], Double.parseDouble(values[i])); } catch (java.lang.NumberFormatException e) { logger.error("Parsing to Numeric failed: Value to parse=" + values[i]); throw e; } } else if (formats[i].equalsIgnoreCase("string")) { streamElement.put(fields[i], values[i]); } else if (formats[i].equalsIgnoreCase("bigint")) { try { streamElement.put(fields[i], Long.parseLong(values[i])); } catch (java.lang.NumberFormatException e) { logger.error("Parsing to BigInt failed: Value to parse=" + values[i]); throw e; } } else if (isTimeStampFormat(formats[i])) { String value = ""; String format = ""; if (streamElement.get(fields[i]) != null) { value = (String) streamElement.get(fields[i]); format = timeStampFormats.get(fields[i]); value += separator; format += separator; } if (isTimeStampLeftPaddedFormat(formats[i])) values[i] = StringUtils.leftPad(values[i], getTimeStampFormat(formats[i]).length(), '0'); value += values[i]; format += getTimeStampFormat(formats[i]); streamElement.put(fields[i], value); timeStampFormats.put(fields[i], format); } } for (String timeField : timeStampFormats.keySet()) { String timeFormat = timeStampFormats.get(timeField); String timeValue = (String) streamElement.get(timeField); try { DateTime x = DateTimeFormat.forPattern(timeFormat).withZone(getTimeZone()).parseDateTime(timeValue); streamElement.put(timeField, x.getMillis()); } catch (IllegalArgumentException e) { logger.error("Parsing error: TimeFormat=" + timeFormat + " , TimeValue=" + timeValue); logger.error(e.getMessage(), e); throw e; } } return streamElement; }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
/** * @param batchClassPluginConfig//from w w w .ja v a 2 s .c o m * @return */ private static PluginConfig mergePluginConfiguration(BatchClassPluginConfigDTO batchClassPluginConfigDTO) { PluginConfig pluginConfig = new PluginConfig(); PluginConfigurationDTO pluginConfigDTO = batchClassPluginConfigDTO.getPluginConfig(); if (pluginConfigDTO != null) { pluginConfig.setName(pluginConfigDTO.getFieldName()); try { long pluginConfigDtoId = Long.valueOf(pluginConfigDTO.getIdentifier()); pluginConfig.setId(pluginConfigDtoId); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } } return pluginConfig; }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
private static void mergeDependencyFromDTO(Dependency dependency, DependencyDTO dependencyDTO, PluginService pluginService) {// w w w . j av a2 s .co m if (dependency != null) { try { long dependencyId = Long.valueOf(dependencyDTO.getIdentifier()); dependency.setId(dependencyId); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } dependency.setDependencyType(getDependencyTypePropertyFromValue(dependencyDTO.getDependencyType())); if (!dependencyDTO.getDependencyType().equals(DependencyTypeProperty.UNIQUE.getProperty())) { dependency.setDependencies( changeDependenciesNameToIdentifier(dependencyDTO.getDependencies(), pluginService)); } else { dependency.setDependencies(BatchConstants.EMPTY_STRING); } } }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
private static String changeDependenciesIdentifierToName(String dependencyNames, PluginService pluginService) { String[] andDependencies = dependencyNames.split(BatchConstants.CONDITION_AND); StringBuffer andDependenciesNameAsString = new StringBuffer(); for (String andDependency : andDependencies) { if (!andDependenciesNameAsString.toString().isEmpty()) { andDependenciesNameAsString.append(BatchConstants.CONDITION_AND); }//from w w w. j a v a 2 s.c o m String[] orDependencies = andDependency.split(BatchConstants.CONDITION_OR); StringBuffer orDependenciesNameAsString = new StringBuffer(); for (String dependencyIdentifier : orDependencies) { try { long dependencyId = Long.valueOf(dependencyIdentifier); final Plugin plugin = pluginService.getPluginPropertiesForPluginId(dependencyId); if (plugin != null) { if (!orDependenciesNameAsString.toString().isEmpty()) { orDependenciesNameAsString.append(BatchConstants.CONDITION_OR); } orDependenciesNameAsString.append(plugin.getPluginName()); } } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } } andDependenciesNameAsString.append(orDependenciesNameAsString); orDependenciesNameAsString = new StringBuffer(); } return andDependenciesNameAsString.toString(); }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
public static void mergePluginFromDTO(Plugin plugin, PluginDetailsDTO pluginDetailsDTO, PluginService pluginService) {/*from ww w .j a v a 2s. co m*/ // plugin.setDescription(pluginDetailsDTO.getPluginDescription()); List<Dependency> dependenciesList = plugin.getDependencies(); if (dependenciesList == null) { dependenciesList = new ArrayList<Dependency>(); } List<DependencyDTO> removedDependencyDTOs = null; for (DependencyDTO dependencyDTO : pluginDetailsDTO.getDependencies()) { if (dependencyDTO.isNew() && !dependencyDTO.isDeleted()) { Dependency dependency = new Dependency(); mergeDependencyFromDTO(dependency, dependencyDTO, pluginService); dependency.setPlugin(plugin); dependenciesList.add(dependency); } else { if (dependencyDTO.isDeleted()) { if (dependencyDTO.isNew()) { if (removedDependencyDTOs == null) { removedDependencyDTOs = new ArrayList<DependencyDTO>(); } removedDependencyDTOs.add(dependencyDTO); } else { long dependencyIdentifier = Long.valueOf(dependencyDTO.getIdentifier()); Dependency dependency = plugin.getDependencyById(dependencyIdentifier); plugin.getDependencies().remove(dependency); dependency.setPlugin(null); } } else if (dependencyDTO.isDirty()) { try { long dependencyId = Long.valueOf(dependencyDTO.getIdentifier()); Dependency dependency = plugin.getDependencyById(dependencyId); mergeDependencyFromDTO(dependency, dependencyDTO, pluginService); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } } } } if (removedDependencyDTOs != null) { pluginDetailsDTO.getDependencies().removeAll(removedDependencyDTOs); } plugin.setDependencies(dependenciesList); }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
public static void setBatchClassModuleDTOPluginConfigList(BatchClassPlugin batchClassPlugin, BatchClassPluginDTO batchClassPluginDTO, BatchClassPluginConfigService batchClassPluginConfigService, BatchClassPluginService batchClassPluginService, PluginConfigService pluginConfigService) { long batchClassPluginId = -1; LOGGER.info("Getting list of batch class plugins in the batch class module DTO"); if (batchClassPluginDTO.isNew()) { String pluginIdentifier = batchClassPluginDTO.getPlugin().getIdentifier(); List<BatchClassPluginConfig> batchClassPluginConfigsList = new ArrayList<BatchClassPluginConfig>(0); try {/*from w w w.j a v a2s. c o m*/ Long pluginId = Long.valueOf(pluginIdentifier); List<BatchClassPlugin> batchClassPlugins = batchClassPluginService .getBatchClassPluginForPluginId(pluginId); for (BatchClassPlugin batchClassPluginTemp : batchClassPlugins) { if (batchClassPluginTemp.getPlugin().getPluginName() .equals(batchClassPluginDTO.getPlugin().getPluginName())) { batchClassPluginId = batchClassPluginTemp.getId(); break; } } } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } if (batchClassPluginId != -1) { batchClassPluginConfigsList = batchClassPluginConfigService .getPluginConfigurationForPluginId(batchClassPluginId); if (batchClassPluginConfigsList != null) { for (BatchClassPluginConfig batchClassPluginConfig : batchClassPluginConfigsList) { if (batchClassPlugin .getBatchClassPluginConfigByName(batchClassPluginConfig.getName()) == null) { batchClassPluginConfigService.evict(batchClassPluginConfig); BatchClassPluginConfig newBatchClassPluginConfig = getNewBatchClassPluginConfig( batchClassPluginConfig); batchClassPlugin.addBatchClassPluginConfig(newBatchClassPluginConfig); } } } } List<PluginConfig> pluginConfigs = pluginConfigService.getPluginConfigForPluginId(pluginIdentifier); if (pluginConfigs != null && !pluginConfigs.isEmpty()) { for (PluginConfig pluginConfig : pluginConfigs) { if (batchClassPlugin.getBatchClassPluginConfigByName(pluginConfig.getName()) == null) { BatchClassPluginConfig batchClassPluginConfig = new BatchClassPluginConfig(); batchClassPluginConfig.setPluginConfig(pluginConfig); batchClassPluginConfig.setId(0); setDefaultValueForNewConfig(batchClassPluginConfig); batchClassPluginConfig.setDescription(pluginConfig.getDescription()); batchClassPluginConfig.setName(pluginConfig.getName()); batchClassPlugin.addBatchClassPluginConfig(batchClassPluginConfig); } } } } }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
public static void mergeFieldTypeKVExtractionFromDTO(KVExtraction kvExtraction, KVExtractionDTO kvExtractionDTO) { kvExtraction.setLocationType(kvExtractionDTO.getLocationType()); kvExtraction.setKeyPattern(kvExtractionDTO.getKeyPattern()); kvExtraction.setValuePattern(kvExtractionDTO.getValuePattern()); kvExtraction.setNoOfWords(kvExtractionDTO.getNoOfWords()); kvExtraction.setLength(kvExtractionDTO.getLength()); kvExtraction.setWidth(kvExtractionDTO.getWidth()); kvExtraction.setXoffset(kvExtractionDTO.getXoffset()); kvExtraction.setYoffset(kvExtractionDTO.getYoffset()); kvExtraction.setFetchValue(kvExtractionDTO.getFetchValue()); kvExtraction.setPageValue(kvExtractionDTO.getKvPageValue()); kvExtraction.setUseExistingKey(kvExtractionDTO.isUseExistingKey()); kvExtraction.setOrderNo(Integer.parseInt(kvExtractionDTO.getOrderNumber())); // Sets extract zone of KVExtraction from its DTO. kvExtraction.setExtractZone(kvExtractionDTO.getExtractZone()); try {//from ww w. jav a 2 s . co m int orderNumber = Integer.parseInt(kvExtractionDTO.getOrderNumber()); kvExtraction.setOrderNo(orderNumber); } catch (NumberFormatException numberFormatException) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + numberFormatException.getMessage()); } // Adding weight value of KV extraction Float weight = kvExtractionDTO.getWeight(); if (null != weight) { kvExtraction.setWeight(weight); } else { kvExtraction.setWeight(CoreCommonConstants.DEFAULT_WEIGHT); } // Setting the fuzzy match threshold value for key pattern. kvExtraction.setKeyFuzziness(kvExtractionDTO.getKeyFuzziness()); AdvancedKVExtractionDTO advancedKVExtractionDTO = kvExtractionDTO.getAdvancedKVExtractionDTO(); if (null != advancedKVExtractionDTO // && advancedKVExtractionDTO.getDisplayImageName() != null /* && !advancedKVExtractionDTO.getDisplayImageName().isEmpty() */) { AdvancedKVExtraction advancedKVExtraction = kvExtraction.getAdvancedKVExtraction(); if (null == advancedKVExtraction) { advancedKVExtraction = new AdvancedKVExtraction(); kvExtraction.setAdvancedKVExtraction(advancedKVExtraction); } mergeAdvancedKVExtractionFromDTO(advancedKVExtraction, advancedKVExtractionDTO); } }
From source file:com.ephesoft.dcma.gwt.core.server.BatchClassUtil.java
public static void mergeDocumentTypeFieldFromDTO(FieldType fieldType, FieldTypeDTO fieldTypeDTO) { // merge the field types edited by user. fieldType.setName(fieldTypeDTO.getName()); fieldType.setDescription(fieldTypeDTO.getDescription()); fieldType.setDataType(fieldTypeDTO.getDataType()); fieldType.setPattern(fieldTypeDTO.getPattern()); fieldType.setRegexListingSeparator(fieldTypeDTO.getRegexListingSeparator()); fieldType.setSampleValue(fieldTypeDTO.getSampleValue()); fieldType.setFieldOrderNumber(Integer.parseInt(fieldTypeDTO.getFieldOrderNumber())); fieldType.setBarcodeType(fieldTypeDTO.getBarcodeType()); fieldType.setHidden(fieldTypeDTO.isHidden()); // fieldType.setMultiLine(fieldTypeDTO.isMultiLine()); fieldType.setReadOnly(fieldTypeDTO.getIsReadOnly()); fieldType.setOcrConfidenceThreshold(fieldTypeDTO.getOcrConfidenceThreshold()); fieldType.setFieldValueChangeScriptEnabled(fieldTypeDTO.isFieldValueChangeScriptEnabled()); fieldType.setFieldOptionValueList(fieldTypeDTO.getFieldOptionValueList()); if (fieldTypeDTO.getKvExtractionList(true) != null) { for (KVExtractionDTO kvExtractionDTO : fieldTypeDTO.getKvExtractionList(true)) { if (kvExtractionDTO.isDeleted()) { try { Long kvExtractionId = Long.parseLong(kvExtractionDTO.getIdentifier()); fieldType.removeKvExtractionById(kvExtractionId); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); }/*from w w w . j a v a 2s .c o m*/ } else if (kvExtractionDTO.isNew()) { KVExtraction kvExtraction = new KVExtraction(); kvExtractionDTO.setNew(false); mergeFieldTypeKVExtractionFromDTO(kvExtraction, kvExtractionDTO); fieldType.addKVExtraction(kvExtraction); } else { KVExtraction kvExtraction = fieldType .getKVExtractionbyIdentifier(kvExtractionDTO.getIdentifier()); mergeFieldTypeKVExtractionFromDTO(kvExtraction, kvExtractionDTO); } } } if (fieldTypeDTO.getRegexList(true) != null) { for (RegexDTO regexDTO : fieldTypeDTO.getRegexList(true)) { if (regexDTO.isDeleted()) { try { Long regexValidationId = Long.parseLong(regexDTO.getIdentifier()); fieldType.removeRegexValidationById(regexValidationId); } catch (NumberFormatException e) { LOGGER.error(BatchConstants.ERROR_CONVERT_NUMBER + e.getMessage()); } } else if (regexDTO.isNew()) { RegexValidation regexValidation = new RegexValidation(); regexDTO.setNew(false); regexValidation.setPattern(regexDTO.getPattern()); fieldType.addRegexValidation(regexValidation); } else { RegexValidation regexValidation = fieldType .getRegexValidationbyIdentifier(regexDTO.getIdentifier()); regexValidation.setPattern(regexDTO.getPattern()); } } } }