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

public static Float getFloatValue(byte[] value, int format, int position) {
    if (value == null)
        return null;
    if (position + (format & 0xF) > value.length)
        return null;
    int i;//  w  w  w . j av  a 2 s .  c o  m
    int mantissa;
    int exponent;
    switch (format) {
    case FORMAT_SFLOAT:
        i = value[(position + 1)];
        position = value[position];
        mantissa = signed((position & 0xFF) + ((i & 0xFF & 0xF) << 8), 12);
        exponent = signed((i & 0xFF) >> 4, 4);
        return Float.valueOf((float) (mantissa * Math.pow(10.0D, exponent)));
    case FORMAT_FLOAT:
        exponent = value[(position + 3)];
        mantissa = value[(position + 2)];
        i = value[(position + 1)];
        position = value[position];
        return Float.valueOf(
                (float) ((format = signed((position & 0xFF) + ((i & 0xFF) << 8) + ((mantissa & 0xFF) << 16),
                        24)) * Math.pow(10.0D, exponent)));
    }
    return null;
}

From source file:Main.java

public static Float getFloatValue(byte[] value, int format, int position) {
    if (value == null || (format & 15) + position > value.length) {
        return null;
    }//ww w.  j  a  va  2  s.co m
    switch (format) {
    case FORMAT_SFLOAT /*50*/:
        int i = value[position + FIRST_BITMASK];
        return Float.valueOf(
                (float) (((double) signed((value[position] & 255) + (((i & 255) & 15) << FOURTH_BITMASK), 12))
                        * Math.pow(10.0d, (double) signed((i & 255) >> THIRD_BITMASK, THIRD_BITMASK))));
    case FORMAT_FLOAT /*52*/:
        int exponent = value[position + 3];
        int mantissa = value[position + SECOND_BITMASK];
        return Float.valueOf((float) (((double) signed(
                ((value[position] & 255) + ((value[position + FIRST_BITMASK] & 255) << FOURTH_BITMASK))
                        + ((mantissa & 255) << FIFTH_BITMASK),
                24)) * Math.pow(10.0d, (double) exponent)));
    default:
        return null;
    }
}

From source file:Main.java

/**
 * Takes a string of the form [HH:]MM:SS[.mmm] and converts it to
 * milliseconds./*from w ww . ja va2s .  c o  m*/
 *
 * @throws java.lang.NumberFormatException if the number segments contain invalid numbers.
 */
public static long parseTimeString(final String time) {
    String[] parts = time.split(":");
    long result = 0;
    int idx = 0;
    if (parts.length == 3) {
        // string has hours
        result += Integer.valueOf(parts[idx]) * 3600000L;
        idx++;
    }
    if (parts.length >= 2) {
        result += Integer.valueOf(parts[idx]) * 60000L;
        idx++;
        result += (Float.valueOf(parts[idx])) * 1000L;
    }
    return result;
}

From source file:Main.java

public static Float getFloatValue(byte[] value, int format, int position) {
    if (value == null || (format & 15) + position > value.length) {
        return null;
    }/*  w ww  .  j a va 2  s .  c o m*/
    switch (format) {
    case FORMAT_SFLOAT /*50*/:
        int i = value[position + FIRST_BITMASK];
        return Float.valueOf(
                (float) (((double) signed((value[position] & 255) + (((i & 255) & 15) << FOURTH_BITMASK), 12))
                        * Math.pow(10.0d, (double) signed((i & 255) >> THIRD_BITMASK, THIRD_BITMASK))));
    case FORMAT_FLOAT /*52*/:
        int exponent = value[position + CategoryIDVoicemail];
        int mantissa = value[position + SECOND_BITMASK];
        return Float.valueOf((float) (((double) signed(
                ((value[position] & 255) + ((value[position + FIRST_BITMASK] & 255) << FOURTH_BITMASK))
                        + ((mantissa & 255) << FIFTH_BITMASK),
                24)) * Math.pow(10.0d, (double) exponent)));
    default:
        return null;
    }
}

From source file:Main.java

public static Object getObject(String type, String value) throws Exception {

    type = type.toLowerCase();/*w w  w . ja v  a 2 s.co  m*/
    if ("boolean".equals(type))
        return Boolean.valueOf(value);
    if ("byte".equals(type))
        return Byte.valueOf(value);
    if ("short".equals(type))
        return Short.valueOf(value);
    if ("char".equals(type))
        if (value.length() != 1)
            throw new NumberFormatException("Argument is not a character!");
        else
            return Character.valueOf(value.toCharArray()[0]);
    if ("int".equals(type))
        return Integer.valueOf(value);
    if ("long".equals(type))
        return Long.valueOf(value);
    if ("float".equals(type))
        return Float.valueOf(value);
    if ("double".equals(type))
        return Double.valueOf(value);
    if ("string".equals(type))
        return value;
    else {
        Object objs[] = new String[] { value };
        return Class.forName(type).getConstructor(new Class[] { java.lang.String.class }).newInstance(objs);
    }
}

From source file:Main.java

private static Rect calculateTapArea(float x, float y, int width, int height, float coefficient) {
    float focusAreaSize = 200;
    int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();
    int centerX = (int) ((x / width) * 2000 - 1000);
    int centerY = (int) ((y / height) * 2000 - 1000);
    int left = clamp(centerX - (areaSize / 2), -1000, 1000);
    int top = clamp(centerY - (areaSize / 2), -1000, 1000);
    RectF rectF = new RectF(left, top, left + areaSize, top + areaSize);
    return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right),
            Math.round(rectF.bottom));
}

From source file:Main.java

/**
 * Converts percentage string into actual based on a relative number
 *
 * @param percentage percentage string//from   ww  w  .  j a  v  a 2 s.  com
 * @param relative   relative number
 * @param offset     offset number
 * @return actual float based on relative number
 */

static float fromPercentageToFloat(String percentage, float relative, float offset, float scale) {
    Matcher matched = percentageRegExp.matcher(percentage);
    if (matched.matches()) {
        return Float.valueOf(matched.group(1)) / 100 * relative + offset;
    } else {
        return Float.valueOf(percentage) * scale + offset;
    }
}

From source file:Main.java

static Float floatElement(Element row, String name) {
    return Float.valueOf(stringElement(row, name));
}

From source file:Main.java

/**
 * box the float to Float
 */
public static Float boxed(float v) {
    return Float.valueOf(v);
}

From source file:Main.java

/**
 * Convert touch position x:y to {@link Camera.Area} position -1000:-1000 to 1000:1000.
 *//* w w w  . j a  v  a2s.  co  m*/
private static Rect calculateTapArea(Camera camera, float x, float y, float coefficient) {
    float focusAreaSize = 300;
    int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();

    int centerX = (int) (x / getResolution(camera).width - 1000);
    int centerY = (int) (y / getResolution(camera).height - 1000);

    int left = clamp(centerX - areaSize / 2, -1000, 1000);
    int top = clamp(centerY - areaSize / 2, -1000, 1000);

    RectF rectF = new RectF(left, top, left + areaSize, top + areaSize);

    return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right),
            Math.round(rectF.bottom));
}