Example usage for java.lang Float floatValue

List of usage examples for java.lang Float floatValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public float floatValue() 

Source Link

Document

Returns the float value of this Float object.

Usage

From source file:org.apache.fop.svg.ACIUtils.java

/**
 * Tries to find matching fonts in FOP's {@link FontInfo} instance for fonts used by
 * Apache Batik. The method inspects the various GVT attributes found in the ACI.
 * @param aci the ACI to find matching fonts for
 * @param fontInfo the font info instance with FOP's fonts
 * @return an array of matching fonts/*  w w w.  j a v  a  2  s  .c om*/
 */
public static Font[] findFontsForBatikACI(AttributedCharacterIterator aci, FontInfo fontInfo) {
    List<Font> fonts = new java.util.ArrayList<Font>();
    @SuppressWarnings("unchecked")
    List<GVTFontFamily> gvtFonts = (List<GVTFontFamily>) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT_FAMILIES);
    Float posture = (Float) aci.getAttribute(TextAttribute.POSTURE);
    Float taWeight = (Float) aci.getAttribute(TextAttribute.WEIGHT);
    Float fontSize = (Float) aci.getAttribute(TextAttribute.SIZE);

    String style = toStyle(posture);
    int weight = toCSSWeight(taWeight);
    int fsize = (int) (fontSize.floatValue() * 1000);

    String firstFontFamily = null;

    //GVT_FONT can sometimes be different from the fonts in GVT_FONT_FAMILIES
    //or GVT_FONT_FAMILIES can even be empty and only GVT_FONT is set
    /* The following code section is not available until Batik 1.7 is released. */
    GVTFont gvtFont = (GVTFont) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT);
    if (gvtFont != null) {
        String gvtFontFamily = gvtFont.getFamilyName();
        if (fontInfo.hasFont(gvtFontFamily, style, weight)) {
            FontTriplet triplet = fontInfo.fontLookup(gvtFontFamily, style, weight);
            Font f = fontInfo.getFontInstance(triplet, fsize);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found a font that matches the GVT font: " + gvtFontFamily + ", " + weight + ", "
                        + style + " -> " + f);
            }
            fonts.add(f);
        }
        firstFontFamily = gvtFontFamily;
    }

    if (gvtFonts != null) {
        boolean haveInstanceOfSVGFontFamily = false;
        for (GVTFontFamily fam : gvtFonts) {
            if (fam instanceof SVGFontFamily) {
                haveInstanceOfSVGFontFamily = true;
            }
            String fontFamily = fam.getFamilyName();
            if (fontInfo.hasFont(fontFamily, style, weight)) {
                FontTriplet triplet = fontInfo.fontLookup(fontFamily, style, weight);
                Font f = fontInfo.getFontInstance(triplet, fsize);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Found a font that matches the GVT font family: " + fontFamily + ", " + weight
                            + ", " + style + " -> " + f);
                }
                fonts.add(f);
            }
            if (firstFontFamily == null) {
                firstFontFamily = fontFamily;
            }
        }
        // SVG fonts are embedded fonts in the SVG document and are rarely used; however if they
        // are used but the fonts also exists in the system and are known to FOP then FOP should
        // use them; then the decision whether Batik should stroke the text should be made after
        // no matching fonts are found
        if (fonts.isEmpty() && haveInstanceOfSVGFontFamily) {
            fontInfo.notifyStrokingSVGTextAsShapes(firstFontFamily);
            return null; // Let Batik paint this text!
        }
    }
    if (fonts.isEmpty()) {
        if (firstFontFamily == null) {
            //This will probably never happen. Just to be on the safe side.
            firstFontFamily = "any";
        }
        //lookup with fallback possibility (incl. substitution notification)
        FontTriplet triplet = fontInfo.fontLookup(firstFontFamily, style, weight);
        Font f = fontInfo.getFontInstance(triplet, fsize);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Falling back to adjustable font lookup up for: " + firstFontFamily + ", " + weight + ", "
                    + style + " -> " + f);
        }
        fonts.add(f);
    }
    return fonts.toArray(new Font[fonts.size()]);
}

From source file:Main.java

/**
 * <p>Converts an array of object Floats to primitives handling {@code null}.</p>
 *
 * <p>This method returns {@code null} for a {@code null} input array.</p>
 *
 * @param array  a {@code Float} array, may be {@code null}
 * @param valueForNull  the value to insert if {@code null} found
 * @return a {@code float} array, {@code null} if null array input
 *///w  w  w  .ja  va2s . co  m
public static float[] toPrimitive(Float[] array, float valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_FLOAT_ARRAY;
    }
    final float[] result = new float[array.length];
    for (int i = 0; i < array.length; i++) {
        Float b = array[i];
        result[i] = (b == null ? valueForNull : b.floatValue());
    }
    return result;
}

From source file:Main.java

/**
 * <p>Converts an array of object Floats to primitives handling {@code null}.</p>
 *
 * <p>This method returns {@code null} for a {@code null} input array.</p>
 *
 * @param array  a {@code Float} array, may be {@code null}
 * @param valueForNull  the value to insert if {@code null} found
 * @return a {@code float} array, {@code null} if null array input
 *///ww w.  j  ava  2  s  .co  m
public static float[] toPrimitive(final Float[] array, final float valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_FLOAT_ARRAY;
    }
    final float[] result = new float[array.length];
    for (int i = 0; i < array.length; i++) {
        final Float b = array[i];
        result[i] = (b == null ? valueForNull : b.floatValue());
    }
    return result;
}

From source file:com.kingcore.framework.util.ConvertUtils.java

/**
 * ?//from  w  w  w.  j a  va2  s  .  c om
 * Create on 2003-6-18
 * @param Float 
 * @param int ??? 
 * @return
 */
public static String formatNumber(Float d, int scalar) throws Exception {
    float temp = d.floatValue();
    return formatNumber(temp, scalar);
}

From source file:Main.java

/**
 * <p>Turns a string value into a java.lang.Number.</p>
 *
 * <p>First, the value is examined for a type qualifier on the end
 * (<code>'f','F','d','D','l','L'</code>).  If it is found, it starts 
 * trying to create successively larger types from the type specified
 * until one is found that can hold the value.</p>
 *
 * <p>If a type specifier is not found, it will check for a decimal point
 * and then try successively larger types from <code>Integer</code> to
 * <code>BigInteger</code> and from <code>Float</code> to
 * <code>BigDecimal</code>.</p>
 *
 * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it
 * will be interpreted as a hexadecimal integer.  Values with leading
 * <code>0</code>'s will not be interpreted as octal.</p>
 *
 * @param val String containing a number
 * @return Number created from the string
 * @throws NumberFormatException if the value cannot be converted
 *///w ww .  j a  v a  2s .  com
public static Number createNumber(String val) throws NumberFormatException {
    if (val == null) {
        return null;
    }
    if (val.length() == 0) {
        throw new NumberFormatException("\"\" is not a valid number.");
    }
    if (val.startsWith("--")) {
        // this is protection for poorness in java.lang.BigDecimal.
        // it accepts this as a legal value, but it does not appear 
        // to be in specification of class. OS X Java parses it to 
        // a wrong value.
        return null;
    }
    if (val.startsWith("0x") || val.startsWith("-0x")) {
        return createInteger(val);
    }
    char lastChar = val.charAt(val.length() - 1);
    String mant;
    String dec;
    String exp;
    int decPos = val.indexOf('.');
    int expPos = val.indexOf('e') + val.indexOf('E') + 1;

    if (decPos > -1) {

        if (expPos > -1) {
            if (expPos < decPos) {
                throw new NumberFormatException(val + " is not a valid number.");
            }
            dec = val.substring(decPos + 1, expPos);
        } else {
            dec = val.substring(decPos + 1);
        }
        mant = val.substring(0, decPos);
    } else {
        if (expPos > -1) {
            mant = val.substring(0, expPos);
        } else {
            mant = val;
        }
        dec = null;
    }
    if (!Character.isDigit(lastChar)) {
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length() - 1);
        } else {
            exp = null;
        }
        //Requesting a specific type..
        String numeric = val.substring(0, val.length() - 1);
        boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
        switch (lastChar) {
        case 'l':
        case 'L':
            if (dec == null && exp == null
                    && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
                try {
                    return createLong(numeric);
                } catch (NumberFormatException nfe) {
                    //Too big for a long
                }
                return createBigInteger(numeric);

            }
            throw new NumberFormatException(val + " is not a valid number.");
        case 'f':
        case 'F':
            try {
                Float f = createFloat(numeric);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    //If it's too big for a float or the float value = 0 and the string
                    //has non-zeros in it, then float does not have the precision we want
                    return f;
                }

            } catch (NumberFormatException e) {
                // ignore the bad number
            }
            //Fall through
        case 'd':
        case 'D':
            try {
                Double d = createDouble(numeric);
                if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createBigDecimal(numeric);
            } catch (NumberFormatException e) {
                // empty catch
            }
            //Fall through
        default:
            throw new NumberFormatException(val + " is not a valid number.");

        }
    } else {
        //User doesn't have a preference on the return type, so let's start
        //small and go from there...
        if (expPos > -1 && expPos < val.length() - 1) {
            exp = val.substring(expPos + 1, val.length());
        } else {
            exp = null;
        }
        if (dec == null && exp == null) {
            //Must be an int,long,bigint
            try {
                return createInteger(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                return createLong(val);
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            return createBigInteger(val);

        } else {
            //Must be a float,double,BigDec
            boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
            try {
                Float f = createFloat(val);
                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
                    return f;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }
            try {
                Double d = createDouble(val);
                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
                    return d;
                }
            } catch (NumberFormatException nfe) {
                // empty catch
            }

            return createBigDecimal(val);

        }

    }
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

public static float getFloat(Float f) {
    if (null == f) {
        return 0;
    }//from w w  w .  j a  v  a  2  s . co m
    return f.floatValue();
}

From source file:org.squale.squaleweb.util.SqualeWebActionUtils.java

/**
 * @param aFloat le nombre  formatter//from   w  w  w .j a  v  a  2  s  . c o m
 * @return le float formatt en String avec un chiffre aprs la virgule
 */
public static String formatFloat(Float aFloat) {
    String result = DASH;
    if (aFloat != null && aFloat.floatValue() != MarkBO.NOT_NOTED_VALUE) {
        result = formatFloat(aFloat.floatValue());
    }
    return result;
}

From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPContainersDataUtils.java

public static void addFloatCDV(FloatCDV result, FloatCDV addendum) {
    addFloatDV(result, addendum);//from w w w .  j  a  v a 2s  .  c o  m
    Float f1 = result.getMin();
    Float f2 = addendum.getMin();
    if (f1 == null && f2 != null)
        result.setMin(f2);
    else if (f1 != null && f2 != null)
        result.setMin(new Float(f1.floatValue() + f2.floatValue()));
    f1 = result.getMax();
    f2 = addendum.getMax();
    if (f1 == null && f2 != null)
        result.setMax(f2);
    else if (f1 != null && f2 != null)
        result.setMax(new Float(f1.floatValue() + f2.floatValue()));
}

From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPContainersDataUtils.java

public static void addFloatDV(FloatDV result, FloatDV addendum) {
    result.setDuration(result.getDuration() + addendum.getDuration());
    Float f1 = result.getValue();
    Float f2 = addendum.getValue();
    if (f1 == null && f2 != null)
        result.setValue(f2);// w  ww  .  jav a  2 s  .c om
    else if (f1 != null && f2 != null)
        result.setValue(new Float(f1.floatValue() + f2.floatValue()));
}

From source file:fr.landel.utils.commons.ObjectUtils.java

/**
 * Get the primitive value of an {@link Float}. If {@code value} is not
 * {@code null}, returns the primitive value of {@code value} otherwise returns
 * {@code defaultValue}//from   w w w.  j  a v a2  s .  c o  m
 * 
 * <pre>
 * Float value = new Float(1f);
 * float value1 = ObjectUtils.toPrimitive(value, 0f); // =&gt; value1 = 1f
 * float value2 = ObjectUtils.toPrimitive((Float) null, 0f); // =&gt; value2 = 0f
 * </pre>
 * 
 * @param value
 *            the {@link Float} value
 * @param defaultValue
 *            the default value
 * @return a primitive float
 */
public static float toPrimitive(final Float value, final float defaultValue) {
    if (value == null) {
        return defaultValue;
    } else {
        return value.floatValue();
    }
}