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.etudes.mneme.impl.SubmissionImpl.java

/**
 * {@inheritDoc}/*from  www  . j  a  va  2s.  c o m*/
 */
public Float getTotalScore() {
    // phantoms don't have a total score
    if (getIsPhantom())
        return null;

    // add up the scores from the answers
    float total = 0;
    for (Answer answer : answers) {
        Float score = answer.getTotalScore();
        if (score != null) {
            total += score.floatValue();
        }
    }

    // add in the submission evaluation score if set
    if (this.evaluation.getScore() != null) {
        total += this.evaluation.getScore().floatValue();
    }

    // round away bogus decimals
    total = Math.round(total * 100.0f) / 100.0f;

    return Float.valueOf(total);
}

From source file:org.squale.squaleweb.applicationlayer.action.results.project.ProjectResultsAction.java

/**
 * Retourne la liste des critres lis au facteur paramtre.
 * /*from   w w w  .ja v  a  2  s. com*/
 * @param pFactorRule le facteur parent
 * @param pAudits la liste des audits
 * @param pProject le projet analys
 * @return la liste des rsultats
 * @throws Exception si un pb apparait
 */
private ResultListForm getCriteriaList(final FactorRuleDTO pFactorRule, final List pAudits,
        final ComponentDTO pProject) throws Exception {
    IApplicationComponent ac = AccessDelegateHelper.getInstance("Results");
    Object[] paramIn = { pProject, new Long(pFactorRule.getId()), pAudits };
    // Appel de la couche mtier
    ResultsDTO resultDTO = ((ResultsDTO) ac.execute("getTreChildrenResults", paramIn));
    ArrayList names = new ArrayList();
    names.addAll((Collection) resultDTO.getResultMap().get(null));
    resultDTO.getResultMap().remove(null);
    ResultListForm results = new ResultListForm();
    // Rcupration et tri des audits
    List audits = new LinkedList();
    audits.addAll(resultDTO.getResultMap().keySet());
    if (audits.size() > 0) {
        AuditComparator auditComp = new AuditComparator();
        // Tri des audits selon leur date
        Collections.sort(audits, auditComp);
        // Inversion des audits pour obtenir la date la plus rcente d'abord
        Collections.reverse(audits);
        CriteriumForm criteriumForm = null;
        ArrayList criteria = new ArrayList();
        // Parcours de chacun des critres pour le placer dans le formbean
        List res = (List) resultDTO.getResultMap().get(audits.get(0));
        for (int i = 0; i < names.size(); i++) {
            criteriumForm = new CriteriumForm();
            criteriumForm.setName(((CriteriumRuleDTO) names.get(i)).getName());
            criteriumForm.setId(((CriteriumRuleDTO) names.get(i)).getId() + "");
            // Mise du facteur correspondant au critre
            criteriumForm.setTreParent(pFactorRule.getId() + "");
            // Obtention de la note affecte au critre
            Float value = (Float) (res.get(i));
            if (null != value && value.floatValue() != -1) {
                SqualeWebActionUtils.setValue(criteriumForm, "setCurrentMark", "" + value.floatValue());
            }
            // Calcul de la tendance s'il existe un audit prcdent
            if (audits.size() > 1) {
                Float value2 = (Float) (((List) resultDTO.getResultMap().get(audits.get(1))).get(i));
                criteriumForm.setPredecessorMark("" + value2);
            }
            getCriteriumResult((CriteriumRuleDTO) names.get(i), criteriumForm, pAudits, pProject);
            criteria.add(criteriumForm);
        }
        results.setList(criteria);
    }
    return results;
}

From source file:org.etudes.mneme.impl.SubmissionImpl.java

/**
 * {@inheritDoc}/*  www.  ja  v  a 2  s. co  m*/
 */
public void consolidateTotalScore() {
    // check if there was a total score set
    if (!this.totalScoreToBeSet)
        return;
    this.totalScoreToBeSet = false;

    // for phantoms
    if (this.getIsPhantom()) {
        // if we have a value to set, phantoms get their evaluation set
        if (this.totalScoreToBe != null) {
            this.evaluation.setScore(this.totalScoreToBe);
        }

        return;
    }

    // adjust either the submission evaluation, or the single answer's evaluation if
    // there is a single answer only, and the submission's evaluation has not yet been set
    if (!getEvaluationUsed()) {
        // we need to have an answer
        if (this.answers.size() > 0) {
            Answer answer = answers.get(0);

            // if null, clear the evaluation score
            if (this.totalScoreToBe == null) {
                answer.getEvaluation().setScore(null);
            }

            else {
                // the final score "to be" will contain the auto-score for the answer (if there is one) - remove it
                float evalScore = this.totalScoreToBe.floatValue();
                Float autoScore = answer.getAutoScore();
                if (autoScore != null) {
                    evalScore -= autoScore.floatValue();
                }

                // round away bogus decimals
                evalScore = Math.round(evalScore * 100.0f) / 100.0f;

                // Note: setting the final to be 0 will not cause a null answer score to become 0 from null
                // (the grade_asssessment UI shows 0 for final score when there is no auto score and no evaluations set)
                if ((evalScore != 0f) || (answer.getEvaluation().getScore() != null)) {
                    answer.getEvaluation().setScore(evalScore);
                }
            }
        }
    }

    else {
        // take a null to mean clear the evaluation adjustment
        if (this.totalScoreToBe == null) {
            this.evaluation.setScore(null);
        }

        // compute the new adjustment to achieve this final score
        else {
            // the current answer total score
            float curAnswerScore = 0;
            for (Answer answer : answers) {
                Float answerScore = answer.getTotalScore();
                if (answerScore != null) {
                    curAnswerScore += answerScore.floatValue();
                }
            }

            // the current total score, including the answer total and any current evaluation
            float curTotalScore = curAnswerScore;
            if (this.evaluation.getScore() != null) {
                curTotalScore += this.evaluation.getScore().floatValue();
            }

            float total = this.totalScoreToBe.floatValue();
            this.totalScoreToBe = null;

            // if the current total is the total we want, we are done
            if (curTotalScore == total)
                return;

            // adjust to remove the current answer score
            total -= curAnswerScore;

            // set this as the new total score
            this.evaluation.setScore(total);
        }
    }
}

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

private Float getFloatValueMonthlyForecast(AHContainerAddress dailyContainerId,
        AHContainerAddress wdHourlyAvgContainerId) throws M2MHapException {
    Calendar c = Calendar.getInstance();
    long now = c.getTimeInMillis();
    int todayDayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    int todayMonth = c.get(Calendar.MONTH);
    int todayDayOfYear = c.get(Calendar.DAY_OF_YEAR);

    float currentMonthEstimation = 0;
    boolean useTodayEstimation = false;
    float todayEstimation = 0;
    long totalDuration = 0;
    long startTime = getNormalizedStartTime(c, now, ESPService.MONTH_RESOLUTION);
    long endTime = now;

    long lastTime = startTime;
    long lastDuration = 0;
    int todayEstimationFirstHour = 0;
    int todayEstimationLastHour = 0;

    ContentInstance ci = null;//from w w w . ja v  a 2 s  . c o  m
    Float lastValue = null;
    Float value = null;

    // Retrieves current month daily consumption and sum
    ContentInstanceItems items = getItemsWithHapCache(c, dailyContainerId, startTime, endTime,
            ESPService.DAY_RESOLUTION);
    if (items != null) {
        List<ContentInstance> resultList = items.getContentInstances();
        if (resultList != null) {
            ContentInstance contentInstance = null;
            FloatDV floatDV = null;
            for (Iterator<ContentInstance> iterator = resultList.iterator(); iterator.hasNext();) {
                contentInstance = iterator.next();
                floatDV = (FloatDV) contentInstance.getContent();
                if (floatDV != null) {
                    value = floatDV.getValue();
                    if (!iterator.hasNext()) {
                        lastValue = value;
                        lastTime = contentInstance.getId().longValue();
                        lastDuration = floatDV.getDuration();
                    } else if (value != null) {
                        currentMonthEstimation += value.floatValue();
                        totalDuration += floatDV.getDuration();
                    }
                }
            }
            log.info("getFloatValueMonthlyForecast - current month daily consumption returned: monthTotal="
                    + currentMonthEstimation + ", monthTotalDuration=" + totalDuration + ", lastValue="
                    + lastValue + ", lastTime=" + lastTime + ", lastDuration=" + lastDuration);
        }
    } else {
        return null;
    }

    // Fix duration error for all daily measures but the last one
    long durationError = (lastTime - startTime) - totalDuration;
    if (totalDuration != 0 && durationError > DateUtils.MILLISEC_IN_ONE_HOUR)
        currentMonthEstimation += currentMonthEstimation * ((float) durationError) / (lastTime - startTime);

    // // If total error for daily measures is greater than max error
    // tolerance a null value is returned
    // totalDuration += lastDuration;
    // if ((now - startTime) > totalDuration*(1+DURATION_ERROR_TOLERANCE))
    // return null;

    // If a partial estimation for today is available, use it current day
    // estimation
    if (lastDuration > 0 && lastTime >= getNormalizedStartTime(c, now, ESPService.DAY_RESOLUTION)) {
        c.setTimeInMillis(lastTime);
        todayEstimationFirstHour = c.get(Calendar.HOUR_OF_DAY);
        c.setTimeInMillis(lastTime + lastDuration);
        todayEstimationLastHour = c.get(Calendar.HOUR_OF_DAY) - 1;
        if (c.get(Calendar.DAY_OF_YEAR) != todayDayOfYear)
            todayEstimationLastHour = 23;
        int estimatedNrOfHours = todayEstimationLastHour - todayEstimationFirstHour + 1;
        if (estimatedNrOfHours > 0) {
            useTodayEstimation = true;
            // Fix last duration error
            todayEstimation = (lastValue / lastDuration) * estimatedNrOfHours * DateUtils.MILLISEC_IN_ONE_HOUR;
        }
    }

    // Calculate an estimation for the average consumption of each week day,
    // including today estimation
    float[] weekDayEstimation = { 0, 0, 0, 0, 0, 0, 0 };
    weekDayEstimation[todayDayOfWeek - 1] = todayEstimation;
    ContentInstanceItems weekDayItems = getNormalizedWeekDayItems(wdHourlyAvgContainerId,
            getHourlyDayOfWeekStartIndex(Calendar.SUNDAY), getHourlyDayOfWeekEndIndex(Calendar.SATURDAY));
    if (weekDayItems == null) {
        log.warn("getFloatValueMonthlyForecast - week day average consumption returned null items\n");
        return null;
    }
    List<ContentInstance> weekDayItemList = weekDayItems.getContentInstances();
    if (weekDayItemList == null || weekDayItemList.size() == 0) {
        log.warn(
                "getFloatValueMonthlyForecast - week day average consumption returned null or 0 sized item list\n");
        return null;
    }
    log.info("getFloatValueMonthlyForecast - week day average consumption returned\n" + weekDayItems);

    int weekDayIndex = 1;
    int hourlyIndex = 0;
    int nrOfMissingAvgValues = 0;

    for (Iterator<ContentInstance> iterator = weekDayItemList.iterator(); iterator.hasNext();) {
        ci = (ContentInstance) iterator.next();
        value = toFloat(ci);
        if (value != null && value.floatValue() >= 0) {
            if (!useTodayEstimation || weekDayIndex != todayDayOfWeek
                    || (hourlyIndex < todayEstimationFirstHour || hourlyIndex > todayEstimationLastHour)) {
                weekDayEstimation[weekDayIndex - 1] += value.floatValue();
            }
        } else {
            nrOfMissingAvgValues++;
        }
        hourlyIndex++;
        if (hourlyIndex % 24 == 0) {
            weekDayIndex++;
            hourlyIndex = 0;
        }
    }
    if (nrOfMissingAvgValues * DateUtils.MILLISEC_IN_ONE_HOUR >= DateUtils.MILLISEC_IN_ONE_DAY) {
        log.info("getFloatValueMonthlyForecast: too many average missing values - " + nrOfMissingAvgValues);
        return null;
    } else if (nrOfMissingAvgValues > 0) {
        log.info("getFloatValueMonthlyForecast: found some missing values - " + nrOfMissingAvgValues);
    }

    // The following update to lastTime value is necessary to manage legal
    // time switch
    c.setTimeInMillis(lastTime);
    c.set(Calendar.HOUR_OF_DAY, 12);
    lastTime = c.getTimeInMillis();
    while (c.get(Calendar.MONTH) == todayMonth) {
        currentMonthEstimation += weekDayEstimation[c.get(Calendar.DAY_OF_WEEK) - 1];
        lastTime += DateUtils.MILLISEC_IN_ONE_DAY;
        c.setTimeInMillis(lastTime);
    }

    return currentMonthEstimation * ((float) (weekDayItemList.size() + nrOfMissingAvgValues))
            / weekDayItemList.size();
}

From source file:org.squale.squaleweb.applicationlayer.action.results.project.ProjectResultsAction.java

/**
 * Retourne le dtail du critre recherch, avec ses pratiques.
 * //from   w ww. ja v  a2 s . c om
 * @param pCriteriumRuleDTO critre
 * @param pCriteriumForm le critre  remplir, il doit possder un nom.
 * @param pAudits la liste des audits.
 * @param pProject le projet analys.
 * @throws Exception si un pb apparat.
 */
private void getCriteriumResult(final CriteriumRuleDTO pCriteriumRuleDTO, final CriteriumForm pCriteriumForm,
        final List pAudits, final ComponentDTO pProject) throws Exception {
    IApplicationComponent ac = AccessDelegateHelper.getInstance("Results");
    Object[] paramIn = { pProject, new Long(pCriteriumRuleDTO.getId()), pAudits };
    ResultsDTO resultDTO = ((ResultsDTO) ac.execute("getTreChildrenResults", paramIn));
    ArrayList names = new ArrayList();
    names.addAll((Collection) resultDTO.getResultMap().get(null));
    resultDTO.getResultMap().remove(null);
    ArrayList practices = new ArrayList();
    // Rcupration et tri des audits
    List audits = new LinkedList();
    audits.addAll(resultDTO.getResultMap().keySet());
    AuditComparator auditComp = new AuditComparator();
    Collections.sort(audits, auditComp);
    // Inversion de la collection pour obtenir la dernire date en premier
    Collections.reverse(audits);
    ResultForm resultForm = null;
    // Parcours des pratiques
    for (int i = 0; i < names.size(); i++) {
        resultForm = new ResultForm();
        resultForm.setName(((PracticeRuleDTO) names.get(i)).getName());
        resultForm.setId(((PracticeRuleDTO) names.get(i)).getId() + "");
        resultForm.setTreParent(pCriteriumForm.getTreParent());
        // Note associe  la pratique
        Float value = (Float) (((List) resultDTO.getResultMap().get(audits.get(0))).get(i));
        if (null != value && value.floatValue() != -1) {
            // Conversion de la valeur en texte
            SqualeWebActionUtils.setValue(resultForm, "setCurrentMark", "" + value.floatValue());
        }
        // Calcul de la tendance s'il existe un audit antrieur
        if (audits.size() > 1) {
            Float value2 = (Float) (((List) resultDTO.getResultMap().get(audits.get(1))).get(i));
            resultForm.setPredecessorMark("" + value2);
        }
        practices.add(resultForm);
    }
    pCriteriumForm.setPractices(practices);
}

From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java

public float toZoom(float size) {
    float zoom = DEFAULT_ZOOM;

    Float zoomRatio = getCurrentItemConfiguration().getZoomRatio();
    if (zoomRatio != null) {
        zoom = zoomRatio.floatValue();
        if (zoom <= 0) {
            throw new JRRuntimeException("Invalid zoom ratio : " + zoom);
        }/*from w w  w  .ja va  2 s . com*/
    }

    return (zoom * size);
}

From source file:er.extensions.foundation.ERXProperties.java

/**
 * <div class="en">/*from ww w.ja  v a 2 s . c  o m*/
 * Cover method for returning a float for a
 * given system property with a default value.
 * </div>
 * 
 * <div class="ja">
 * ?? float ????
 * </div>
 * 
 * @param s <div class="en">system property</div>
 *          <div class="ja"></div>
 * @param defaultValue <div class="en">default value</div>
 *                     <div class="ja"></div>
 * 
 * @return <div class="en">float value of the system property or the default value</div>
 *         <div class="ja">float </div>
 */
public static float floatForKeyWithDefault(final String s, final float defaultValue) {
    final String propertyName = getApplicationSpecificPropertyName(s);

    float value;
    Object cachedValue = _cache.get(propertyName);
    if (UndefinedMarker.equals(cachedValue)) {
        value = defaultValue;
    } else if (cachedValue instanceof Float) {
        value = ((Float) cachedValue).floatValue();
    } else {
        Float objValue = ERXValueUtilities.FloatValueWithDefault(ERXSystem.getProperty(propertyName), null);
        _cache.put(s, objValue == null ? (Object) UndefinedMarker : objValue);
        if (objValue == null) {
            value = defaultValue;
        } else {
            value = objValue.floatValue();
        }
        if (retainDefaultsEnabled() && objValue == null) {
            System.setProperty(propertyName, Float.toString(defaultValue));
        }
    }
    return value;
}

From source file:org.squale.squaleweb.applicationlayer.action.results.project.ProjectResultsAction.java

/**
 * Retourne la valeur du facteur//from  w w  w .  jav a 2s . c  o m
 * 
 * @param pFactor le nom de facteur (cl du tre)
 * @param pAudits le liste des audits
 * @param pProject le projet analys
 * @param pRequest la requte active.
 * @return un form de rsultat contenant la note du facteur
 * @throws Exception si un pb apparat.
 */
private ResultForm getFactorResult(final FactorRuleDTO pFactor, final List pAudits, final ComponentDTO pProject,
        final HttpServletRequest pRequest) throws Exception {
    IApplicationComponent ac = AccessDelegateHelper.getInstance("Results");
    Object[] paramIn = { pAudits, pProject, new Long(pFactor.getId()) };
    ResultsDTO resultDTO = ((ResultsDTO) ac.execute("getByAudit", paramIn));

    // Rcupration et tri des audits
    List audits = new ArrayList();
    audits.addAll((List) resultDTO.getResultMap().get(null));
    resultDTO.getResultMap().remove(null);
    AuditComparator auditComp = new AuditComparator();
    audits.remove(null);
    Collections.sort(audits, auditComp);
    Collections.reverse(audits);
    ResultForm factorResult = new ResultForm();
    factorResult.setName(pFactor.getName());
    factorResult.setId("" + pFactor.getId());
    List res = (List) resultDTO.getResultMap().get(pProject);
    Float value = null;
    if (res.size() > 0) {
        value = (Float) res.get(0);
    }
    if (null != value) {
        SqualeWebActionUtils.setValue(factorResult, "setCurrentMark", "" + value.floatValue());
    }
    if (audits.size() > 1) {
        Float value2 = (Float) (((List) resultDTO.getResultMap().get(pProject)).get(1));
        factorResult.setPredecessorMark("" + value2);
    }
    return factorResult;
}

From source file:br.com.topsys.util.TSArrayUtil.java

/**
 * <p>/*from   ww  w .j a  v  a  2  s .c o m*/
 * Converts an array of object Floats to primitives handling
 * <code>null</code>.
 * </p>
 * 
 * <p>
 * This method returns <code>null</code> if <code>null</code> array
 * input.
 * </p>
 * 
 * @param array
 *            a <code>Float</code> array, may be <code>null</code>
 * @param valueForNull
 *            the value to insert if <code>null</code> found
 * @return a <code>float</code> array, <code>null</code> if null array
 *         input
 */
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++) {
        Float b = array[i];
        result[i] = (b == null ? valueForNull : b.floatValue());
    }
    return result;
}

From source file:net.ymate.platform.commons.lang.TreeObject.java

/**
 * 
 *
 * @param f
 */
public TreeObject(Float f) {
    _object = f != null ? f.floatValue() : Float.MIN_VALUE;
    _type = TYPE_FLOAT;
}