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:Main.java

/**
 * Converts to object array./*from  www .j a  v a  2s . co  m*/
 */
public static Float[] valuesOf(float[] array) {
    Float[] dest = new Float[array.length];
    for (int i = 0; i < array.length; i++) {
        dest[i] = Float.valueOf(array[i]);
    }
    return dest;
}

From source file:ImageUtil.java

/**
 * returns a dimension where width and height are inside the bounds of the
 * maxWidth and maxHeight parameters<br>
 * and the aspect ratio is the same as sourceWidth and sourceHeight.
 * /*w ww .  j a  v  a  2 s .  c  o m*/
 * @param maxWidth
 *            the maximum width of the target dimension
 * @param maxHeight
 *            the maximum height of the target dimension
 * @param sourceWidth
 *            the widht of the source image
 * @param sourceHeight
 *            the height of the source image
 * @return the target dimension that will be the greatest dimension that
 *         <ul>
 *         <li>will keep the ratio of the source images dimension</li>
 *         <li>fits in the bounds of the maximum dimension given</li>
 *         </ul>
 */
public static Dimension scaleDimensions(int maxWidth, int maxHeight, int sourceWidth, int sourceHeight) {
    float vidH, vidW, maxH, maxW;
    vidW = Integer.valueOf(sourceWidth).floatValue();
    vidH = Integer.valueOf(sourceHeight).floatValue();
    maxW = Integer.valueOf(maxWidth).floatValue();
    maxH = Integer.valueOf(maxHeight).floatValue();

    //        System.out.println("initial height / width ratio: " + vidH / vidW);
    //        System.out.println();
    //        System.out.println("vidW "+vidW+", vidH "+vidH);
    //        System.out.println("maxW "+maxW+", maxH "+maxH);
    //        System.out.println();

    float finalW, finalH;
    finalH = vidH / vidW * maxW;
    finalW = maxW;

    if (finalH > maxH) {
        float factor = maxH / finalH;
        finalH = maxH;
        finalW = finalW * factor;
    }

    int w = Float.valueOf(finalW).intValue();
    int h = Float.valueOf(finalH).intValue();

    Dimension d = new Dimension(w, h);

    //        System.out.println();
    //        System.out.println("finalW "+finalW+", finalH "+finalH);
    //        System.out.println("final height / width ratio: " + finalH / finalW);
    //        System.out.println();
    //        System.out.println(d);

    return d;
}

From source file:com.bstek.dorado.data.type.FloatDataType.java

public Object fromText(String text) {
    if (StringUtils.isEmpty(text)) {
        return null;
    } else {/*  www  .j  a  va2  s .  c  o  m*/
        return Float.valueOf(text);
    }
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,// w w  w  .  j ava 2s.c o  m
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}

From source file:com.tmobile.TMobileParsing.java

protected static Balance extractBalance(JsonObject jsonBillingAccount) {
    Balance balance = new Balance();
    JsonObject jsonBalance = jsonBillingAccount.getAsJsonObject("balance");
    balance.setRawValue(Float.valueOf(jsonBalance.get("rawValue").toString()));
    balance.setRoundedValue(Integer.valueOf(jsonBalance.get("roundedValue").toString()));

    return balance;
}

From source file:com.mingo.domain.util.DomainTestBuilder.java

public static Review createReview(int prefix) {
    Review review = new Review();
    review.setAuthor(createAuthor(prefix));
    review.setModerationStatus(ModerationStatus.values()[random(0, ModerationStatus.values().length - 1)]);
    review.setCreated(createDateAndAddYear(prefix));
    review.setText(MessageFormatter.format(REVIEW_TEXT, prefix).getMessage());
    review.setRating(Float.valueOf(prefix));
    review.addComment(createComment(prefix));
    for (int i = 0; i < random(1, TAGS_COUNT); i++) {
        review.addTag(TAGS.get(random(0, TAGS.size() - 1)));
        i++;//from   w  w  w .j a v  a 2  s.  c  o m
    }
    return review;
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static float randomFloat(float min, float max) {
    Float f = (float) (min + Math.random() * (max - min + 1));
    return Float.valueOf(new DecimalFormat("#.##").format(f));
}

From source file:Main.java

/**
 * Convert a string value to a boxed primitive type.
 *
 * @param type the boxed primitive type/*from   w w  w. j a va2 s.  c  o m*/
 * @param value the string value
 * @return a boxed primitive type
 */
public static Object valueOf(final Class<?> type, final String value) {
    if (type == String.class) {
        return value;
    }
    if (type == boolean.class) {
        return Boolean.valueOf(value);
    }
    if (type == int.class) {
        return Integer.valueOf(value);
    }
    if (type == long.class) {
        return Long.valueOf(value);
    }
    if (type == float.class) {
        return Float.valueOf(value);
    }
    if (type == double.class) {
        return Double.valueOf(value);
    }
    throw new IllegalArgumentException("Unsupported type " + type.getName());
}

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

public static DenseData loadCSVFile(String filePath) throws IOException {
    DenseData denseData = new DenseData();

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

    denseData.nrow = 0;//from   www  . jav  a  2s. c  o m
    denseData.ncol = -1;
    String line;
    List<Float> tlabels = new ArrayList<>();
    List<Float> tdata = new ArrayList<>();

    while ((line = reader.readLine()) != null) {
        String[] items = line.trim().split(",");
        if (items.length == 0) {
            continue;
        }
        denseData.nrow++;
        if (denseData.ncol == -1) {
            denseData.ncol = items.length - 1;
        }

        tlabels.add(Float.valueOf(items[items.length - 1]));
        for (int i = 0; i < items.length - 1; i++) {
            tdata.add(Float.valueOf(items[i]));
        }
    }

    reader.close();
    in.close();

    denseData.labels = ArrayUtils.toPrimitive(tlabels.toArray(new Float[tlabels.size()]));
    denseData.data = ArrayUtils.toPrimitive(tdata.toArray(new Float[tdata.size()]));

    return denseData;
}

From source file:Main.java

/**
 * Same as {@link #asFloat(String, Node)} but allows an xpath to be passed
 * in explicitly for reuse./* w  w  w  .  j  a  v  a 2 s  .  co  m*/
 */
public static Float asFloat(String expression, Node node, XPath xpath) throws XPathExpressionException {
    String floatString = evaluateAsString(expression, node, xpath);
    return (isEmptyString(floatString)) ? null : Float.valueOf(floatString);
}