Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

In this page you can find the example usage for java.lang Float valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:marytts.util.string.StringUtils.java

public static float string2float(String str) {
    return Float.valueOf(str).floatValue();
}

From source file:ml.dmlc.xgboost4j.java.example.util.DataLoader.java

public static CSRSparseData loadSVMFile(String filePath) throws IOException {
    CSRSparseData spData = new CSRSparseData();

    List<Float> tlabels = new ArrayList<>();
    List<Float> tdata = new ArrayList<>();
    List<Long> theaders = new ArrayList<>();
    List<Integer> tindex = new ArrayList<>();

    File f = new File(filePath);
    FileInputStream in = new FileInputStream(f);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

    String line;/* ww  w  .  j  av  a 2s .c o m*/
    long rowheader = 0;
    theaders.add(rowheader);
    while ((line = reader.readLine()) != null) {
        String[] items = line.trim().split(" ");
        if (items.length == 0) {
            continue;
        }

        rowheader += items.length - 1;
        theaders.add(rowheader);
        tlabels.add(Float.valueOf(items[0]));

        for (int i = 1; i < items.length; i++) {
            String[] tup = items[i].split(":");
            assert tup.length == 2;

            tdata.add(Float.valueOf(tup[1]));
            tindex.add(Integer.valueOf(tup[0]));
        }
    }

    spData.labels = ArrayUtils.toPrimitive(tlabels.toArray(new Float[tlabels.size()]));
    spData.data = ArrayUtils.toPrimitive(tdata.toArray(new Float[tdata.size()]));
    spData.colIndex = ArrayUtils.toPrimitive(tindex.toArray(new Integer[tindex.size()]));
    spData.rowHeaders = ArrayUtils.toPrimitive(theaders.toArray(new Long[theaders.size()]));

    return spData;
}

From source file:edu.uga.cs.fluxbuster.clustering.hierarchicalclustering.DistanceMatrix.java

/**
 * Loads the distance matrix from a file which contains the upper triangle
 * values in a single row./*from  w w w.  j  av a2s . c  o  m*/
 * 
 * @param path
 *            the path to the matrix file
 * @throws IOException
 *             if the matrix values file can not be read
 */
public DistanceMatrix(String path) throws IOException {
    distMatrix = new Vector<Vector<Float>>();
    BufferedReader br = new BufferedReader(new FileReader(path));
    String[] strvals = br.readLine().split("\\s");
    Vector<Float> vals = new Vector<Float>();
    for (String s : strvals) {
        vals.add(Float.valueOf(s));
    }
    br.close();
    populateDistanceMatrix(vals);
}

From source file:com.orthancserver.DicomDecoder.java

private static void ExtractCalibration(ImagePlus image, JSONObject tags) {
    JSONObject rescaleIntercept = (JSONObject) tags.get("0028,1052");
    JSONObject rescaleSlope = (JSONObject) tags.get("0028,1053");
    if (rescaleIntercept != null && rescaleSlope != null) {
        double[] coeff = { Float.valueOf((String) rescaleIntercept.get("Value")),
                Float.valueOf((String) rescaleSlope.get("Value")) };
        image.getCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "Gray Value");
    }/*  www.j  a  v  a 2  s .c  om*/
}

From source file:io.github.swagger2markup.internal.adapter.PropertyAdapter.java

/**
 * Convert a string {@code value} to specified {@code type}.
 *
 * @param value value to convert//ww  w.ja  v a 2 s . com
 * @param type  target conversion type
 * @return converted value as object
 */
public static Object convertExample(String value, String type) {
    if (value == null) {
        return null;
    }

    try {
        switch (type) {
        case "integer":
            return Integer.valueOf(value);
        case "number":
            return Float.valueOf(value);
        case "boolean":
            return Boolean.valueOf(value);
        case "string":
            return value;
        default:
            return value;
        }
    } catch (NumberFormatException e) {
        throw new RuntimeException(String.format("Value '%s' cannot be converted to '%s'", value, type), e);
    }
}

From source file:com.wabacus.system.datatype.FloatType.java

public Object label2value(String label) {
    if (label == null || label.trim().equals(""))
        return null;
    if (this.numberformat != null && !this.numberformat.trim().equals("")) {
        return Float.valueOf(this.getNumber(label.trim()).floatValue());
    } else {// w ww .  j  a  va  2s  .c o m
        return Float.valueOf(label.trim());
    }
}

From source file:org.imsglobal.lti.LTIUtil.java

/**
* Converts a String value to a float value
*
* @param value string to be converted/*from  www . j av  a  2 s.  co m*/
*
* @return numeric value, or null if not a numeric string
*/
public static Float stringToFloat(String value) {

    Float fValue = null;
    try {
        fValue = Float.valueOf(value);
    } catch (NumberFormatException e) {
    }

    return fValue;

}

From source file:mercury.RootJsonHandler.java

protected <T extends DTO> T populateDtoFromJson(String jsonData, T dto) {
    try {/*w w w  . j  a  v a2  s  .co m*/
        JSONObject json = new JSONObject(jsonData);
        Class clazz = dto.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            try {
                String name = field.getName();
                Class fieldClass = field.getType();
                Object value = null;
                if (fieldClass.equals(String.class)) {
                    value = json.has(name) ? json.getString(name) : null;
                } else if (fieldClass.equals(Integer.class)) {
                    try {
                        value = json.has(name) ? json.getInt(name) : null;
                    } catch (Exception e) {
                        value = -1;
                    }
                } else if (fieldClass.equals(Float.class)) {
                    String sValue = json.has(name) ? json.getString(name).replaceAll(",", ".") : null;
                    value = sValue != null ? Float.valueOf(sValue) : null;
                } else if (fieldClass.equals(Date.class)) {
                    value = json.has(name) ? json.getString(name) : null;
                    value = value != null ? this.dateFormatter.parse((String) value) : null;
                }

                if (value == null) {
                    continue;
                }

                Method setter = clazz.getDeclaredMethod("set" + StringUtils.capitalize(name), fieldClass);
                if (setter != null) {
                    setter.invoke(dto, value);
                }
            } catch (Exception e) {
                continue;
            }
        }
    } catch (JSONException je) {
    }
    return dto;
}

From source file:net.sf.jasperreports.engine.xml.JRChartPlotFactory.java

/**
 *
 *//*from w  ww.  j  ava  2  s. c  o m*/
public Object createObject(Attributes atts) {
    JRChartPlot plot = (JRChartPlot) digester.peek();

    Color color = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor), Color.black);
    if (color != null) {
        plot.setBackcolor(color);
    }

    String orientation = atts.getValue(JRXmlConstants.ATTRIBUTE_orientation);
    if (orientation != null && orientation.length() > 0)
        plot.setOrientation((PlotOrientation) JRXmlConstants.getPlotOrientationMap().get(orientation));

    String foregroundAlpha = atts.getValue(JRXmlConstants.ATTRIBUTE_foregroundAlpha);
    if (foregroundAlpha != null && foregroundAlpha.length() > 0)
        plot.setForegroundAlpha(Float.valueOf(foregroundAlpha));

    String backgroundAlpha = atts.getValue(JRXmlConstants.ATTRIBUTE_backgroundAlpha);
    if (backgroundAlpha != null && backgroundAlpha.length() > 0)
        plot.setBackgroundAlpha(Float.valueOf(backgroundAlpha));

    String labelRotation = atts.getValue(JRXmlConstants.ATTRIBUTE_labelRotation);
    if (labelRotation != null && labelRotation.length() > 0)
        plot.setLabelRotation(Double.valueOf(labelRotation));

    return plot;
}

From source file:com.chinamobile.bcbsp.examples.connectedcomponent.CCVertexLiteNew.java

@Override
public void fromString(String vertexData) throws Exception {
    String[] buffer = new String[2];
    StringTokenizer str = new StringTokenizer(vertexData, Constants.KV_SPLIT_FLAG);
    if (str.hasMoreElements()) {
        buffer[0] = str.nextToken();/*from   w ww.j av a2 s  .c  o m*/
    } else {
        throw new Exception();
    }
    if (str.hasMoreElements()) {
        buffer[1] = str.nextToken();
    }
    str = new StringTokenizer(buffer[0], Constants.SPLIT_FLAG);
    if (str.countTokens() != 2) {
        throw new Exception();
    }
    this.vertexID = Integer.valueOf(str.nextToken());
    float tmp = Float.valueOf(str.nextToken());
    this.vertexValue = (int) tmp;

    if (buffer[1].length() > 0) { // There has edges.
        str = new StringTokenizer(buffer[1], Constants.SPACE_SPLIT_FLAG);
        while (str.hasMoreTokens()) {
            CCEdgeLiteNew edge = new CCEdgeLiteNew();
            edge.fromString(str.nextToken());
            this.edgesList.add(edge);
        }
    }
}