List of usage examples for java.lang Float parseFloat
public static float parseFloat(String s) throws NumberFormatException
From source file:alba.solr.docvalues.DynamicDocValuesHelper.java
public Object eval(int doc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { // TODO Auto-generated method stub /*if (doc < 0 || doc > this.readerContext.reader().maxDoc()) { return null;// w ww. ja v a2 s . c o m }*/ Map<String, Object> params = new HashMap<String, Object>(); for (String s : args.keySet()) { if (args.get(s).startsWith("\"")) { params.put(s, args.get(s)); } else if (NumberUtils.isNumber(args.get(s))) { Object objVal; try { objVal = Long.parseLong(args.get(s)); } catch (NumberFormatException nfe1) { try { objVal = Float.parseFloat(args.get(s)); } catch (NumberFormatException nfe2) { objVal = s; } } if (objVal != null) { params.put(s, objVal); } else { params.put(s, "N/A"); } } else if ("false".equals(args.get(s).toLowerCase())) { params.put(s, false); } else if ("true".equals(args.get(s).toLowerCase())) { params.put(s, true); } else { SchemaField f = fp.getReq().getSchema().getField(args.get(s)); ValueSource vs = f.getType().getValueSource(f, fp); Object objVal = null; try { objVal = vs.getValues(this.context, this.readerContext).longVal(doc); params.put(s, objVal); } catch (IOException | UnsupportedOperationException e) { // TODO Auto-generated catch block // TODO Log properly try { objVal = vs.getValues(this.context, this.readerContext).floatVal(doc); } catch (IOException | UnsupportedOperationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); try { objVal = vs.getValues(this.context, this.readerContext).strVal(doc); } catch (IOException | UnsupportedOperationException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } } logger.error("error converting values ", e); } if (objVal != null) { params.put(s, objVal); } else { params.put(s, "N/A"); } } } CallableFunction cf = functions.get(this.functionName); if (cf == null) { logger.error("unable to get function " + this.functionName); } if (cf != null) { List<Object> fnParams = new ArrayList<Object>(); Parameter[] methodParameters = cf.getMethod().getParameters(); //TODO spostare quanto pi codice possibile in fase di inizializzazione for (Parameter p : methodParameters) { if (p.isAnnotationPresent(Param.class)) { Param paramAnnotation = p.getAnnotation(Param.class); fnParams.add(params.get(paramAnnotation.name())); } } return cf.getMethod().invoke(cf.getInstance(), fnParams.toArray()); } else { return null; } }
From source file:blue.components.lines.Line.java
public static Line loadFromXML(Element data) { Line line = new Line(false, false); if (data.getName().equals("line")) { line.varName = data.getAttributeValue("name"); line.setZak(false);//from w ww. j av a 2s . c o m } else if (data.getName().equals("zakline")) { line.channel = Integer.parseInt(data.getAttributeValue("channel")); line.setZak(true); } int version = 1; String versionStr = data.getAttributeValue("version"); if (versionStr != null) { version = Integer.parseInt(versionStr); } line.max = Float.parseFloat(data.getAttributeValue("max")); line.min = Float.parseFloat(data.getAttributeValue("min")); if (data.getAttributeValue("resolution") != null) { line.resolution = Float.parseFloat(data.getAttributeValue("resolution")); } String colorStr = data.getAttributeValue("color"); if (colorStr != null && colorStr.length() > 0) { line.color = new Color(Integer.parseInt(colorStr)); } else { // some older project files may not have a color associated with // their Line objects. However, a color IS required in the // LineCanvas // implementation, so we makeup a color. line.color = new Color(128, 128, 128); } String rBound = data.getAttributeValue("rightBound"); if (rBound != null && rBound.length() > 0) { line.rightBound = Boolean.valueOf(rBound).booleanValue(); } String endLinked = data.getAttributeValue("endPointsLinked"); if (endLinked != null && endLinked.length() > 0) { line.endPointsLinked = Boolean.valueOf(endLinked).booleanValue(); } Elements nodes = data.getElements(); while (nodes.hasMoreElements()) { Element node = nodes.next(); LinePoint lp = LinePoint.loadFromXML(node); line.addLinePoint(lp); if (version == 1) { lp.setLocation(lp.getX(), migrateYValue(lp.getY(), line.max, line.min)); } } return line; }
From source file:edu.snu.leader.hidden.builder.PersonalityDistributionIndividualBuilder.java
/** * Initializes the builder//w ww . j av a 2 s . c o m * * @param simState The simulation's state * @see edu.snu.leader.hidden.builder.AbstractIndividualBuilder#initialize(edu.snu.leader.hidden.SimulationState) */ @Override public void initialize(SimulationState simState) { _LOG.trace("Entering initialize( simState )"); // Call the superclass implementation super.initialize(simState); // Get the properties Properties props = simState.getProps(); // Get the mean personality value String personalityMeanStr = props.getProperty(_PERSONALITY_MEAN_KEY); Validate.notEmpty(personalityMeanStr, "Personality mean (key=" + _PERSONALITY_MEAN_KEY + ") may not be empty"); _personalityMean = Float.parseFloat(personalityMeanStr); _LOG.info("Using _personalityMean=[" + _personalityMean + "]"); // Get the personality value standard deviation String personalityStdDevStr = props.getProperty(_PERSONALITY_STD_DEV_KEY); Validate.notEmpty(personalityStdDevStr, "Personality std dev (key=" + _PERSONALITY_STD_DEV_KEY + ") may not be empty"); _personalityStdDev = Float.parseFloat(personalityStdDevStr); _LOG.info("Using _personalityStdDev=[" + _personalityStdDev + "]"); // Get the min personality String minPersonalityStr = props.getProperty(_MIN_PERSONALITY_KEY); Validate.notEmpty(minPersonalityStr, "Minimum personality value (key=" + _MIN_PERSONALITY_KEY + ") may not be empty"); _minPersonality = Float.parseFloat(minPersonalityStr); _LOG.info("Using _minPersonality=[" + _minPersonality + "]"); // Get the max personality String maxPersonalityStr = props.getProperty(_MAX_PERSONALITY_KEY); Validate.notEmpty(maxPersonalityStr, "Maximum personality value (key=" + _MAX_PERSONALITY_KEY + ") may not be empty"); _maxPersonality = Float.parseFloat(maxPersonalityStr); _LOG.info("Using _maxPersonality=[" + _maxPersonality + "]"); // Get the random number distribution String rnDistStr = props.getProperty(_RNG_DIST_KEY); Validate.notEmpty(rnDistStr, "Random number distribution (key=" + _RNG_DIST_KEY + ") may not be empty"); _rnDist = RNDistribution.valueOf(rnDistStr.toUpperCase()); _LOG.info("Using _rnDist=[" + _rnDist + "]"); _LOG.trace("Leaving initialize( simState )"); }
From source file:edu.snu.leader.hidden.builder.PersonalityDistributionAndDirIndividualBuilder.java
/** * Initializes the builder//from www .j ava2s . c om * * @param simState The simulation's state * @see edu.snu.leader.hidden.builder.AbstractIndividualBuilder#initialize(edu.snu.leader.hidden.SimulationState) */ @Override public void initialize(SimulationState simState) { // Call the superclass implementation super.initialize(simState); // Get the properties Properties props = simState.getProps(); // Get the mean direction value String directionMeanStr = props.getProperty(_DIR_MEAN_KEY); Validate.notEmpty(directionMeanStr, "Direction mean (key=" + _DIR_MEAN_KEY + ") may not be empty"); _directionMean = Float.parseFloat(directionMeanStr); _LOG.info("Using _directionMean=[" + _directionMean + "]"); // Get the value standard deviation String directionStdDevStr = props.getProperty(_DIR_STD_DEV_KEY); Validate.notEmpty(directionStdDevStr, "Direction std dev (key=" + _DIR_STD_DEV_KEY + ") may not be empty"); _directionStdDev = Float.parseFloat(directionStdDevStr); _LOG.info("Using _directionStdDev=[" + _directionStdDev + "]"); // Get the min direction String minDirectionStr = props.getProperty(_MIN_DIR_KEY); Validate.notEmpty(minDirectionStr, "Minimum Direction (key=" + _MIN_DIR_KEY + ") may not be empty"); _minDirection = Float.parseFloat(minDirectionStr); _LOG.info("Using _minDirection=[" + _minDirection + "]"); // Get the max direction String maxDirectionStr = props.getProperty(_MAX_DIR_KEY); Validate.notEmpty(maxDirectionStr, "Maximum direction (key=" + _MAX_DIR_KEY + ") may not be empty"); _maxDirection = Float.parseFloat(maxDirectionStr); _LOG.info("Using _maxDirection=[" + _maxDirection + "]"); // Get the direction delta value String dirDeltaStr = props.getProperty(_DIR_DELTA_KEY); Validate.notEmpty(dirDeltaStr, "Direction delta (key=" + _DIR_DELTA_KEY + ") may not be empty"); _dirDelta = Float.parseFloat(dirDeltaStr); _LOG.info("Using _dirDelta=[" + _dirDelta + "]"); // Get the positive delta probability String posDeltaProbabilityStr = props.getProperty(_POS_DELTA_PROB_KEY); Validate.notEmpty(posDeltaProbabilityStr, "Positive delta percentage (key=" + _POS_DELTA_PROB_KEY + ") may not be empty"); _positiveDeltaProbability = Float.parseFloat(posDeltaProbabilityStr); _LOG.info("Using _positiveDeltaProbability=[" + _positiveDeltaProbability + "]"); }
From source file:com.haulmont.cuba.gui.xml.layout.loaders.GridLayoutLoader.java
@Override public void createComponent() { resultComponent = (GridLayout) factory.createComponent(GridLayout.NAME); loadId(resultComponent, element);/*from w w w .j a v a2 s . co m*/ Element columnsElement = element.element("columns"); if (columnsElement == null) { throw new GuiDevelopmentException("'grid' element must contain 'columns' element", context.getFullFrameId(), "Grid ID", resultComponent.getId()); } Element rowsElement = element.element("rows"); if (rowsElement == null) { throw new GuiDevelopmentException("'grid' element must contain 'rows' element", context.getFullFrameId(), "Grid ID", resultComponent.getId()); } int columnCount; @SuppressWarnings("unchecked") final List<Element> columnElements = columnsElement.elements("column"); if (columnElements.size() == 0) { try { columnCount = Integer.parseInt(columnsElement.attributeValue("count")); } catch (NumberFormatException e) { throw new GuiDevelopmentException( "'grid' element must contain either a set of 'column' elements or a 'count' attribute", context.getFullFrameId(), "Grid ID", resultComponent.getId()); } resultComponent.setColumns(columnCount); for (int i = 0; i < columnCount; i++) { resultComponent.setColumnExpandRatio(i, 1); } } else { String countAttr = columnsElement.attributeValue("count"); if (StringUtils.isNotEmpty(countAttr)) { throw new GuiDevelopmentException( "'grid' element can't contain a set of 'column' elements and a 'count' attribute", context.getFullFrameId(), "Grid ID", resultComponent.getId()); } columnCount = columnElements.size(); resultComponent.setColumns(columnCount); int i = 0; for (Element columnElement : columnElements) { String flex = columnElement.attributeValue("flex"); if (!StringUtils.isEmpty(flex)) { resultComponent.setColumnExpandRatio(i, Float.parseFloat(flex)); } i++; } } @SuppressWarnings("unchecked") List<Element> rowElements = rowsElement.elements("row"); Set<Element> invisibleRows = new HashSet<>(); int rowCount = 0; for (Element rowElement : rowElements) { String visible = rowElement.attributeValue("visible"); if (!StringUtils.isEmpty(visible)) { Boolean value = Boolean.valueOf(visible); if (BooleanUtils.toBoolean(value)) { rowCount++; } else { invisibleRows.add(rowElement); } } else { rowCount++; } } resultComponent.setRows(rowCount); int j = 0; for (Element rowElement : rowElements) { final String flex = rowElement.attributeValue("flex"); if (!StringUtils.isEmpty(flex)) { resultComponent.setRowExpandRatio(j, Float.parseFloat(flex)); } j++; } spanMatrix = new boolean[columnCount][rowElements.size()]; int row = 0; for (Element rowElement : rowElements) { if (!invisibleRows.contains(rowElement)) { createSubComponents(resultComponent, rowElement, row); row++; } } }
From source file:io.github.msdk.db.mona.MonaSpectrum.java
/** * actual builder//from www . j av a2s .c o m * * @param monaRecord * object. */ protected void build(Spectra monaRecord) { logger.info("received: " + monaRecord.getId()); // convert to internal model for (String s : monaRecord.getSpectrum().split(" ")) { String v[] = s.split(":"); addDataPoint(Double.parseDouble(v[0]), Float.parseFloat(v[1])); } // assign compound information @SuppressWarnings("unused") String molFile = monaRecord.getBiologicalCompound().getMolFile(); // done logger.debug("spectra build"); }
From source file:javadz.beanutils.converters.FloatArrayConverter.java
/** * Convert the specified input object into an output object of the * specified type.//from w ww .java 2 s .co m * * @param type Data type to which this value should be converted * @param value The input value to be converted * @return the converted value * * @exception ConversionException if conversion cannot be performed * successfully */ public Object convert(Class type, Object value) { // Deal with a null value if (value == null) { if (useDefault) { return (defaultValue); } else { throw new ConversionException("No value specified"); } } // Deal with the no-conversion-needed case if (MODEL.getClass() == value.getClass()) { return (value); } // Deal with input value as a String array if (strings.getClass() == value.getClass()) { try { String[] values = (String[]) value; float[] results = new float[values.length]; for (int i = 0; i < values.length; i++) { results[i] = Float.parseFloat(values[i]); } return (results); } catch (Exception e) { if (useDefault) { return (defaultValue); } else { throw new ConversionException(value.toString(), e); } } } // Parse the input value as a String into elements // and convert to the appropriate type try { List list = parseElements(value.toString()); float[] results = new float[list.size()]; for (int i = 0; i < results.length; i++) { results[i] = Float.parseFloat((String) list.get(i)); } return (results); } catch (Exception e) { if (useDefault) { return (defaultValue); } else { throw new ConversionException(value.toString(), e); } } }
From source file:edu.nyu.vida.data_polygamy.exp.NoiseExp.java
void load1DData(String aggregatesFile, int year) { String[] s = null;/*from w w w .ja va 2s.com*/ try { BufferedReader buf = new BufferedReader(new FileReader(aggregatesFile)); s = Utilities.getLine(buf, ","); while (true) { if (s == null) { break; } String attr = Utilities.splitString(s[0], ":")[1].trim(); //System.out.println("Attribute: " + attr); Attribute a = new Attribute(); a.nodeSet.add(0); s = Utilities.getLine(buf, ","); if (s != null && s.length > 0 && s[0].toLowerCase().startsWith("spatial")) { s = Utilities.getLine(buf, ","); } if (s == null || s.length == 0) { System.out.println("Empty: ---------------------- " + attr); } while (s != null && s.length > 0) { int month = Integer.parseInt(Utilities.splitString(s[0], ":")[1].trim()); s = Utilities.getLine(buf, ","); HashSet<SpatioTemporalVal> set = new HashSet<SpatioTemporalVal>(); while (s != null && s.length == 2) { if (month / 100 == year) { int time = Integer.parseInt(s[0]); float value = Float.parseFloat(s[1]); SpatioTemporalVal val = new SpatioTemporalVal(0, time, value); set.add(val); ArrayList<Float> vals = (values.get(attr) == null) ? new ArrayList<Float>() : values.get(attr); vals.add(value); values.put(attr, vals); set.add(val); } s = Utilities.getLine(buf, ","); } if (set.size() > 0) { ArrayList<SpatioTemporalVal> arr = new ArrayList<SpatioTemporalVal>(set); Collections.sort(arr); a.data.put(month, arr); } } if (dataAttributesHashSet.contains(attr)) { attributes.put(attr, a); } s = Utilities.getLine(buf, ","); } buf.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.koda.integ.hbase.storage.FIFOStorageRecycler.java
/** * Inits the./*from ww w. j a v a 2 s. co m*/ * * @param config the config */ private void init(Configuration config) { lowWatermark = Float.parseFloat(config.get(STORAGE_RATIO_LOW_CONF, STORAGE_RATIO_LOW_DEFAULT)); highWatermark = Float.parseFloat(config.get(STORAGE_RATIO_HIGH_CONF, STORAGE_RATIO_HIGH_DEFAULT)); dumpConfig(); }
From source file:it.uniroma2.sag.kelp.data.representation.vector.SparseVector.java
@Override public void setDataFromText(String representationDescription) throws IOException { String[] feats = representationDescription.trim().split(FEATURE_SEPARATOR); if (feats[0].equals("")) { return;//from www . j a v a 2 s . c o m } String dimTmp = null; String valueTmp = null; float value; for (String feature : feats) { int separatorIndex = feature.lastIndexOf(NAME_VALUE_SEPARATOR); if (separatorIndex <= 0) { throw new IOException( "Parsing error in SparseVector.init function: formatting error in the feat-value pair " + feature); } dimTmp = feature.substring(0, separatorIndex); valueTmp = feature.substring(separatorIndex + 1); Float val = Float.parseFloat(valueTmp); if (val.isNaN()) { logger.warn("NaN value in representation: " + representationDescription); } value = val.floatValue(); this.setFeatureValue(dimTmp, value); } }