Example usage for java.lang Number floatValue

List of usage examples for java.lang Number floatValue

Introduction

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

Prototype

public abstract float floatValue();

Source Link

Document

Returns the value of the specified number as a float .

Usage

From source file:org.squale.squalecommon.enterpriselayer.facade.rule.AuditComputing.java

/**
 * Calcul d'une note sur un composant//  ww w.  j  av  a 2 s  .c om
 * 
 * @param pSession session
 * @param pInterpreter interprte
 * @param pMeasures mesures
 * @param pPractice pratique
 * @param pPracticeResult rsultat de pratique
 * @param pChild composant
 * @return la note
 * @throws FormulaException si erreur
 * @throws JrafDaoException si erreur
 */

private static MarkBO computeMark(ISession pSession, FormulaInterpreter pInterpreter, MeasureBO[] pMeasures,
        PracticeRuleBO pPractice, PracticeResultBO pPracticeResult, AbstractComponentBO pChild)
        throws FormulaException, JrafDaoException {
    MarkBO mark = new MarkBO();
    mark.setComponent(pChild);
    mark.setPractice(pPracticeResult);
    // Calcul de la note
    // L'exception dans le calcul est remonte telle quelle
    Number value = pInterpreter.evaluate(pPractice.getFormula(), pMeasures);
    // On place une note -1 si la formule n'a pu tre calcule
    if (value == null) {
        mark.setValue(MarkBO.NOT_NOTED_VALUE);
    } else {
        mark.setValue(value.floatValue());
    }
    // Mise  jour de la rpartition des notes
    pPracticeResult.incrementRepartition(mark.getValue());
    // Enregistrement de la note
    MarkDAOImpl.getInstance().save(pSession, mark);
    return mark;
}

From source file:org.red5.io.utils.ConversionUtils.java

/**
 * Convert number to primitive wrapper like Boolean or Float
 * /*from   ww w.ja  va 2 s . c  om*/
 * @param num
 *            Number to conver
 * @param wrapper
 *            Primitive wrapper type
 * @return Converted object
 */
public static Object convertNumberToWrapper(Number num, Class<?> wrapper) {
    //XXX Paul: Using valueOf will reduce object creation
    if (wrapper.equals(String.class)) {
        return num.toString();
    } else if (wrapper.equals(Boolean.class)) {
        return Boolean.valueOf(num.intValue() == 1);
    } else if (wrapper.equals(Double.class)) {
        return Double.valueOf(num.doubleValue());
    } else if (wrapper.equals(Long.class)) {
        return Long.valueOf(num.longValue());
    } else if (wrapper.equals(Float.class)) {
        return Float.valueOf(num.floatValue());
    } else if (wrapper.equals(Integer.class)) {
        return Integer.valueOf(num.intValue());
    } else if (wrapper.equals(Short.class)) {
        return Short.valueOf(num.shortValue());
    } else if (wrapper.equals(Byte.class)) {
        return Byte.valueOf(num.byteValue());
    }
    throw new ConversionException(String.format("Unable to convert number to: %s", wrapper));
}

From source file:org.saiku.adhoc.service.report.SaikuAdhocPreProcessor.java

/**
 * Computes a set of field widths. The input-width definitions can be a mix of absolute and relative values; the
 * resulting widths are always relative values. If the input width is null or zero, it is assumed that the field wants
 * to have a generic width./*from w  w w  . j a  v  a2s . co  m*/
 *
 * @param fieldDescriptions
 * @param pageWidth
 * @return
 */
public static float[] computeFieldWidths(final Float[] fieldDescriptions, final float pageWidth) {
    final float[] resultWidths = new float[fieldDescriptions.length];

    float definedWidth = 0;
    int definedNumberOfFields = 0;
    for (int i = 0; i < fieldDescriptions.length; i++) {
        final Number number = fieldDescriptions[i];
        if (number != null && number.floatValue() != 0) {
            if (number.floatValue() < 0) {
                // a fixed value ..
                resultWidths[i] = number.floatValue();
                definedNumberOfFields += 1;
                definedWidth += number.floatValue();
            } else {
                final float absValue = number.floatValue();
                final float relativeValue = -absValue * 100 / pageWidth;
                resultWidths[i] = relativeValue;
                definedNumberOfFields += 1;
                definedWidth += relativeValue;
            }
        }
    }

    if (definedNumberOfFields == fieldDescriptions.length) {
        // we are done, all fields are defined.
        return resultWidths;
    }

    if (definedNumberOfFields == 0) {
        // the worst case, no element provides a weight ..
        // therefore all fields have the same proportional width.
        Arrays.fill(resultWidths, -(100 / fieldDescriptions.length));
        return resultWidths;
    }

    final float availableSpace = -100 - definedWidth;
    if (availableSpace > 0) {
        // all predefined fields already fill the complete page. There is no space left for the
        // extra columns.
        return resultWidths;
    }

    final float avgSpace = availableSpace / (fieldDescriptions.length - definedNumberOfFields);
    for (int i = 0; i < resultWidths.length; i++) {
        final float width = resultWidths[i];
        if (width == 0) {
            resultWidths[i] = avgSpace;
        }
    }
    return resultWidths;
}

From source file:gedi.util.FileUtils.java

public static void writeNumber(BinaryWriter out, Number d) throws IOException {
    if (d instanceof Byte)
        out.putByte(d.intValue());//from   w w w .ja  v  a 2s  .  co  m
    else if (d instanceof Short)
        out.putShort(d.shortValue());
    else if (d instanceof Integer)
        out.putInt(d.intValue());
    else if (d instanceof Long)
        out.putLong(d.longValue());
    else if (d instanceof Float)
        out.putFloat(d.floatValue());
    else
        out.putDouble(d.doubleValue());
}

From source file:com.actionbarsherlock.internal.nineoldandroids.animation.FloatEvaluator.java

/**
 * This function returns the result of linearly interpolating the start and end values, with
 * <code>fraction</code> representing the proportion between the start and end values. The
 * calculation is a simple parametric calculation: <code>result = x0 + t * (v1 - v0)</code>,
 * where <code>x0</code> is <code>startValue</code>, <code>x1</code> is <code>endValue</code>,
 * and <code>t</code> is <code>fraction</code>.
 *
 * @param fraction   The fraction from the starting to the ending values
 * @param startValue The start value; should be of type <code>float</code> or
 *                   <code>Float</code>
 * @param endValue   The end value; should be of type <code>float</code> or <code>Float</code>
 * @return A linear interpolation between the start and end values, given the
 *         <code>fraction</code> parameter.
 *///www .  j  av a  2s .  c om
public Float evaluate(float fraction, Number startValue, Number endValue) {
    float startFloat = startValue.floatValue();
    return startFloat + fraction * (endValue.floatValue() - startFloat);
}

From source file:routines.system.BigDataParserUtils.java

/**
 * Parse anything to Float//from   w  w  w . j  a  v  a 2s  . com
 *
 * @param input
 * @return
 */
public static Float parseTo_Float(Number input) {
    if (input == null) {
        return null;
    }
    return input.floatValue();
}

From source file:routines.system.BigDataParserUtils.java

/**
 * Parse anything to float/*from   w  w w  .j  av a 2s .c  o  m*/
 *
 * @param input
 * @return
 */
public static float parseTo_float(Number input) {
    if (input == null) {
        return defaultValueFloat;
    }
    return input.floatValue();
}

From source file:org.diorite.nbt.NbtTagFloat.java

@Override
public void setNumberValue(final Number i) {
    this.value = i.floatValue();
}

From source file:com.bstek.dorado.data.variant.DefaultVariantConvertor.java

public float toFloat(Object object) {
    Number n = (Number) floatDateType.convertFromObject(object);
    return n.floatValue();
}

From source file:org.xenei.jdbc4sparql.iface.TypeConverter.java

private static <T> T fromNumber(final Object columnObject, final Class<T> resultingClass) throws SQLException {
    final Number n = Number.class.cast(columnObject);
    if (resultingClass == BigDecimal.class) {
        return resultingClass.cast(new BigDecimal(n.toString()));
    }//from   w ww.ja v  a  2  s .  co  m
    if (resultingClass == BigInteger.class) {
        return resultingClass.cast(new BigInteger(n.toString()));
    }
    if (resultingClass == Byte.class) {
        return resultingClass.cast(new Byte(n.byteValue()));
    }
    if (resultingClass == Double.class) {
        return resultingClass.cast(new Double(n.doubleValue()));
    }
    if (resultingClass == Float.class) {
        return resultingClass.cast(new Float(n.floatValue()));
    }
    if (resultingClass == Integer.class) {
        return resultingClass.cast(new Integer(n.intValue()));
    }
    if (resultingClass == Long.class) {
        return resultingClass.cast(new Long(n.longValue()));
    }
    if (resultingClass == Short.class) {
        return resultingClass.cast(new Short(n.shortValue()));
    }
    if (resultingClass == String.class) {
        return resultingClass.cast(n.toString());
    }
    if (resultingClass == Boolean.class) {
        if (n.byteValue() == 0) {
            return resultingClass.cast(Boolean.FALSE);
        }
        if (n.byteValue() == 1) {
            return resultingClass.cast(Boolean.TRUE);
        }
    }
    if (resultingClass == byte[].class) {
        return resultingClass.cast(n.toString().getBytes());
    }
    if (resultingClass == Blob.class) {
        return resultingClass.cast(new SerialBlob(n.toString().getBytes()));
    }
    if (resultingClass == Clob.class) {
        return resultingClass.cast(new SerialClob(n.toString().toCharArray()));
    }
    return null;
}