Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

In this page you can find the example usage for java.math BigDecimal add.

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:jgnash.ui.report.compiled.PayeePieChart.java

private JFreeChart createPieChart(Account a, PieDataset[] data, int index) {
    PiePlot plot = new PiePlot(data[index]);

    // rebuilt each time because they're based on the account's commodity
    NumberFormat valueFormat = CommodityFormat.getFullNumberFormat(a.getCurrencyNode());
    NumberFormat percentFormat = new DecimalFormat("0.0#%");
    defaultLabels = new StandardPieSectionLabelGenerator("{0} = {1}", valueFormat, percentFormat);
    percentLabels = new StandardPieSectionLabelGenerator("{0} = {1}\n{2}", valueFormat, percentFormat);

    plot.setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels);

    plot.setLabelGap(.02);//from   w w w  .  j  a v a 2s. c  o  m
    plot.setInteriorGap(.1);

    BigDecimal thisTotal = BigDecimal.ZERO;
    for (int i = 0; i < data[index].getItemCount(); i++) {
        thisTotal = thisTotal.add((BigDecimal) (data[index].getValue(i)));
    }
    BigDecimal acTotal = a.getTreeBalance(startField.getLocalDate(), endField.getLocalDate()).abs();

    String title = "";
    String subtitle = "";

    // pick an appropriate title(s)
    if (index == 0) {
        title = a.getPathName();
        subtitle = rb.getString("Column.Credit") + " : " + valueFormat.format(thisTotal);
    } else if (index == 1) {
        title = rb.getString("Column.Balance") + " : " + valueFormat.format(acTotal);
        subtitle = rb.getString("Column.Debit") + " : " + valueFormat.format(thisTotal);
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.addSubtitle(new TextTitle(subtitle));
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:com.heliumv.api.inventory.InventoryApi.java

private boolean updateInventurliste(ArtikelDto itemDto, BigDecimal newAmount, Boolean changeAmountTo,
        InventurlisteDto workListeDto) throws NamingException, RemoteException {
    if (!changeAmountTo) {
        BigDecimal oldAmount = workListeDto.getNInventurmenge();
        newAmount = oldAmount.add(newAmount);
    }/*  w  w  w  .  j  a v a2 s. co m*/

    if (newAmount.signum() < 0) {
        respondBadRequest("amount", "<0");
        return false;
    }

    if (newAmount.signum() == 0) {
        inventurCall.removeInventurListe(workListeDto);
    } else {
        if (itemDto.isSeriennrtragend() && newAmount.compareTo(BigDecimal.ONE) > 0) {
            respondBadRequest("serialnr", "amount has to be 1");
            return false;
        }

        workListeDto.setNInventurmenge(newAmount);
        inventurCall.updateInventurliste(workListeDto, false);
    }

    return true;
}

From source file:com.ar.dev.tierra.api.controller.DetalleFacturaController.java

@RequestMapping(value = "/delete/discount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteDiscount(@RequestParam("dni") int dni, @RequestParam("password") String password,
        @RequestBody DetalleFactura detalleFactura) {
    Usuarios user = facadeService.getUsuariosDAO().findUsuarioByDNI(dni);
    boolean permiso = passwordEncoder.matches(password, user.getPassword());
    if (permiso) {
        if (user.getRoles().getIdRol() == 1 || user.getRoles().getIdRol() == 6) {
            detalleFactura.setDescuentoDetalle(BigDecimal.ZERO);
            BigDecimal monto = detalleFactura.getProducto().getPrecioVenta()
                    .multiply(BigDecimal.valueOf(detalleFactura.getCantidadDetalle()));
            detalleFactura.setTotalDetalle(monto);
            facadeService.getDetalleFacturaDAO().update(detalleFactura);
            List<DetalleFactura> detallesFactura = facadeService.getDetalleFacturaDAO()
                    .facturaDetalle(detalleFactura.getFactura().getIdFactura());
            BigDecimal sumMonto = new BigDecimal(BigInteger.ZERO);
            Factura factura = facadeService.getFacturaDAO()
                    .searchById(detalleFactura.getFactura().getIdFactura());
            for (DetalleFactura detailList : detallesFactura) {
                sumMonto = sumMonto.add(detailList.getTotalDetalle());
            }/*from ww  w . ja v a  2  s  .  c om*/
            factura.setTotal(sumMonto);
            factura.setFechaModificacion(new Date());
            factura.setUsuarioModificacion(user.getIdUsuario());
            facadeService.getFacturaDAO().update(factura);
            JsonResponse msg = new JsonResponse("Success", "Descuento eliminado con exito.");
            return new ResponseEntity<>(msg, HttpStatus.OK);
        } else {
            JsonResponse msg = new JsonResponse("Error",
                    "No tienes los permisos necesarios para realizar esta operacion.");
            return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST);
        }
    } else {
        JsonResponse msg = new JsonResponse("Error",
                "No tienes los permisos necesarios para realizar esta operacion.");
        return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.evaluator.util.KeyphrasePerformanceCounter.java

public Double getMeanAveragePrecision() {
    BigDecimal meanAveragePrecision = new BigDecimal("0.0");
    for (FilePerformance filePerformance : fileName2performanceMap.values()) {
        meanAveragePrecision = meanAveragePrecision.add(filePerformance.calculateAveragePrecision());
    }//from  w  w w. ja v a2 s  .  c o  m
    if (fileName2performanceMap.size() == 0) {
        return 0d;
    }
    meanAveragePrecision = meanAveragePrecision.divide(
            new BigDecimal(String.valueOf(fileName2performanceMap.size())), NBR_FLOATING_POINTS,
            RoundingMode.UP);
    return meanAveragePrecision.doubleValue();
}

From source file:net.sourceforge.fenixedu.domain.credits.util.DepartmentCreditsPoolBean.java

protected BigDecimal setExecutionCourseUnitCredit(DepartmentExecutionCourse departmentExecutionCourse,
        boolean canEditUnitValue, BigDecimal newAssignedCredits, Boolean shared) {
    if (canEditUnitValue) {
        BigDecimal newExecutionCourseCLE = departmentExecutionCourse.getDepartmentEffectiveLoad()
                .multiply(departmentExecutionCourse.getUnitCreditValue());
        newAssignedCredits = newAssignedCredits.add(newExecutionCourseCLE);
        if (departmentExecutionCourse.executionCourse.getUnitCreditValue()
                .compareTo(departmentExecutionCourse.getUnitCreditValue()) != 0
                || StringUtils.equals(departmentExecutionCourse.executionCourse.getUnitCreditValueNotes(),
                        departmentExecutionCourse.getUnitCreditJustification())) {
            departmentExecutionCourse.executionCourse.setUnitCreditValue(
                    departmentExecutionCourse.getUnitCreditValue(),
                    departmentExecutionCourse.getUnitCreditJustification());
        }// w  ww .ja va 2 s. c o m
    } else {
        BigDecimal oldExecutionCourseCLE = departmentExecutionCourse.getDepartmentEffectiveLoad()
                .multiply(departmentExecutionCourse.executionCourse.getUnitCreditValue());
        newAssignedCredits = newAssignedCredits.add(oldExecutionCourseCLE);
    }
    return newAssignedCredits;
}

From source file:com.autentia.intra.manager.billing.BillManager.java

/**
 * Account DAO */*from  w ww.j  av a  2  s .  c  o  m*/
 */

public List<BillBreakDown> getAllBitacoreBreakDowns(Date start, Date end, Set<ProjectRole> roles,
        Set<ProjectCost> costes) {

    List<BillBreakDown> desgloses = new ArrayList<BillBreakDown>();

    ActivityDAO activityDAO = ActivityDAO.getDefault();
    ActivitySearch actSearch = new ActivitySearch();
    actSearch.setBillable(new Boolean(true));
    actSearch.setStartStartDate(start);
    actSearch.setEndStartDate(end);

    List<Activity> actividadesTotal = new ArrayList<Activity>();
    Hashtable user_roles = new Hashtable();

    for (ProjectRole proyRole : roles) {
        actSearch.setRole(proyRole);
        List<Activity> actividades = activityDAO.search(actSearch, new SortCriteria("startDate", false));
        actividadesTotal.addAll(actividades);
    }

    for (Activity act : actividadesTotal) {
        String key = act.getRole().getId().toString() + act.getUser().getId().toString();

        if (!user_roles.containsKey(key)) {
            Hashtable value = new Hashtable();
            value.put("ROLE", act.getRole());
            value.put("USER", act.getUser());
            user_roles.put(key, value);
        }
    }

    Enumeration en = user_roles.keys();

    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        Hashtable pair = (Hashtable) user_roles.get(key);
        actSearch.setBillable(new Boolean(true));
        actSearch.setStartStartDate(start);
        actSearch.setEndStartDate(end);

        ProjectRole pR = (ProjectRole) pair.get("ROLE");
        User u = (User) pair.get("USER");
        actSearch.setRole(pR);
        actSearch.setUser(u);
        List<Activity> actividadesUsuarioRol = activityDAO.search(actSearch,
                new SortCriteria("startDate", false));

        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Imputaciones (usuario - rol): " + u.getName() + " - " + pR.getName());
        brd.setAmount(pR.getCostPerHour());
        brd.setIva(new BigDecimal(ConfigurationUtil.getDefault().getIva()));
        BigDecimal unitsTotal = new BigDecimal(0);
        for (Activity act : actividadesUsuarioRol) {
            BigDecimal unitsActual = new BigDecimal(act.getDuration());
            unitsActual = unitsActual.divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
            unitsTotal = unitsTotal.add(unitsActual);
        }
        brd.setUnits(unitsTotal);
        brd.setSelected(true);
        desgloses.add(brd);
    }

    for (ProjectCost proyCost : costes) {
        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Coste: " + proyCost.getName());
        brd.setUnits(new BigDecimal(1));
        brd.setAmount(proyCost.getCost());
        brd.setIva(new BigDecimal(ConfigurationUtil.getDefault().getIva()));
        brd.setSelected(true);
        desgloses.add(brd);
    }

    return desgloses;

}

From source file:net.sourceforge.fenixedu.domain.residence.StudentsPerformanceReport.java

private int getApprovedGradeValuesSum(final Student student) {
    Collection<ICurriculumEntry> entries = student.getLastActiveRegistration()
            .getCurriculum(getExecutionSemester().getEndDateYearMonthDay().toDateTimeAtCurrentTime(),
                    getExecutionSemester().getExecutionYear(), null)
            .getCurriculumEntries();//www .  jav a 2 s.  co  m
    BigDecimal sum = new BigDecimal(0d);

    for (final ICurriculumEntry entry : entries) {
        if (entry.getGrade().isNumeric()) {
            final BigDecimal weigth = entry.getWeigthForCurriculum();
            if (GradeScale.TYPE20.equals(entry.getGrade().getGradeScale())) {
                sum = sum.add(entry.getGrade().getNumericValue());
            }
        }
    }

    return sum.intValue();
}

From source file:edu.macalester.tagrelatedness.KendallsCorrelation.java

public BigDecimal get(BigDecimal n) {

    // Make sure n is a positive number

    if (n.compareTo(ZERO) <= 0) {
        throw new IllegalArgumentException();
    }//w ww. j a va 2  s . c  o m

    BigDecimal initialGuess = getInitialApproximation(n);
    trace("Initial guess " + initialGuess.toString());
    BigDecimal lastGuess = ZERO;
    BigDecimal guess = new BigDecimal(initialGuess.toString());

    // Iterate

    iterations = 0;
    boolean more = true;
    while (more) {
        lastGuess = guess;
        guess = n.divide(guess, scale, BigDecimal.ROUND_HALF_UP);
        guess = guess.add(lastGuess);
        guess = guess.divide(TWO, scale, BigDecimal.ROUND_HALF_UP);
        trace("Next guess " + guess.toString());
        error = n.subtract(guess.multiply(guess));
        if (++iterations >= maxIterations) {
            more = false;
        } else if (lastGuess.equals(guess)) {
            more = error.abs().compareTo(ONE) >= 0;
        }
    }
    return guess;

}

From source file:com.devnexus.ting.web.controller.RegisterController.java

private BigDecimal getTotal(RegistrationDetails registerForm) {
    BigDecimal total = BigDecimal.ZERO;

    for (TicketOrderDetail order : registerForm.getOrderDetails()) {

        total = total.add(getOrderPrice(order));
    }/*from ww w  . j a  va 2 s  . com*/

    return total.setScale(2);
}

From source file:com.dnsoft.inmobiliaria.controllers.ConsultaCCPropietariosController.java

void saldos() {

    DecimalFormat formatter = new DecimalFormat("###,###,###.00");
    BigDecimal saldoPesos = new BigDecimal(BigInteger.ZERO);
    BigDecimal saldoDolares = new BigDecimal(BigInteger.ZERO);
    ;/* w ww . j  av  a  2s .com*/

    for (Propietario propietario : listPropietarios) {
        CCPropietario ccPesos = cCPropietarioDAO.findUltimoMovimiento(Moneda.PESOS, propietario);
        if (ccPesos != null) {
            saldoPesos = saldoPesos.add(ccPesos.getSaldo());
        }
        CCPropietario ccDolares = cCPropietarioDAO.findUltimoMovimiento(Moneda.DOLARES, propietario);
        if (ccDolares != null) {
            saldoDolares = saldoDolares.add(ccDolares.getSaldo());
        }
    }
    view.txtDolares.setText(formatter.format(saldoDolares));
    view.txtPesos.setText(formatter.format(saldoPesos));

}