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:ca.etsmtl.applets.etsmobile.ProfileActivity.java

private void getBandwith(String phase, String appt) {
    appt_input.setEnabled(false);/*  w w w  .  j av  a2 s. c  om*/
    phase_input.setEnabled(false);

    final Editor edit = prefs.edit();
    creds.setPhase(phase);
    creds.setAppt(appt);
    edit.putString(UserCredentials.REZ, phase);
    edit.putString(UserCredentials.APPT, appt);
    edit.commit();

    // get bandwidth from cooptel, parse html, extract floats, etc etc
    new AsyncTask<String, Void, float[]>() {
        final Pattern usageRegex = Pattern.compile(
                "<TR><TD>(.*)</TD><TD>(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TR>");
        final Pattern quotaRegex = Pattern.compile(
                "<TR><TD>Quota permis pour la p&eacute;riode</TD><TD ALIGN=\"RIGHT\">(.*)</TD></TD></TR>");

        @Override
        protected float[] doInBackground(String... params) {
            final float[] result = new float[2];
            try {
                final HttpGet get = new HttpGet(URI.create(
                        String.format("http://www2.cooptel.qc.ca/services/temps/?mois=%d&cmd=Visualiser",
                                Calendar.getInstance().get(Calendar.MONTH) + 1)));
                final BasicScheme scheme = new BasicScheme();
                final Credentials credentials = new UsernamePasswordCredentials(
                        "ets-res" + params[0] + "-" + params[1], "ets" + params[1]);
                try {
                    final Header h = scheme.authenticate(credentials, get);
                    get.addHeader(h);
                    final HttpClient client = new DefaultHttpClient();
                    final HttpResponse re = client.execute(get);

                    // if HTTP200
                    if (re.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                        final String ent = EntityUtils.toString(re.getEntity());
                        final Matcher matcher = usageRegex.matcher(ent);

                        float total = 0;
                        // String[] usageResult = matcher.;
                        // parse all results
                        while (matcher.find()) {
                            final Number upload = Float.parseFloat(matcher.group(3));
                            final Number download = Float.parseFloat(matcher.group(4));

                            total += upload.floatValue();
                            total += download.floatValue();
                        }

                        final Matcher quotaResult = quotaRegex.matcher(ent);
                        float totalBandwithAvail = 0;
                        if (quotaResult.find()) {
                            totalBandwithAvail = Float.parseFloat(quotaResult.group(1));
                        }
                        result[0] = total / 1024;
                        result[1] = totalBandwithAvail / 1024;

                    }
                } catch (final AuthenticationException e) {
                    e.printStackTrace();
                }

            } catch (final IOException e) {
                e.printStackTrace();
            }

            return result;
        }

        @Override
        protected void onPostExecute(float[] result) {
            handlerBandwith.obtainMessage(2, result).sendToTarget();
            super.onPostExecute(result);
        }

    }.execute(phase, appt);
}

From source file:net.sf.jasperreports.engine.data.JRAbstractTextDataSource.java

protected Object convertNumber(Number number, Class<?> valueClass) throws JRException {
    Number value = null;//from  www  .  j  a v  a 2  s.  co m
    if (valueClass.equals(Byte.class)) {
        value = number.byteValue();
    } else if (valueClass.equals(Short.class)) {
        value = number.shortValue();
    } else if (valueClass.equals(Integer.class)) {
        value = number.intValue();
    } else if (valueClass.equals(Long.class)) {
        value = number.longValue();
    } else if (valueClass.equals(Float.class)) {
        value = number.floatValue();
    } else if (valueClass.equals(Double.class)) {
        value = number.doubleValue();
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException(EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE, new Object[] { valueClass.getName() });
    }
    return value;
}

From source file:org.appcelerator.titanium.TiBlob.java

@Kroll.method
public TiBlob imageWithRoundedCorner(Number cornerRadius, @Kroll.argument(optional = true) Number borderSize) {
    Bitmap img = getImage();/*from   w ww  .  j  ava  2 s . c o m*/
    if (img == null) {
        return null;
    }

    float radius = cornerRadius.floatValue();
    float border = 1f;
    if (borderSize != null) {
        border = borderSize.floatValue();
    }

    Bitmap imageRoundedCorner = TiImageHelper.imageWithRoundedCorner(img, radius, border);
    return blobFromImage(imageRoundedCorner);
}

From source file:org.jbpm.formModeler.core.processing.fieldHandlers.NumericFieldHandler.java

public Object getTheValue(Field field, String[] paramValue, String desiredClassName) throws Exception {
    if (paramValue == null || paramValue.length == 0)
        return null;

    if (desiredClassName.equals("byte")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Byte((byte) 0);
        else/*from w  w w  .j a v a 2 s  .  com*/
            return Byte.decode(paramValue[0]);
    } else if (desiredClassName.equals("short")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Short((short) 0);
        else
            return Short.decode(paramValue[0]);
    } else if (desiredClassName.equals("int")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Integer(0);
        else
            return Integer.decode(paramValue[0]);
    } else if (desiredClassName.equals("long")) {
        if (StringUtils.isEmpty(paramValue[0]))
            return new Long(0L);
        else
            return Long.decode(paramValue[0]);
    } else if (desiredClassName.equals(Byte.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Byte.decode(paramValue[0]);
    } else if (desiredClassName.equals(Short.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Short.decode(paramValue[0]);

    } else if (desiredClassName.equals(Integer.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Integer.decode(paramValue[0]);

    } else if (desiredClassName.equals(Long.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return Long.decode(paramValue[0]);

    } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double")
            || desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float")
            || desiredClassName.equals(BigDecimal.class.getName())) {

        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();

        DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(new Locale(LocaleManager.currentLang()));
        if (desiredClassName.equals(BigDecimal.class.getName()))
            df.setParseBigDecimal(true);
        String pattern = getFieldPattern(field);
        if (pattern != null && !"".equals(pattern)) {
            df.applyPattern(pattern);
        } else {
            df.applyPattern("###.##");
        }
        ParsePosition pp = new ParsePosition(0);
        Number num = df.parse(paramValue[0], pp);
        if (paramValue[0].length() != pp.getIndex() || num == null) {
            log.debug("Error on parsing value");
            throw new ParseException("Error parsing value", pp.getIndex());
        }

        if (desiredClassName.equals(BigDecimal.class.getName())) {
            return num;
        } else if (desiredClassName.equals(Float.class.getName()) || desiredClassName.equals("float")) {
            return new Float(num.floatValue());
        } else if (desiredClassName.equals(Double.class.getName()) || desiredClassName.equals("double")) {
            return new Double(num.doubleValue());
        }
    } else if (desiredClassName.equals(BigInteger.class.getName())) {
        if (StringUtils.isEmpty(paramValue[0]))
            throw new EmptyNumberException();
        return new BigInteger(paramValue[0]);

    }
    throw new IllegalArgumentException("Invalid class for NumericFieldHandler: " + desiredClassName);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleDiv(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case IDIV://from w w  w . j  a v  a 2s  . c om
        number = Integer.valueOf(one.intValue() / two.intValue());
        break;
    case DDIV:
        number = Double.valueOf(one.doubleValue() / two.doubleValue());
        break;
    case FDIV:
        number = Float.valueOf(one.floatValue() / two.floatValue());
        break;
    case LDIV:
        number = Long.valueOf(one.longValue() / two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleMul(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case IMUL:/*from   ww  w .j a v a2 s  . c  om*/
        number = Integer.valueOf(one.intValue() * two.intValue());
        break;
    case DMUL:
        number = Double.valueOf(one.doubleValue() * two.doubleValue());
        break;
    case FMUL:
        number = Float.valueOf(one.floatValue() * two.floatValue());
        break;
    case LMUL:
        number = Long.valueOf(one.longValue() * two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleSub(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case ISUB://from  w  w  w  .j  a  v  a  2s .c  o m
        number = Integer.valueOf(one.intValue() - two.intValue());
        break;
    case DSUB:
        number = Double.valueOf(one.doubleValue() - two.doubleValue());
        break;
    case FSUB:
        number = Float.valueOf(one.floatValue() - two.floatValue());
        break;
    case LSUB:
        number = Long.valueOf(one.longValue() - two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:de.tuberlin.uebb.jbop.optimizer.arithmetic.ArithmeticExpressionInterpreter.java

private AbstractInsnNode handleAdd(final int opcode, final Number one, final Number two) {
    final Number number;
    switch (opcode) {
    case IADD:/*from www  . j a  v  a  2 s.  co  m*/
        number = Integer.valueOf(one.intValue() + two.intValue());
        break;
    case DADD:
        number = Double.valueOf(one.doubleValue() + two.doubleValue());
        break;
    case FADD:
        number = Float.valueOf(one.floatValue() + two.floatValue());
        break;
    case LADD:
        number = Long.valueOf(one.longValue() + two.longValue());
        break;
    default:
        return null;
    }
    return NodeHelper.getInsnNodeFor(number);
}

From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatExportHelper.java

private Object convertNumberTypes(Object val, String javaColType) {
    Number n = (Number) val;
    if (javaColType.equals(BYTE_TYPE)) {
        return n.byteValue();
    } else if (javaColType.equals(SHORT_TYPE)) {
        return n.shortValue();
    } else if (javaColType.equals(INTEGER_TYPE)) {
        return n.intValue();
    } else if (javaColType.equals(LONG_TYPE)) {
        return n.longValue();
    } else if (javaColType.equals(FLOAT_TYPE)) {
        return n.floatValue();
    } else if (javaColType.equals(DOUBLE_TYPE)) {
        return n.doubleValue();
    } else if (javaColType.equals(BIG_DECIMAL_TYPE)) {
        return new BigDecimal(n.doubleValue());
    } else if (javaColType.equals(BOOLEAN_TYPE)) {
        return n.byteValue() == 0 ? Boolean.FALSE : Boolean.TRUE;
    } else if (javaColType.equals(STRING_TYPE)) {
        return n.toString();
    }//from  w  w w  .j a  v a  2  s  .  c om
    return null;
}

From source file:com.enonic.cms.business.core.content.index.ContentIndexServiceImpl.java

/**
 * @inheritDoc/*from  www .  j a  v a2s . c o m*/
 */
public AggregatedResult query(AggregatedQuery query) {
    AggregatedQueryTranslator translator = new AggregatedQueryTranslator();
    TranslatedQuery translated = translator.translate(query);
    List<Object[]> list = contentIndexDao.findIndexValues(translated.getQuery());

    Object[] values = list.get(0);
    Number count = (Number) values[0];
    Number minValue = (Number) values[1];
    Number maxValue = (Number) values[2];
    Number sumValue = (Number) values[3];
    Number averageValue = (Number) values[4];

    return new AggregatedResultImpl(count.intValue(), minValue == null ? 0 : minValue.floatValue(),
            maxValue == null ? 0 : maxValue.floatValue(), sumValue == null ? 0 : sumValue.floatValue(),
            averageValue == null ? 0 : averageValue.floatValue());
}