Example usage for java.lang Double equals

List of usage examples for java.lang Double equals

Introduction

In this page you can find the example usage for java.lang Double equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object against the specified object.

Usage

From source file:org.mifos.accounts.servicefacade.WebTierAccountServiceFacade.java

@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);

    try {//from www  .  jav a 2 s.c o  m
        AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(
                new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId()))
                        .getParentAccount();
        BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
        BigDecimal membersAmount = BigDecimal.ZERO;

        for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
            LoanBO individual = loanDao.findById(entry.getKey());
            Double chargeAmount = Double.valueOf(entry.getValue());
            if (chargeAmount.equals(0.0)) {
                continue;
            }
            membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
            individual.updateDetails(userContext);

            if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
            } else {
                individual.applyCharge(chargeId, chargeAmount);
            }
        }

        boolean isRateCharge = false;

        if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES))
                && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {

            if (isPenaltyType) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                if (penalty instanceof RatePenaltyBO) {
                    isRateCharge = true;
                }
            } else {
                FeeBO fee = feeDao.findById(chargeId);
                if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
                    isRateCharge = true;
                }
            }
        }

        Double chargeAmount = null;

        if (!isRateCharge) {
            chargeAmount = sumCharge(idsAndValues);
        } else {
            chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
            BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
            membersAmount = membersAmount.multiply(chargeAmountBig);
            int scale = Money.getInternalPrecision();
            chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
            chargeAmount = chargeAmountBig.doubleValue();
        }

        parentAccount.updateDetails(userContext);

        CustomerLevel customerLevel = null;
        if (parentAccount.isCustomerAccount()) {
            customerLevel = parentAccount.getCustomer().getLevel();
        }
        if (parentAccount.getPersonnel() != null) {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext,
                    parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext,
                    parentAccount.getOffice().getOfficeId(), userContext.getId());
        }

        this.transactionHelper.startTransaction();

        if (isPenaltyType && parentAccount instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) parentAccount)
                    .addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
        } else {
            parentAccount.applyCharge(chargeId, chargeAmount);
        }

        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }

}

From source file:org.polymap.kaps.ui.form.WohnungGrunddatenFormEditorPage.java

private void updateKaufpreis() {
    VertragComposite vertrag = wohnung.vertrag().get();
    Double kaufpreis = null;
    if (vertrag != null) {
        if (vertrag.erweiterteVertragsdaten().get() != null) {
            VertragsdatenErweitertComposite vertragsdatenErweitertComposite = vertrag.erweiterteVertragsdaten()
                    .get();/*from   w  w w  .  j a va 2  s  .  com*/
            kaufpreis = vertragsdatenErweitertComposite.bereinigterVollpreis().get();
        }
        // erweiterte Daten kann leer sein
        if (kaufpreis == null || kaufpreis == 0.0d) {
            kaufpreis = vertrag.vollpreis().get();
        }
    }
    if (kaufpreis != null && !kaufpreis.equals(wohnung.kaufpreis().get())) {
        pageSite.fireEvent(this, wohnung.kaufpreis().qualifiedName().name(), IFormFieldListener.VALUE_CHANGE,
                kaufpreis);
    }
}

From source file:org.polymap.kaps.ui.form.WohnungLiegenschaftzinsFormEditorPage.java

@SuppressWarnings("unchecked")
@Override//from w  w w .  j  a  v a2s.  co  m
public void createFormContent(final IFormEditorPageSite site) {
    super.createFormContent(site);

    Control newLine, lastLine = null;
    Composite parent = pageSite.getPageBody();

    newLine = createLabel(parent, "Richtwert in /m", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenrichtwert(), two().top(lastLine), parent, false);
    createLabel(parent, "Bodenpreis in /m", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenpreis(), five().top(lastLine), parent, true);

    lastLine = newLine;
    newLine = createLabel(parent, "Mietfestsetzung seit", one().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL).setProperty(new PropertyAdapter(wohnung.mietfestsetzungSeit()))
            .setField(new DateTimeFormField()).setLayoutData(two().top(lastLine).create()).create();
    createLabel(parent, "Bebauungsabschlag in %", three().top(lastLine), SWT.RIGHT);
    createFlaecheField(wohnung.bebauungsabschlagInProzent(), four().top(lastLine), parent, true);
    createPreisField(wohnung.bebauungsabschlag(), five().top(lastLine), parent, false);
    site.addFieldListener(bebabschlag = new FieldCalculation(site, 2, wohnung.bebauungsabschlag(),
            wohnung.bebauungsabschlagInProzent(), wohnung.bodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double prozent = values.get(wohnung.bebauungsabschlagInProzent());
            Double preis = values.get(wohnung.bodenpreis());
            if (preis == null) {
                return null;
            }
            if (prozent == null) {
                return null;
            }
            return preis * prozent / 100;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "bereinigter Bodenpreis", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bereinigterBodenpreis(), five().top(lastLine), parent, true);
    site.addFieldListener(berPreis = new FieldCalculation(site, 2, wohnung.bereinigterBodenpreis(),
            wohnung.bebauungsabschlag(), wohnung.bodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double abschlag = values.get(wohnung.bebauungsabschlag());
            Double preis = values.get(wohnung.bodenpreis());
            if (preis == null) {
                return null;
            }
            if (abschlag == null) {
                return preis;
            }
            return preis - abschlag;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "monatlicher Rohertrag in ", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.monatlicherRohertrag(), two().top(lastLine), parent, true);
    createLabel(parent, "Jahresrohertrag in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.jahresRohertrag(), five().top(lastLine), parent, true);
    site.addFieldListener(jahresRohertrag = new FieldCalculation(site, 2, wohnung.jahresRohertrag(),
            wohnung.monatlicherRohertrag()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double abschlag = values.get(wohnung.monatlicherRohertrag());
            if (abschlag != null) {
                return abschlag * 12;
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Rohertrag in /m", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.monatlicherRohertragJeQm(), two().top(lastLine), parent, true);
    createLabel(parent, "Bewirtschaftungkosten in %", three().top(lastLine), SWT.RIGHT);
    createFlaecheField(wohnung.bewirtschaftungsKostenInProzent(), four().top(lastLine), parent, true);
    createPreisField(wohnung.bewirtschaftungsKosten(), five().top(lastLine), parent, false);
    site.addFieldListener(
            bewirtschaftungskosten = new FieldCalculation(site, 2, wohnung.bewirtschaftungsKosten(),
                    wohnung.bewirtschaftungsKostenInProzent(), wohnung.jahresRohertrag()) {

                @Override
                protected Double calculate(ValueProvider values) {
                    Double prozent = values.get(wohnung.bewirtschaftungsKostenInProzent());
                    Double preis = values.get(wohnung.jahresRohertrag());
                    if (preis == null) {
                        return null;
                    }
                    if (prozent == null) {
                        return null;
                    }
                    return preis * prozent / 100;
                }

            });

    lastLine = newLine;
    newLine = createLabel(parent, "Jahresreinertrag in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.jahresReinertrag(), five().top(lastLine), parent, true);
    site.addFieldListener(jahresReinertrag = new FieldCalculation(site, 2, wohnung.jahresReinertrag(),
            wohnung.bewirtschaftungsKosten(), wohnung.jahresRohertrag()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double ertrag = values.get(wohnung.jahresRohertrag());
            if (ertrag != null) {
                Double kosten = values.get(wohnung.bewirtschaftungsKosten());
                if (kosten == null) {
                    return ertrag;
                } else {
                    return MathUtil.round(ertrag - kosten);
                }
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Bodenwertanteil der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenwertAnteilDerWohnung(), five().top(lastLine), parent, true);
    site.addFieldListener(bodenwertAnteilDerWohnung = new FieldCalculation(site, 2,
            wohnung.bodenwertAnteilDerWohnung(), wohnung.wohnflaeche(), wohnung.bereinigterBodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            if (wohnung.flurstueck().get() != null) {
                Double flaeche = wohnung.flurstueck().get().flaeche().get();
                if (flaeche != null) {
                    Double zaehler = wohnung.flurstueck().get().flaechenAnteilZaehler().get();
                    Double nenner = wohnung.flurstueck().get().flaechenAnteilNenner().get();
                    Double preis = values.get(wohnung.bereinigterBodenpreis());
                    if (zaehler != null) {
                        flaeche *= zaehler;
                    }
                    if (nenner != null && !nenner.equals(Double.valueOf(0.0d))) {
                        flaeche /= nenner;
                    }
                    if (preis != null) {
                        flaeche *= preis;
                    } else {
                        flaeche = Double.valueOf(0.0d);
                    }
                    return MathUtil.round(flaeche);
                }
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Abschlge bercksichtigen?",
            "beim Kaufpreis die Zu/Abschlge bei\nGaragen/Stellplatz/Anderes bercksichtigen?",
            one().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL)
            .setToolTipText(
                    "beim Kaufpreis die Zu/Abschlge bei\nGaragen/Stellplatz/Anderes bercksichtigen?")
            .setProperty(new PropertyAdapter(wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen()))
            .setField(new CheckboxFormField()).setLayoutData(two().top(lastLine).create()).create();
    createLabel(parent, "Gebudewertanteil der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.gebaeudewertAnteilDerWohnung(), five().top(lastLine), parent, true);
    site.addFieldListener(gebaeudewertAnteilDerWohnung = new FieldCalculationWithTrigger(site, 2,
            wohnung.gebaeudewertAnteilDerWohnung(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.bodenwertAnteilDerWohnung(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double bodenwert = values.get(wohnung.bodenwertAnteilDerWohnung());
            if (bodenwert != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null) {
                    return MathUtil.round(preis - bodenwert);
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Sachwert der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.sachwertDerWohnung(), five().top(lastLine), parent, false);
    site.addFieldListener(sachwertDerWohnung = new FieldSummation(site, 2, wohnung.sachwertDerWohnung(),
            wohnung.bodenwertAnteilDerWohnung(), wohnung.gebaeudewertAnteilDerWohnung()));

    lastLine = newLine;
    newLine = createLabel(parent, "Jahresreinertrag/Kaufpreis", three().top(lastLine), SWT.RIGHT);
    createNumberField(IFormFieldLabel.NO_LABEL, null, wohnung.jahresReinErtragZuKaufpreis(),
            five().top(lastLine), parent, false, 4);
    site.addFieldListener(jahresReinErtragZuKaufpreis = new FieldCalculationWithTrigger(site, 4,
            wohnung.jahresReinErtragZuKaufpreis(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.jahresReinertrag(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double reinertrag = values.get(wohnung.jahresReinertrag());
            if (reinertrag != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null && !preis.equals(Double.valueOf(0.0d))) {
                    return reinertrag / preis;
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Gebudewertanteil/Kaufpreis", three().top(lastLine), SWT.RIGHT);
    createNumberField(IFormFieldLabel.NO_LABEL, null, wohnung.gebaeudewertAnteilZuKaufpreis(),
            five().top(lastLine), parent, false, 4);
    site.addFieldListener(gebaeudewertAnteilZuKaufpreis = new FieldCalculationWithTrigger(site, 4,
            wohnung.gebaeudewertAnteilZuKaufpreis(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.gebaeudewertAnteilDerWohnung(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double gebaeudewertAnteil = values.get(wohnung.gebaeudewertAnteilDerWohnung());
            if (gebaeudewertAnteil != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null && !preis.equals(Double.valueOf(0.0d))) {
                    return gebaeudewertAnteil / preis;
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Liegenschaftszins in %", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.liegenschaftsZins(), five().top(lastLine), parent, false);
    site.addFieldListener(liegenschaftsZins = new FieldCalculationWithTrigger(site, 2,
            wohnung.liegenschaftsZins(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.gebaeudewertAnteilZuKaufpreis(), wohnung.jahresReinErtragZuKaufpreis(),
            wohnung.gesamtNutzungsDauer(), wohnung.bereinigtesBaujahr(), wohnung.baujahr()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double faktor1 = values.get(wohnung.jahresReinErtragZuKaufpreis());
            Double faktor2 = values.get(wohnung.gebaeudewertAnteilZuKaufpreis());
            Double GND = values.get(wohnung.gesamtNutzungsDauer());
            Double baujahr = values.get(wohnung.bereinigtesBaujahr());
            if (baujahr == null || baujahr.doubleValue() == 0.0d) {
                baujahr = values.get(wohnung.baujahr());
            }

            VertragComposite vertrag = wohnung.vertrag().get();
            int currentYear = (vertrag != null ? vertrag.vertragsDatum().get().getYear() : new Date().getYear())
                    + 1900;
            Double RND = (GND != null && baujahr != null) ? baujahr + GND - currentYear : null;
            if (RND != null && faktor1 != null && faktor2 != null) {
                Double liziV = faktor1;
                Double liziN = faktor1 - ((liziV) / (Math.pow(1 + liziV, RND) - 1) * faktor2);
                int iteration = 1;
                while (Math.abs(liziN - liziV) > 0.005d) {
                    liziV = liziN;
                    liziN = faktor1 - ((liziV) / (Math.pow(1 + liziV, RND) - 1) * faktor2);
                    iteration++;
                }
                // in % umrechnen
                double result = liziN * 100;
                return Double.isNaN(result) ? 0.0d : result;
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Zur Auswertung geeignet?",
            "Ist der Liegenschaftszins geeignet fr Auswertungen?", three().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL)
            .setToolTipText("Ist der Liegenschaftszins geeignet fr Auswertungen?")
            .setProperty(new PropertyAdapter(wohnung.geeignet())).setField(new CheckboxFormField())
            .setLayoutData(five().top(lastLine).create()).create();

}

From source file:org.sakaiproject.tool.gradebook.ui.GradebookDependentBean.java

public boolean getIsExistingConflictScale() {
    isExistingConflictScale = true;/*from   ww  w  . ja v  a2 s . co  m*/
    Gradebook gb = getGradebookManager().getGradebookWithGradeMappings(getGradebookId());
    if (gb != null && gb.getGrade_type() == GradebookService.GRADE_TYPE_LETTER) {
        if ((gb.getSelectedGradeMapping().getGradingScale() != null
                && gb.getSelectedGradeMapping().getGradingScale().getUid().equals("LetterGradeMapping"))
                || (gb.getSelectedGradeMapping().getGradingScale() == null
                        && gb.getSelectedGradeMapping().getName().equals("Letter Grades"))) {
            isExistingConflictScale = false;
            return isExistingConflictScale;
        }
        Set mappings = gb.getGradeMappings();
        for (Iterator iter = mappings.iterator(); iter.hasNext();) {
            GradeMapping gm = (GradeMapping) iter.next();
            if (gm != null) {
                if ((gm.getGradingScale() != null
                        && gm.getGradingScale().getUid().equals("LetterGradePlusMinusMapping"))
                        || (gm.getGradingScale() == null && gm.getName().equals("Letter Grades with +/-"))) {
                    Map defaultMapping = gm.getDefaultBottomPercents();
                    for (Iterator gradeIter = gm.getGrades().iterator(); gradeIter.hasNext();) {
                        String grade = (String) gradeIter.next();
                        Double percentage = (Double) gm.getValue(grade);
                        Double defautPercentage = (Double) defaultMapping.get(grade);
                        if (percentage != null && !percentage.equals(defautPercentage)) {
                            isExistingConflictScale = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    return isExistingConflictScale;
}

From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverter.java

private Double[] checkViscosities(final Double[] eddy) {
    final Double[] eddyRes = new Double[eddy.length];
    final Double lDoubleDefaultViscosity = m_controlModel.getTBMIN();

    for (int i = 0; i < eddy.length; i++) {
        final Double double1 = eddy[i];
        if (double1.equals(0.0)) {
            eddyRes[i] = lDoubleDefaultViscosity * 1000;
        } else {/*from www  .j  a  v a  2s .  c  om*/
            eddyRes[i] = double1;
        }
    }
    return eddyRes;
}

From source file:com.sawyer.advadapters.widget.JSONAdapter.java

/**
 * Determines whether the provided constraint filters out the given item. Subclass to provide
 * you're own logic. It's incorrect to modify the adapter or the contents of the item itself.
 * Any alterations will lead to undefined behavior or crashes. Internally, this method is only
 * ever invoked from a background thread.
 *
 * @param item       The Double item to compare against the constraint
 * @param constraint The constraint used to filter the item
 *
 * @return True if the item is filtered out by the given constraint. False if the item will
 * continue to display in the adapter.//from w w w.j  a v  a2s.c  o m
 */
protected boolean isFilteredOut(Double item, CharSequence constraint) {
    try {
        return !item.equals(Double.valueOf(constraint.toString()));
    } catch (NumberFormatException e) {
        return true;
    }
}

From source file:com.act.lcms.db.io.report.IonAnalysisInterchangeModel.java

/**
 * This function is used to compute log frequency distribution of the ion model vs a metric.
 * @param metric The metric on which the frequency distribution is plotted
 * @return A map of a range to the count of molecules that get bucketed in that range
 *//*from  ww w .  java  2  s  .co m*/
public Map<Pair<Double, Double>, Integer> computeLogFrequencyDistributionOfMoleculeCountToMetric(
        METRIC metric) {
    Map<Pair<Double, Double>, Integer> rangeToHitCount = new HashMap<>();

    // This variable represents the total number of statistics that have zero values.
    Integer countOfZeroStats = 0;

    // This statistic represents the log value of the min statistic.
    Double minLogValue = Double.MAX_VALUE;

    for (ResultForMZ resultForMZ : this.getResults()) {
        for (HitOrMiss molecule : resultForMZ.getMolecules()) {

            Double power = 0.0;

            switch (metric) {
            case TIME:
                power = Math.log10(molecule.getTime());
                break;
            case INTENSITY:
                power = Math.log10(molecule.getIntensity());
                break;
            case SNR:
                power = Math.log10(molecule.getSnr());
                break;
            }

            if (power.equals(Double.NEGATIVE_INFINITY)) {
                // We know the statistic was 0 here.
                countOfZeroStats++;
                break;
            }

            Double floor = Math.floor(power);
            Double lowerBound = Math.pow(10.0, floor);
            Double upperBound = Math.pow(10.0, floor + 1);

            minLogValue = Math.min(minLogValue, lowerBound);
            Pair<Double, Double> key = Pair.of(lowerBound, upperBound);
            rangeToHitCount.compute(key, (k, v) -> (v == null) ? 1 : v + 1);
        }

        // We count the total number of zero statistics and put them in the 0 to minLog metric bucket.
        if (countOfZeroStats > 0) {
            Pair<Double, Double> key = Pair.of(0.0, minLogValue);
            rangeToHitCount.put(key, countOfZeroStats);
        }
    }

    return rangeToHitCount;
}

From source file:org.envirocar.app.activity.ListTracksFragment.java

/**
 * This method requests the current fuel price of a given fuel type from a
 * WPS that caches prices from export.benzinpreis-aktuell.de, calculates the
 * total fuel price using the fuel consumption and length of track and sets
 * the text of the respective <code>Textview</code>.
 * //from   w  w w  .  j a  v  a 2 s  .  c  o m
 * @param fuelCostView
 *            The <code>Textview</code> the fuel price will be written to.
 * @param twoDForm
 *            Used for rounding the fuel price.
 * @param t
 *            the track
 */
private void getEstimatedFuelCost(final TextView fuelCostView, final DecimalFormat twoDForm, Track t) {

    WPSClient.calculateFuelCosts(t, new ResultCallback<Double>() {

        @Override
        public void onResultAvailable(Double result) {
            if (result.equals(Double.NaN)) {
                fuelCostView.setText(R.string.error_calculating_fuel_costs);

                fuelCostView.setTextColor(Color.RED);

            } else {
                fuelCostView
                        .setText(twoDForm.format(result) + " " + getActivity().getString(R.string.euro_sign));
            }
        }
    });

}

From source file:org.sakaiproject.tool.gradebook.ui.InstructorViewBean.java

/**
 * Save the input scores for the user/*from  w  w  w  .  j  av  a2  s  . com*/
 * @throws StaleObjectModificationException
 */
public void saveScoresWithoutConfirmation() throws StaleObjectModificationException {
    if (logger.isInfoEnabled())
        logger.info("saveScores for " + getStudentUid());

    // first, determine which scores were updated
    List updatedGradeRecords = new ArrayList();
    if (getGradebookItems() != null) {
        Iterator itemIter = getGradebookItems().iterator();
        while (itemIter.hasNext()) {
            Object item = itemIter.next();
            if (item instanceof AssignmentGradeRow) {
                AssignmentGradeRow gradeRow = (AssignmentGradeRow) item;
                AssignmentGradeRecord gradeRecord = gradeRow.getGradeRecord();

                if (gradeRecord == null && (gradeRow.getScore() != null || gradeRow.getLetterScore() != null)) {
                    // this is a new grade
                    gradeRecord = new AssignmentGradeRecord(gradeRow.getAssociatedAssignment(), getStudentUid(),
                            null);
                }
                if (gradeRecord != null) {
                    if (getGradeEntryByPoints()) {
                        Double originalScore = null;
                        originalScore = gradeRecord.getPointsEarned();

                        if (originalScore != null) {
                            // truncate to two decimals for more accurate comparison
                            originalScore = new Double(FacesUtil.getRoundDown(originalScore.doubleValue(), 2));
                        }
                        Double newScore = gradeRow.getScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setPointsEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                        }
                    } else if (getGradeEntryByPercent()) {
                        Double originalScore = null;
                        originalScore = gradeRecord.getPercentEarned();

                        if (originalScore != null) {
                            // truncate to two decimals for more accurate comparison
                            originalScore = new Double(FacesUtil.getRoundDown(originalScore.doubleValue(), 2));
                        }
                        Double newScore = gradeRow.getScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setPercentEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                        }

                    } else if (getGradeEntryByLetter()) {

                        String originalScore = gradeRecord.getLetterEarned();
                        String newScore = gradeRow.getLetterScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setLetterEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                        }
                    }
                }
            }
        }
    }

    Set excessiveScores = getGradebookManager().updateStudentGradeRecords(updatedGradeRecords,
            getGradebook().getGrade_type(), getStudentUid());

    if (updatedGradeRecords.size() > 0) {
        getGradebookBean().getEventTrackingService().postEvent("gradebook.updateItemScores",
                "/gradebook/" + getGradebookId() + "/" + updatedGradeRecords.size() + "/" + getAuthzLevel());
    }
}

From source file:org.sakaiproject.tool.gradebook.ui.InstructorViewBean.java

/**
 * Save the input scores for the user//www. ja  v a 2s .c o  m
 * @throws StaleObjectModificationException
 */
public void saveScores() throws StaleObjectModificationException {
    if (logger.isInfoEnabled())
        logger.info("saveScores for " + getStudentUid());

    // first, determine which scores were updated
    List updatedGradeRecords = new ArrayList();
    if (getGradebookItems() != null) {
        Iterator itemIter = getGradebookItems().iterator();
        while (itemIter.hasNext()) {
            Object item = itemIter.next();
            if (item instanceof AssignmentGradeRow) {
                AssignmentGradeRow gradeRow = (AssignmentGradeRow) item;
                AssignmentGradeRecord gradeRecord = gradeRow.getGradeRecord();

                if (gradeRecord == null && (gradeRow.getScore() != null || gradeRow.getLetterScore() != null)) {
                    // this is a new grade
                    gradeRecord = new AssignmentGradeRecord(gradeRow.getAssociatedAssignment(), getStudentUid(),
                            null);
                }
                if (gradeRecord != null) {
                    if (getGradeEntryByPoints()) {
                        Double originalScore = null;
                        originalScore = gradeRecord.getPointsEarned();

                        if (originalScore != null) {
                            // truncate to two decimals for more accurate comparison
                            originalScore = new Double(FacesUtil.getRoundDown(originalScore.doubleValue(), 2));
                        }
                        Double newScore = gradeRow.getScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setPointsEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                            getGradebookBean().getEventTrackingService().postEvent("gradebook.updateItemScore",
                                    "/gradebook/" + getGradebookUid() + "/"
                                            + gradeRecord.getAssignment().getName() + "/"
                                            + gradeRecord.getStudentId() + "/" + gradeRecord.getPointsEarned()
                                            + "/" + getAuthzLevel());
                        }
                    } else if (getGradeEntryByPercent()) {
                        Double originalScore = null;
                        originalScore = gradeRecord.getPercentEarned();

                        if (originalScore != null) {
                            // truncate to two decimals for more accurate comparison
                            originalScore = new Double(FacesUtil.getRoundDown(originalScore.doubleValue(), 2));
                        }
                        Double newScore = gradeRow.getScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setPercentEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                        }

                    } else if (getGradeEntryByLetter()) {

                        String originalScore = gradeRecord.getLetterEarned();
                        String newScore = gradeRow.getLetterScore();
                        if ((originalScore != null && !originalScore.equals(newScore))
                                || (originalScore == null && newScore != null)) {
                            gradeRecord.setLetterEarned(newScore);
                            updatedGradeRecords.add(gradeRecord);
                        }
                    }
                }
            }
        }
    }

    Set excessiveScores = getGradebookManager().updateStudentGradeRecords(updatedGradeRecords,
            getGradebook().getGrade_type(), getStudentUid());

    if (updatedGradeRecords.size() > 0) {
        getGradebookBean().getEventTrackingService().postEvent("gradebook.updateItemScores",
                "/gradebook/" + getGradebookId() + "/" + updatedGradeRecords.size() + "/" + getAuthzLevel());
        String messageKey = (excessiveScores.size() > 0) ? "inst_view_scores_saved_excessive"
                : "inst_view_scores_saved";

        // Let the user know.
        FacesUtil.addMessage(getLocalizedString(messageKey));
    }

}