Example usage for java.lang Float doubleValue

List of usage examples for java.lang Float doubleValue

Introduction

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

Prototype

public double doubleValue() 

Source Link

Document

Returns the value of this Float as a double after a widening primitive conversion.

Usage

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts a number to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse/*from  w ww  .  ja  v  a  2 s . c  o  m*/
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Number number) {

    /* Switch on class and convert to double */

    String type = number.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFToDouble.java

public Double evaluate(Float i) {
    if (i == null) {
        return null;
    } else {/*from w ww . j ava  2s  . co  m*/
        return Double.valueOf(i.doubleValue());
    }
}

From source file:net.solarnetwork.node.dao.jdbc.consumption.test.JdbcConsumptionDatumDaoTest.java

@Test
public void storeNew() {
    ConsumptionDatum datum = new ConsumptionDatum(TEST_SOURCE_ID, TEST_AMPS, TEST_VOLTS);
    datum.setCreated(new Date());
    datum.setWattHourReading(TEST_WATT_HOUR_READING);

    dao.storeDatum(datum);// w  w  w  . j a v a2 s.  c om

    jdbcOps.query(SQL_GET_BY_ID,
            new Object[] { new java.sql.Timestamp(datum.getCreated().getTime()), TEST_SOURCE_ID },
            new ResultSetExtractor<Object>() {

                @Override
                public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
                    assertTrue("Must have one result", rs.next());

                    int col = 1;

                    String s = rs.getString(col++);
                    assertFalse(rs.wasNull());
                    assertEquals(TEST_SOURCE_ID, s);

                    rs.getTimestamp(col++);
                    assertFalse(rs.wasNull());

                    Float f = rs.getFloat(col++);
                    assertFalse(rs.wasNull());
                    assertEquals(TEST_VOLTS.doubleValue(), f.doubleValue(), 0.001);

                    f = rs.getFloat(col++);
                    assertFalse(rs.wasNull());
                    assertEquals(TEST_AMPS.doubleValue(), f.doubleValue(), 0.001);

                    Long l = rs.getLong(col++);
                    assertFalse(rs.wasNull());
                    assertEquals(TEST_WATT_HOUR_READING, l);

                    assertFalse("Must not have more than one result", rs.next());
                    return null;
                }

            });
}

From source file:org.openmicroscopy.shoola.agents.measurement.util.ui.ResultsCellRenderer.java

/**
 * Formats the passed object to two decimal places and returns as a string.
 * /*from  w ww  .j a va 2s  .  c  om*/
 * @param value The object to handle.
 * @return See above.
 */
private String twoDecimalPlaces(Float value) {
    return UIUtilities.twoDecimalPlaces(value.doubleValue());
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);/*from  w ww  .  j  a v a 2  s.c  o  m*/
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = false;
        } else if (obj instanceof Float) {
            Float f = (Float) obj;
            Double v = new Double(f.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Double v = new Double(s.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Double v = new Double(i.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Double v = new Double(l.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Double v = new Double(b.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Double v = new Double(n.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number");
        }
    }
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java

public Double getDoubleValue() {
    final String S_ProcName = "getDoubleValue";
    Double retval;//w  w w.  j av a2 s.  c  o m
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Float) {
            Float f = (Float) obj;
            Double v = new Double(f.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Double v = new Double(s.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Double v = new Double(i.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Double v = new Double(l.doubleValue());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Double v = new Double(b.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Double v = new Double(n.toString());
            if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, minValue, maxValue);
            }
            retval = v;
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number");
        }
    }
    return (retval);
}

From source file:org.muse.mneme.impl.GradesServiceGradebook23Impl.java

/**
 * {@inheritDoc}/* ww  w .  j a v  a2  s  .  c  om*/
 */
public Boolean reportAssessmentGrades(Assessment assessment) {
    if (assessment == null)
        throw new IllegalArgumentException();

    // make sure we are published, valid, have a title, and desire gradebook integration
    if (!(assessment.getPublished() && assessment.getGrading().getGradebookIntegration()
            && assessment.getIsValid() && (assessment.getTitle() != null)))
        return Boolean.FALSE;

    // make sure our assessment is in the gb
    if (!assessmentReported(assessment))
        return Boolean.FALSE;

    M_log.debug("reportAssessmentGrades: " + assessment.getId());

    try {
        // make sure there's a gradebook
        boolean hasGradebook = gradebookService.isGradebookDefined(assessment.getContext());
        if (hasGradebook) {
            // get the "official" submissions map of user id -> Float score (for released completed submissions)
            Map<String, Float> scores = this.submissionService.getAssessmentHighestScores(assessment,
                    Boolean.TRUE);

            // make them double for gb
            Map<String, Double> dScores = new HashMap<String, Double>();
            for (Map.Entry entry : scores.entrySet()) {
                String key = (String) entry.getKey();
                Float total = (Float) entry.getValue();
                dScores.put(key, (total == null) ? null : Double.valueOf(total.doubleValue()));
            }

            // report them
            gradebookService.updateExternalAssessmentScores(assessment.getContext(), assessment.getTitle(),
                    dScores);

            return Boolean.TRUE;
        }
    } catch (GradebookNotFoundException e) {
        M_log.warn("reportAssessmentGrades: " + assessment.getId() + e.toString());
    } catch (AssessmentNotFoundException e) {
        M_log.warn("reportAssessmentGrades: " + assessment.getId() + e.toString());
    }

    return Boolean.FALSE;
}

From source file:org.muse.mneme.impl.GradesServiceGradebook23Impl.java

/**
 * {@inheritDoc}//from   w w w.  j  a  v a 2  s  .  c o m
 */
public Boolean reportSubmissionGrade(Submission submission) {
    if (submission == null)
        throw new IllegalArgumentException();

    // make sure we are published, valid and desire gradebook integration
    Assessment assessment = submission.getAssessment();
    if (!(assessment.getPublished() && assessment.getGrading().getGradebookIntegration()
            && assessment.getIsValid() && (assessment.getTitle() != null)))
        return Boolean.FALSE;

    // make sure we are complete
    if (!submission.getIsComplete())
        return Boolean.FALSE;

    M_log.debug("reportSubmissionGrade: " + submission.getId());

    try {
        // make sure there's an entry
        boolean hasGradebook = gradebookService.isGradebookDefined(assessment.getContext());
        if (hasGradebook) {
            boolean reported = gradebookService.isExternalAssignmentDefined(assessment.getContext(),
                    assessment.getTitle());
            if (reported) {
                Double dScore = null;

                // if not released, report the null score
                if (submission.getIsReleased()) {
                    // get this submission's user's "official" submission for this submission's assessment
                    Float score = this.submissionService.getSubmissionOfficialScore(assessment,
                            submission.getUserId());
                    if (score != null) {
                        dScore = Double.valueOf(score.doubleValue());
                    }
                }

                // report it
                gradebookService.updateExternalAssessmentScore(assessment.getContext(), assessment.getTitle(),
                        submission.getUserId(), dScore);

                return Boolean.TRUE;
            }
        }
    } catch (GradebookNotFoundException e) {
        M_log.warn("reportAssessmentGrades: " + assessment.getId() + e.toString());
    } catch (AssessmentNotFoundException e) {
        M_log.warn("reportAssessmentGrades: " + assessment.getId() + e.toString());
    }

    return Boolean.FALSE;
}

From source file:org.openmrs.module.tracpatienttransfer.web.view.chart.OverviewOnExitPieChartView.java

@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {

    JFreeChart chart = null;//w  w  w .  jav  a2s  .c om
    UserContext userContext = Context.getUserContext();
    ApplicationContext appContext = ContextProvider.getApplicationContext();
    try {
        DefaultPieDataset pieDataset = new DefaultPieDataset();
        Concept reasonForExitCare = Context.getConceptService()
                .getConcept(TransferOutInPatientConstant.REASON_PATIENT_EXITED_FROM_CARE);
        Collection<ConceptAnswer> answers = reasonForExitCare.getAnswers();

        int total = Integer.valueOf(TransferOutInPatientTag.getNumberOfPatientExitedFromCare());

        int other = 0;
        Float percentage = 0f;
        for (ConceptAnswer ca : answers) {
            int nbrOfPatient = (Integer.valueOf(TransferOutInPatientTag
                    .getNumberOfPatientExitedFromCareWithReason(ca.getAnswerConcept().getConceptId())));
            percentage = (100f * nbrOfPatient / total);

            if (percentage > 5)
                pieDataset.setValue(
                        ca.getAnswerConcept().getDisplayString() + " (" + nbrOfPatient + " - "
                                + MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()) + "%)",
                        MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()));
            else
                other += nbrOfPatient;
        }

        if (other > 0) {
            String otherTitle = appContext.getMessage("tracpatienttransfer.others", null,
                    userContext.getLocale());
            percentage = (100f * other / total);
            pieDataset.setValue(
                    otherTitle + " (" + other + " - "
                            + MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()) + "%)",
                    MohTracUtil.roundTo2DigitsAfterComma(percentage.doubleValue()));
        }
        chart = ChartFactory.createPieChart(reasonForExitCare.getDisplayString(), pieDataset, true, true,
                false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return chart;
}

From source file:org.gephi.statistics.plugin.Modularity.java

private double q(int node, Community community) {
    Float edgesToFloat = structure.nodeConnectionsWeight[node].get(community);
    double edgesTo = 0;
    if (edgesToFloat != null) {
        edgesTo = edgesToFloat.doubleValue();
    }// w  w w.  j  a  v a2 s  .  c o m
    double weightSum = community.weightSum;
    double nodeWeight = structure.weights[node];
    double qValue = resolution * edgesTo - (nodeWeight * weightSum) / (2.0 * structure.graphWeightSum);
    if ((structure.nodeCommunities[node] == community) && (structure.nodeCommunities[node].size() > 1)) {
        qValue = resolution * edgesTo
                - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * structure.graphWeightSum);
    }
    if ((structure.nodeCommunities[node] == community) && (structure.nodeCommunities[node].size() == 1)) {
        qValue = 0.;
    }
    return qValue;
}