List of usage examples for java.lang NumberFormatException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.deegree.tools.rendering.manager.ModelGeneralizor.java
private static void startModelGeneralizor(CommandLine line) throws FileNotFoundException, IOException, UnsupportedOperationException, DatasourceException { ModelBackend<?> backend = getModelBackend(line); String type = line.getOptionValue(TYPE); if (!"building".equalsIgnoreCase(type)) { throw new IllegalArgumentException(TYPE + " may only be building."); }/*w ww. ja va 2 s . c o m*/ int targetQL = -1; try { targetQL = Integer.parseInt(line.getOptionValue(TARGET_QL)); // if ( targetQL > 1 || targetQL < 0 ) { // throw new IllegalArgumentException( TARGET_QL + " may only be 0 or 1" ); // } } catch (NumberFormatException e) { throw new IllegalArgumentException( TARGET_QL + " may only be a number 0 or 1: " + e.getLocalizedMessage(), e); } int sourceQL = -1; try { sourceQL = Integer.parseInt(line.getOptionValue(SOURCE_QL)); if (targetQL > 5 || targetQL <= 1) { throw new IllegalArgumentException(SOURCE_QL + " " + sourceQL + " may only be between 2 and 5"); } } catch (NumberFormatException e) { throw new IllegalArgumentException( SOURCE_QL + " may only be a number betwee 2 and 5: " + e.getLocalizedMessage(), e); } double[] translationVector = createTranslationVector(line.getOptionValue(WPVS_TRANSLATION_TO), 2); backend.setWPVSTranslationVector(translationVector); String sqlWhere = line.getOptionValue(SQL_WHERE); long begin = System.currentTimeMillis(); List<Object> buildings = backend.getDeSerializedObjectsForSQL(Type.BUILDING, sqlWhere); if (!buildings.isEmpty()) { WorldObjectSimplifier wos = new WorldObjectSimplifier(); List<DataObjectInfo<WorldRenderableObject>> insert = new ArrayList<DataObjectInfo<WorldRenderableObject>>( buildings.size()); for (Object obj : buildings) { if (obj != null) { if (obj instanceof WorldRenderableObject) { WorldRenderableObject building = (WorldRenderableObject) obj; wos.createSimplified3DObject(building, sourceQL, targetQL); DataObjectInfo<WorldRenderableObject> updated = new DataObjectInfo<WorldRenderableObject>( building.getId(), Type.BUILDING.getModelTypeName(), building.getName(), building.getExternalReference(), building.getBbox(), building); insert.add(updated); } else { System.err.println("retrieved object was not a WorldRenderable object, this is strange."); } } } BackendResult inserted = backend.insert(insert, Type.BUILDING); System.out .println("Result " + inserted + "\ntook: " + (System.currentTimeMillis() - begin) + " millis"); } else { System.err.println("Unable to retrieve buildings for sql statement: " + sqlWhere); } }
From source file:org.deegree.tools.rendering.manager.PrototypeAssigner.java
private static void startManager(CommandLine line) throws FileNotFoundException, IOException, UnsupportedOperationException, DatasourceException { ModelBackend<?> backend = getModelBackend(line); String type = line.getOptionValue(TYPE); if (!"building".equalsIgnoreCase(type)) { throw new IllegalArgumentException(TYPE + " may only be building."); }/*from w ww . ja va 2 s . c o m*/ int qualityLevel = -1; try { qualityLevel = Integer.parseInt(line.getOptionValue(QL)); } catch (NumberFormatException e) { throw new IllegalArgumentException( QL + " may only be a number between 0 and 5: " + e.getLocalizedMessage(), e); } double[] translationVector = createTranslationVector(line.getOptionValue(WPVS_TRANSLATION_TO), 2); backend.setWPVSTranslationVector(translationVector); double[] translation = createTranslationVector(line.getOptionValue(TRANSLATION), 3); translation[0] += translationVector[0]; translation[1] += translationVector[1]; String buildingID = line.getOptionValue(BUILDING_ID); String prototypeID = line.getOptionValue(PROTOTYPE_ID); float width = parseNumber(line, WIDTH); float height = parseNumber(line, HEIGHT); float depth = parseNumber(line, DEPTH); float rotation = parseNumber(line, ROTATION); long begin = System.currentTimeMillis(); WorldRenderableObject building = (WorldRenderableObject) backend.getDeSerializedObjectForUUID(Type.BUILDING, buildingID); if (building != null) { PrototypeReference pr = new PrototypeReference(prototypeID, rotation, new float[] { (float) translation[0], (float) translation[1] }, width, height, depth); RenderableQualityModel modelQL = building.getQualityLevel(qualityLevel); if (modelQL != null) { modelQL.setPrototype(pr); } else { modelQL = new RenderableQualityModel(pr); } building.setQualityLevel(qualityLevel, modelQL); DataObjectInfo<WorldRenderableObject> updated = new DataObjectInfo<WorldRenderableObject>(buildingID, Type.BUILDING.getModelTypeName(), building.getName(), building.getExternalReference(), building.getBbox(), building); List<DataObjectInfo<WorldRenderableObject>> insert = new ArrayList<DataObjectInfo<WorldRenderableObject>>( 1); insert.add(updated); BackendResult inserted = backend.insert(insert, Type.BUILDING); System.out .println("Result " + inserted + "\ntook: " + (System.currentTimeMillis() - begin) + " millis"); } else { System.err.println("Unable to retrieve building with id: " + buildingID); } }
From source file:org.deegree.tools.rendering.manager.ModelGeneralizor.java
/** * @param optionValue/*from w w w .j a v a 2 s .c o m*/ * @return */ private static double[] createTranslationVector(String optionValue, int size) { double[] result = new double[size]; if (optionValue != null && !"".equals(optionValue)) { try { result = ArrayUtils.splitAsDoubles(optionValue, ","); if (result.length != size) { throw new NumberFormatException( "Illigal number of values, only two dimensional translations are allowed"); } } catch (NumberFormatException e) { System.err.println("Translation vector " + optionValue + " could not be read, please make sure it is a comma seperated list of (floating point) numbers: " + e.getLocalizedMessage()); } } return result; }
From source file:org.openestate.io.immoxml.ImmoXmlUtils.java
public static BigInteger parseInteger(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; try {// w w w .j a va2s. co m return DatatypeConverter.parseInteger(value); } catch (NumberFormatException ex) { throw new IllegalArgumentException( "Can't parse integer value '" + value + "'! " + ex.getLocalizedMessage()); } }
From source file:com.jkoolcloud.tnt4j.streams.utils.TimestampFormatter.java
/** * Parses the value into a timestamp with microsecond accuracy based on the specified units. * <p>//from www .j a va 2s . c o m * If {@code value} represents decimal number (as {@link Number} or {@link String}, fraction gets preserved by * scaling down {@code value} in {@code units} until numeric value expression gets with low (epsilon is * {@code 0.001}) or without fraction or {@code units} gets set to {@link TimeUnit#NANOSECONDS}. * * @param units * units that value is in * @param value * value to convert * @return microsecond timestamp * @throws ParseException * if an error parsing the specified value * * @see #scale(double, TimeUnit) */ public static UsecTimestamp parse(TimeUnit units, Object value) throws ParseException { UsecTimestamp ts; try { long time; if (value instanceof Date) { time = ((Date) value).getTime(); units = TimeUnit.MILLISECONDS; } else if (value instanceof Calendar) { time = ((Calendar) value).getTimeInMillis(); units = TimeUnit.MILLISECONDS; } else { if (units == null) { units = TimeUnit.MILLISECONDS; } double dTime = value instanceof Number ? ((Number) value).doubleValue() : Double.parseDouble(value.toString()); Pair<Double, TimeUnit> sTimePair = scale(dTime, units); dTime = sTimePair.getLeft(); units = sTimePair.getRight(); time = (long) dTime; } switch (units) { case NANOSECONDS: long scale = 1000000L; long mSecs = time / scale; long uSecs = (time - mSecs * scale) / 1000L; ts = new UsecTimestamp(mSecs, uSecs); break; case MICROSECONDS: scale = 1000L; mSecs = time / scale; uSecs = time - mSecs * scale; ts = new UsecTimestamp(mSecs, uSecs); break; default: ts = new UsecTimestamp(units.toMicros(time)); break; } } catch (NumberFormatException nfe) { ParseException pe = new ParseException( StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME, "TimestampFormatter.failed.parsing", value, nfe.getLocalizedMessage()), 0); pe.initCause(nfe); throw pe; } return ts; }
From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicGranulesDescriptor.java
/** * This method should implement the COARDS file name recognition and update the * ImageMosaicGranulesDescriptor members * //ww w . j a va 2s.c o m * @param coverageID * @param firstCvNameParts * @param lastCvNameParts * @return */ private static ImageMosaicGranulesDescriptor buildCOARDS(final String storeID, final String coverageID, final List<String[]> fileListNameParts) { // final String[] firstCvNameParts, final String[] lastCvNameParts) { // if (firstCvNameParts != null && firstCvNameParts.length > 3) { if (fileListNameParts != null && fileListNameParts.size() > 0 && fileListNameParts.get(0).length > 3) { final ImageMosaicGranulesDescriptor mosaicDescriptor = new ImageMosaicGranulesDescriptor(storeID, coverageID, fileListNameParts); // TODO: // Temp workaround to leverages on a coverageStoreId having the // same name of the coverage // and the same name of the mosaic folder final String[] firstCvNameParts = fileListNameParts.get(0); final String[] lastCvNameParts = fileListNameParts.get(fileListNameParts.size() - 1); if (firstCvNameParts.length >= 8 && firstCvNameParts.length == lastCvNameParts.length) { try { final StringBuilder fields = new StringBuilder().append(firstCvNameParts[0]).append("_") .append(firstCvNameParts[1]).append("_").append(firstCvNameParts[2]).append("_"); double val = Double.parseDouble(firstCvNameParts[3]); fields.append(val).append("_"); // Min Z mosaicDescriptor.setMinZ(val); val = Double.parseDouble(lastCvNameParts[3]); fields.append(val).append("_"); // Max Z mosaicDescriptor.setMaxZ(val); fields.append(firstCvNameParts[5]).append("_"); // Base Time mosaicDescriptor.setBaseTime(firstCvNameParts[5]); fields.append(lastCvNameParts[6]).append("_"); // Forecast Time mosaicDescriptor.setForecastTime(firstCvNameParts[6]); if (firstCvNameParts.length == 9) { int intVal = Integer.parseInt(firstCvNameParts[7]); fields.append(intVal).append("_"); // TAU mosaicDescriptor.setTAU(intVal); val = Double.parseDouble(firstCvNameParts[8]); fields.append(val); // NoDATA mosaicDescriptor.setNoData(val); } else { // firstCvNameParts.length == 8 val = Double.parseDouble(firstCvNameParts[7]); fields.append(val); // NoDATA mosaicDescriptor.setNoData(val); } mosaicDescriptor.setMetocFields(fields.toString()); return mosaicDescriptor; } catch (NumberFormatException nfe) { // if the string does not contain a parsable float. if (LOGGER.isWarnEnabled()) { LOGGER.warn("Some of the name parts don't contain a parsable number: " + nfe.getLocalizedMessage(), nfe); } } } } return null; }
From source file:org.deegree.tools.rendering.dem.filtering.DEMRasterFilterer.java
private static void startFilterer(CommandLine line) throws IOException, InterruptedException, ParseException { // input options // filter options String t = line.getOptionValue(OPT_KERNEL_SIZE, "11"); int kernelSize = 11; try {//from w w w . j ava 2s . c om Integer.parseInt(t); } catch (NumberFormatException e) { throw new IllegalArgumentException( "The kernel size must be an odd integer: " + e.getLocalizedMessage()); } if (kernelSize % 2 == 0) { throw new IllegalArgumentException("The kernel size must be an odd integer."); } float stdCorr = 1.5f; t = line.getOptionValue(OPT_STANDARD_DEVIATION_CORRECTION, "1.5f"); try { stdCorr = Float.parseFloat(t); } catch (NumberFormatException e) { throw new IllegalArgumentException( "The Standard deviation correction must be a number: " + e.getLocalizedMessage()); } RasterIOOptions options = RasterOptionsParser.parseRasterIOOptions(line); String inputType = options.get(RasterIOOptions.OPT_FORMAT); // output options String outputDirectory = line.getOptionValue(OPT_OUTPUT_DIR); String outputType = line.getOptionValue(OPT_OUTPUT_TYPE, inputType); String cacheDir = options.get(RasterIOOptions.RASTER_CACHE_DIR); AbstractCoverage raster = RasterOptionsParser.loadCoverage(line, options); if (!(raster instanceof AbstractRaster)) { throw new IllegalArgumentException( "Given raster location holds a multiresolution raster, filtering a multi resolution raster is not supported."); } DEMRasterFilterer filter = new DEMRasterFilterer((AbstractRaster) raster, kernelSize, stdCorr, cacheDir, outputDirectory, outputType); filter.applyFilter(); }
From source file:org.deegree.tools.rendering.manager.DataManager.java
/** * @param optionValue//from w w w.java 2 s . c o m * @return */ private static double[] createTranslationVector(String optionValue) { double[] result = new double[2]; if (optionValue != null && !"".equals(optionValue)) { try { result = ArrayUtils.splitAsDoubles(optionValue, ","); if (result.length != 2) { throw new NumberFormatException( "Illigal number of values, only two dimensional translations are allowed"); } } catch (NumberFormatException e) { System.err.println("Translation vector " + optionValue + " could not be read, please make sure it is a comma seperated list of (floating point) numbers: " + e.getLocalizedMessage()); } } return result; }
From source file:org.opennms.netmgt.config.SnmpEventInfo.java
private static int computeIntValue(String parmContent) throws IllegalArgumentException { int val = 0; try {/*www . j a v a 2 s. co m*/ val = Integer.parseInt(parmContent); } catch (NumberFormatException e) { LOG.error("computeIntValue: parm value passed in the event isn't a valid number.", e); throw new IllegalArgumentException(e.getLocalizedMessage()); } return val; }
From source file:ch.elexis.data.Prescription.java
private static float getNum(String num) { try {//from w w w. j a v a2 s.com String n = num.trim(); if (n.matches(special_num_at_start)) { float value = getNum(n.substring(0, 1)) / getNum(n.substring(2)); return value; } else if (n.equalsIgnoreCase("")) return 0.5F; else if (n.equalsIgnoreCase("")) return 0.25F; else if (n.equalsIgnoreCase("1")) return 1.5F; else if (n.indexOf('/') != -1) { if (n.length() == 1) { return 0.0f; } String[] bruch = n.split(StringConstants.SLASH); if (bruch.length < 2) { return 0.0f; } float zaehler = Float.parseFloat(bruch[0]); float nenner = Float.parseFloat(bruch[1]); if (nenner == 0.0f) { return 0.0f; } return zaehler / nenner; } // matching for values like 2x1, 2,5x1 or 20x1 else if (n.toLowerCase().matches("^[0-9][,.]*[0-9]*x[0-9][,.]*[0-9]*$")) { n = n.replace("\\s", ""); String[] nums = n.toLowerCase().split("x"); float num1 = Float.parseFloat(nums[0].replace(",", ".")); float num2 = Float.parseFloat(nums[1].replace(",", ".")); return num1 * num2; } // matching numbers with comma i.e. 1,5 and parses it to 1.5 for float value else if (n.matches("^[0-9,]")) { n = n.replace(",", "."); return Float.parseFloat(n); } // any other digit-letter combination. replaces comma with dot and removes all non-digit chars. i.e. 1,5 p. Day becomes 1.5 else { n = n.replace(",", "."); n = n.replaceAll("[^\\d.]", ""); if (n.endsWith(".")) { n = n.substring(0, n.length() - 1); } if (n.isEmpty()) { return 0.0f; } return Float.parseFloat(n); } } catch (NumberFormatException e) { ElexisStatus status = new ElexisStatus(ElexisStatus.INFO, CoreHub.PLUGIN_ID, ElexisStatus.CODE_NONE, e.getLocalizedMessage(), e); ElexisEventDispatcher.fireElexisStatusEvent(status); return 0.0F; } }