Example usage for java.math MathContext DECIMAL128

List of usage examples for java.math MathContext DECIMAL128

Introduction

In this page you can find the example usage for java.math MathContext DECIMAL128.

Prototype

MathContext DECIMAL128

To view the source code for java.math MathContext DECIMAL128.

Click Source Link

Document

A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of RoundingMode#HALF_EVEN HALF_EVEN , the IEEE 754R default.

Usage

From source file:org.fede.calculator.IndexTest.java

public void youIndexARS() {

    MoneyAmountSeries dollar = Util.readSeries("ahorros-dolar.json");
    MoneyAmountSeries gold = Util.readSeries("ahorros-oro.json");
    MoneyAmountSeries peso = Util.readSeries("ahorros-peso.json");

    final String target = "USD";

    MoneyAmountSeries proportionInUSD = new SortedMapMoneyAmountSeries("USD");

    YearMonth start = dollar.getFrom().min(gold.getFrom());

    final YearMonth end = dollar.getTo().max(gold.getTo());

    final MoneyAmount oneUSD = new MoneyAmount(BigDecimal.ONE, "USD");
    final MoneyAmount oneARS = getForeignExchange(oneUSD.getCurrency(), "ARS").exchange(oneUSD, "ARS",
            start.getYear(), start.getMonth());
    final MoneyAmount oneXAU = getForeignExchange(oneUSD.getCurrency(), "XAU").exchange(oneUSD, "XAU",
            start.getYear(), start.getMonth());

    while (start.compareTo(end) <= 0) {
        MoneyAmount usdSavings = dollar.getAmountOrElseZero(start);
        MoneyAmount arsSavings = peso.getAmountOrElseZero(start);
        MoneyAmount xauSavings = gold.getAmountOrElseZero(start);

        usdSavings = getForeignExchange(usdSavings.getCurrency(), target).exchange(usdSavings, target,
                start.getYear(), start.getMonth());
        xauSavings = getForeignExchange(xauSavings.getCurrency(), target).exchange(xauSavings, target,
                start.getYear(), start.getMonth());
        arsSavings = getForeignExchange(arsSavings.getCurrency(), target).exchange(arsSavings, target,
                start.getYear(), start.getMonth());

        final MoneyAmount totalSavings = usdSavings.add(xauSavings).add(arsSavings);

        if (totalSavings.getAmount().signum() > 0) {

            BigDecimal usdSavingsPercent = usdSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);
            BigDecimal arsSavingsPercent = arsSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);
            BigDecimal xauSavingsPercent = xauSavings.getAmount().divide(totalSavings.getAmount(),
                    MathContext.DECIMAL128);

            System.out.print(MessageFormat.format("{0}{1}\t{2}\t{3}\t{4}\t", String.valueOf(start.getYear()),
                    start.getMonth(), usdSavingsPercent, arsSavingsPercent, xauSavingsPercent));

            BigDecimal usdPrice = getForeignExchange(oneUSD.getCurrency(), target)
                    .exchange(oneUSD, target, start.getYear(), start.getMonth()).getAmount();
            BigDecimal arsPrice = getForeignExchange(oneARS.getCurrency(), target)
                    .exchange(oneARS, target, start.getYear(), start.getMonth()).getAmount();
            BigDecimal xauPrice = getForeignExchange(oneXAU.getCurrency(), target)
                    .exchange(oneXAU, target, start.getYear(), start.getMonth()).getAmount();

            System.out.print(MessageFormat.format("{0}\t{1}\t{2}\t", usdPrice, arsPrice, xauPrice));

            BigDecimal youIndex = usdPrice.multiply(usdSavingsPercent).add(arsPrice.multiply(arsSavingsPercent))
                    .add(xauPrice.multiply(xauSavingsPercent));

            // final MoneyAmount index = new MoneyAmount(youIndex, target);

            //BigDecimal adjustedYouIndex = USD_INFLATION.adjust(index, start.getYear(), start.getMonth(),
            //        USD_INFLATION.getTo().getYear(), USD_INFLATION.getTo().getMonth()).getAmount();

            // System.out.println(MessageFormat.format("{0}\t{1}", youIndex, adjustedYouIndex));

            proportionInUSD.putAmount(start, new MoneyAmount(youIndex, target));
        }//from   w  ww .j  a  v  a2  s  .  co m
        start = start.next();
    }
    //proportionInUSD.forEach(new MoneyAmountProcessor() {
    //   @Override
    //  public void process(int year, int month, MoneyAmount amount) throws NoSeriesDataFoundException {
    //System.out.println(MessageFormat.format("{0}{1}\t{2}", String.valueOf(year), month, amount.getAmount()));
    //}
    //});
}

From source file:de.appsolve.padelcampus.controller.bookings.BookingsPayMillController.java

private ModelAndView handlePost(ModelAndView mav, Booking booking, String token) {
    if (StringUtils.isEmpty(token)) {
        mav.addObject("error", msg.get("MissingRequiredPaymentToken"));
        return mav;
    }//from w  w w .  jav a  2 s .c  o  m
    if (booking.getConfirmed()) {
        mav.addObject("error", msg.get("BookingAlreadyConfirmed"));
        return mav;
    }
    try {
        PayMillConfig config = payMillConfigDAO.findFirst();
        PaymillContext paymillContext = new PaymillContext(config.getPrivateApiKey());
        TransactionService transactionService = paymillContext.getTransactionService();
        BigDecimal amount = booking.getAmount().multiply(new BigDecimal("100"), MathContext.DECIMAL128);
        Transaction transaction = transactionService.createWithToken(token, amount.intValue(),
                booking.getCurrency().toString(), getBookingDescription(booking));
        if (!transaction.getStatus().equals(Transaction.Status.CLOSED)) {
            throw new Exception("Payment Backend Returned Unexpected Status: [Code: " + transaction.getStatus()
                    + ", Response Code: " + transaction.getResponseCode() + ", Response Code Detail: "
                    + transaction.getResponseCodeDetail() + "]");
        }
        booking.setPaymentConfirmed(true);
        bookingDAO.saveOrUpdate(booking);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        mav.addObject("error", e.getMessage());
        return mav;
    }
    return BookingsController.getRedirectToSuccessView(booking);
}

From source file:dk.clanie.money.Money.java

/**
 * Divide evenly into parts.//from   ww  w .java  2  s. c o  m
 * 
 * Divides an amount into parts of approximately the same size while
 * ensuring that the sum of all the parts equals the whole.
 * <p>
 * Parts of unequal size will be distributed evenly in the returned array.
 * <p>
 * For example, if asked to divede 20 into 6 parts the result will be {3.33,
 * 3.34, 3.33, 3.33, 3.34, 3.33}
 * 
 * @param parts -
 *            number of parts
 * @return Money[] with the parts
 */
public Money[] divideEvenlyIntoParts(int parts) {
    Money[] res = new Money[parts];
    final BigDecimal bdParts = new BigDecimal(parts);
    final MathContext mc = MathContext.DECIMAL128;
    BigDecimal sumOfPreviousParts = BigDecimal.ZERO;
    for (int i = 0; i < parts; i++) {
        Money part = new Money();
        BigDecimal sumOfParts = amount.multiply(new BigDecimal(i + 1));
        sumOfParts = sumOfParts.divide(bdParts, mc);
        sumOfParts = sumOfParts.setScale(amount.scale(), mc.getRoundingMode());
        part.amount = sumOfParts.subtract(sumOfPreviousParts);
        sumOfPreviousParts = sumOfParts;
        part.currency = currency;
        res[i] = part;
    }
    return res;
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public List<TimeSlot> getTimeSlotsForDate(LocalDate selectedDate, List<CalendarConfig> allCalendarConfigs,
        List<Booking> existingBookings, Boolean onlyFutureTimeSlots, Boolean preventOverlapping)
        throws CalendarConfigException {

    List<CalendarConfig> calendarConfigs = calendarConfigUtil.getCalendarConfigsMatchingDate(allCalendarConfigs,
            selectedDate);/*from w  w w.  j  a va2s.  co  m*/
    Iterator<CalendarConfig> iterator = calendarConfigs.iterator();
    while (iterator.hasNext()) {
        CalendarConfig calendarConfig = iterator.next();
        if (isHoliday(selectedDate, calendarConfig)) {
            iterator.remove();
        }
    }

    List<TimeSlot> timeSlots = new ArrayList<>();
    if (calendarConfigs.size() > 0) {
        LocalDate today = new LocalDate(DEFAULT_TIMEZONE);

        //sort all calendar configurations for selected date by start time
        Collections.sort(calendarConfigs);

        CalendarConfig previousConfig = null;
        LocalDateTime time = null;
        LocalDateTime now = new LocalDateTime(DEFAULT_TIMEZONE);

        //generate list of bookable time slots
        int i = 0;
        for (CalendarConfig config : calendarConfigs) {
            i++;
            LocalDateTime startDateTime = getLocalDateTime(selectedDate, config.getStartTime());
            if (time == null) {
                //on first iteration
                time = startDateTime;
            } else if (!time.plusMinutes(previousConfig.getMinInterval()).equals(startDateTime)) {
                //reset basePriceLastConfig as this is a non contiguous offer
                previousConfig = null;
                time = startDateTime;
            }
            LocalDateTime endDateTime = getLocalDateTime(selectedDate, config.getEndTime());
            while (time.plusMinutes(config.getMinDuration()).compareTo(endDateTime) <= 0) {
                BigDecimal pricePerMinDuration;
                if (previousConfig == null) {
                    pricePerMinDuration = config.getBasePrice();
                } else {
                    BigDecimal previousConfigBasePricePerMinute = getPricePerMinute(previousConfig);
                    pricePerMinDuration = previousConfigBasePricePerMinute
                            .multiply(new BigDecimal(previousConfig.getMinInterval()), MathContext.DECIMAL128);
                    BigDecimal basePricePerMinute = getPricePerMinute(config);
                    pricePerMinDuration = pricePerMinDuration.add(basePricePerMinute.multiply(
                            new BigDecimal(config.getMinDuration() - previousConfig.getMinInterval()),
                            MathContext.DECIMAL128));
                    previousConfig = null;
                }
                pricePerMinDuration = pricePerMinDuration.setScale(2, RoundingMode.HALF_EVEN);
                if (onlyFutureTimeSlots) {
                    if (selectedDate.isAfter(today) || time.isAfter(now)) {
                        addTimeSlot(timeSlots, time, config, pricePerMinDuration);
                    }
                } else {
                    addTimeSlot(timeSlots, time, config, pricePerMinDuration);
                }
                time = time.plusMinutes(config.getMinInterval());
            }
            //make sure to display the last min interval of the day
            if (config.getMinInterval() < config.getMinDuration() && i == calendarConfigs.size()) {
                if (time.plusMinutes(config.getMinInterval()).compareTo(endDateTime) <= 0) {
                    addTimeSlot(timeSlots, time, config, null);
                }
            }
            previousConfig = config;
        }
        //sort time slots by time
        Collections.sort(timeSlots);

        //decrease court count for every blocking booking
        for (TimeSlot timeSlot : timeSlots) {
            checkForBookedCourts(timeSlot, existingBookings, preventOverlapping);
        }
    }
    return timeSlots;
}

From source file:com.marcosanta.service.impl.KalturaServiceImpl.java

@Override
public ReporteGeneralGranulado calculoReporteGlobal(Date fechaInicio, Date fechaFin, String valorUnitarioTam,
        String valorUnitarioMIN, String tipoReporte, String cuenta, String unidad, String fabrica,
        int novistos) {
    ChartSeries chartStorage = new ChartSeries();
    ChartSeries chartTiempoVisto = new ChartSeries();
    ChartSeries chartProductividad = new ChartSeries();
    CartesianChartModel graficaStorage = new CartesianChartModel();
    CartesianChartModel graficaTiempoVisto = new CartesianChartModel();
    CartesianChartModel graficaProductividad = new CartesianChartModel();
    Map<Object, Number> mapaSerieTamanio = new HashMap<>();
    Map<Object, Number> mapaSerieProductividad = new HashMap<>();
    Map<Object, Number> mapaSerieTiempoVisto = new HashMap<>();
    List<CatReporteXls> reporteGlobal = new ArrayList<>();
    List<SistemaSubReporte> listaTemportalSubReporteGlobal = new ArrayList<>();
    if (fechaInicio != null && fechaFin != null) {
        if (cuenta != null && unidad == null && fabrica == null) {
            listaTemportalSubReporteGlobal = consultasBDService.findReportByFechaCorteNivelUnidad(fechaInicio,
                    fechaFin, tipoReporte, cuenta, novistos);
        } else if (cuenta != null && unidad != null) {
            listaTemportalSubReporteGlobal = consultasBDService.findReportByFechaCorteNivelFabrica(fechaInicio,
                    fechaFin, tipoReporte, cuenta, unidad, novistos);
        } else if (cuenta != null && fabrica != null) {
            listaTemportalSubReporteGlobal = consultasBDService.findSubReportByFechaCorteNivelPrograma(
                    fechaInicio, fechaFin, tipoReporte, cuenta, fabrica, novistos);
        } else {/*www . j ava 2  s . c o  m*/
            listaTemportalSubReporteGlobal = consultasBDService.findSubReporteByFechasAndTipo(fechaInicio,
                    fechaFin, tipoReporte, novistos);
        }
    } else {
        if (cuenta != null && unidad == null && fabrica == null) {
            listaTemportalSubReporteGlobal = consultasBDService.findReportNivelUnidad(tipoReporte, cuenta,
                    novistos);
        } else if (cuenta != null && unidad != null) {
            listaTemportalSubReporteGlobal = consultasBDService.findReportNivelFabrica(tipoReporte, cuenta,
                    unidad, novistos);
        } else if (cuenta != null && fabrica != null) {
            listaTemportalSubReporteGlobal = consultasBDService.findReportNivelPrograma(tipoReporte, cuenta,
                    fabrica, novistos);
        } else {
            listaTemportalSubReporteGlobal = consultasBDService.findSubReporteByTipo(tipoReporte, novistos);
        }
    }
    if (!listaTemportalSubReporteGlobal.isEmpty()) {
        for (SistemaSubReporte ssr : listaTemportalSubReporteGlobal) {
            if (reporteGlobal.contains(new CatReporteXls(ssr.getNombre()))) {
                CatReporteXls caRepTmp = reporteGlobal
                        .get(reporteGlobal.indexOf(new CatReporteXls(ssr.getNombre())));
                caRepTmp.setMinVistos(caRepTmp.getMinVistos().add(new BigDecimal(ssr.getTiempoVisto())));
                caRepTmp.setDuration(caRepTmp.getDuration().add(new BigDecimal(ssr.getDuracion())));
                caRepTmp.setTamanio(caRepTmp.getTamanio().add(new BigDecimal(ssr.getTamanio())));
                caRepTmp.setTamUni(caRepTmp.getTamUni()
                        .add(new BigDecimal((ssr.getTamanio() * Double.parseDouble(valorUnitarioTam)))));
                caRepTmp.setMinVisUni(caRepTmp.getMinVisUni()
                        .add(new BigDecimal((ssr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)))));
                if (caRepTmp.getTotalEntrys().longValue() < ssr.getTotalEntrys()) {
                    caRepTmp.setTotalEntrys(new BigDecimal(ssr.getTotalEntrys()));
                }
                mapaSerieTamanio.put(ssr.getNombre(),
                        mapaSerieTamanio.get(ssr.getNombre()).doubleValue() + ssr.getTamanio());
                mapaSerieTiempoVisto.put(ssr.getNombre(),
                        mapaSerieTiempoVisto.get(ssr.getNombre()).longValue() + ssr.getTiempoVisto());
            } else {
                reporteGlobal.add(new CatReporteXls(ssr.getNombre(), new BigDecimal(ssr.getTiempoVisto()),
                        new BigDecimal(ssr.getTamanio()), new BigDecimal(ssr.getDuracion()),
                        ssr.getFechaCorte(),
                        new BigDecimal(ssr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)),
                        new BigDecimal(ssr.getTamanio() * Double.parseDouble(valorUnitarioTam)),
                        new BigDecimal(ssr.getTotalEntrys())));
                mapaSerieTamanio.put(ssr.getNombre(), ssr.getTamanio());
                mapaSerieTiempoVisto.put(ssr.getNombre(), ssr.getTiempoVisto());
            }
        }
    }
    int cortes = 1;
    mapaSerieTamanio = new HashMap<>();
    if (fechaInicio != null && fechaFin != null) {
        cortes = consultasBDService.findCorteByFechaSubReporte(fechaInicio, fechaFin).size();
    } else {
        cortes = consultasBDService.findCorteB().size();
    }

    for (CatReporteXls crxls : reporteGlobal) {
        crxls.setTamanio(crxls.getTamanio().divide(new BigDecimal(cortes), MathContext.DECIMAL128));
        crxls.setTamUni(crxls.getTamUni().divide(new BigDecimal(cortes), MathContext.DECIMAL128));
        mapaSerieTamanio.put(crxls.getNombre(), crxls.getTamanio());
        BigDecimal prod;

        if (crxls.getTamUni().compareTo(BigDecimal.ZERO) == 0) {
            prod = new BigDecimal(-1);
        } else {
            prod = crxls.getMinVisUni().subtract(crxls.getTamUni());
            prod = prod.divide(crxls.getTamUni(), MathContext.DECIMAL128);
        }
        mapaSerieProductividad.put(crxls.getNombre(), prod);
    }
    chartProductividad.setData(mapaSerieProductividad);
    chartStorage.setData(mapaSerieTamanio);
    chartTiempoVisto.setData(mapaSerieTiempoVisto);
    graficaProductividad.addSeries(chartProductividad);
    graficaStorage.addSeries(chartStorage);
    graficaTiempoVisto.addSeries(chartTiempoVisto);
    ReporteGeneralGranulado repGenGra = new ReporteGeneralGranulado(reporteGlobal, graficaStorage,
            graficaTiempoVisto, graficaProductividad);
    return repGenGra;
}

From source file:com.idylwood.utils.MathUtils.java

private final static double varianceSlow(final double[] data) {
    BigDecimal mean = new BigDecimal(0);
    for (double x : data)
        mean = mean.add(new BigDecimal(x), MathContext.UNLIMITED);
    mean = mean.divide(new BigDecimal(data.length), MathContext.UNLIMITED);
    //mean = new BigDecimal(mean(data));
    BigDecimal ret = new BigDecimal(0);
    for (double x : data) {
        //BigDecimal summand = ret.add(new BigDecimal(x),MathContext.UNLIMITED);
        BigDecimal summand = new BigDecimal(x).subtract(mean, MathContext.UNLIMITED);
        ret = ret.add(summand.pow(2));/* ww  w.j a v a2s. co m*/
    }
    ret = ret.divide(new BigDecimal(data.length - 1), MathContext.DECIMAL128);
    return ret.doubleValue();
}

From source file:br.msf.commons.util.AbstractDateUtils.java

public static BigDecimal getDifferenceInDays(final Object date1, final Object date2,
        final boolean ignoreTimeInfo) {
    ArgumentUtils.rejectIfAnyNull(date1, date2);

    Calendar c1 = toUtcCalendar(date1);
    Calendar c2 = toUtcCalendar(date2);
    if (ignoreTimeInfo) {
        c1 = getTimeTruncatedInternal(c1);
        c2 = getTimeTruncatedInternal(c2);
    }//from ww  w.  j a va 2s.c o m
    final long l1 = c1.getTimeInMillis();
    final long l2 = c2.getTimeInMillis();
    BigDecimal res;
    if (l1 > l2) {
        res = new BigDecimal(l1 - l2);
    } else {
        res = new BigDecimal(l2 - l1);
    }
    return NumberUtils.round(res.divide(MILLISECS_PER_DAY, MathContext.DECIMAL128), 2);
}

From source file:com.marcosanta.service.impl.KalturaServiceImpl.java

@Override
public ReporteGeneralGranulado reporteEntrysGranulado(Date fechaInicio, Date fechaFin, String valorUnitarioTam,
        String valorUnitarioMIN, String tipoReporte, String cuenta, String unidad, String fabrica,
        String programa, int novistos) {
    System.out.println(programa + " " + fabrica + " " + unidad + " " + cuenta + " ");
    ChartSeries chartStorage = new ChartSeries();
    ChartSeries chartTiempoVisto = new ChartSeries();
    ChartSeries chartProductividad = new ChartSeries();
    CartesianChartModel graficaStorage = new CartesianChartModel();
    CartesianChartModel graficaTiempoVisto = new CartesianChartModel();
    CartesianChartModel graficaProductividad = new CartesianChartModel();
    Map<Object, Number> mapaSerieTamanio = new HashMap<>();
    Map<Object, Number> mapaSerieTiempoVisto = new HashMap<>();
    Map<Object, Number> mapaSerieProductividad = new HashMap<>();
    List<SistemaReporte> listaTemporalReporte = new ArrayList<>();
    if (fechaInicio != null && fechaFin != null) {
        if (novistos == 0) {
            listaTemporalReporte = this.consultasBDService.findReportByFechaCorteNivelPrograma(fechaInicio,
                    fechaFin, unidad, fabrica, programa);
        } else {//from w  w  w.j a va 2 s  . co  m
            listaTemporalReporte = this.consultasBDService.findReportByFechaCorteNivelPrograma2(fechaInicio,
                    fechaFin, unidad, fabrica, programa);
        }
    } else {
        if (novistos == 0) {
            listaTemporalReporte = this.consultasBDService.findReportByNivelPrograma(unidad, fabrica, programa);
        } else {
            listaTemporalReporte = this.consultasBDService.findReportByNivelPrograma2(unidad, fabrica,
                    programa);
        }
    }
    List<CatReporteXls> reporteTemporal = new ArrayList<>();
    List<CatReporteXlsEntry> reporteTemporalGrafica = new ArrayList<>();
    for (SistemaReporte sr : listaTemporalReporte) {
        if (reporteTemporal.contains(new CatReporteXls(sr.getEntryId()))) {
            CatReporteXls caRepTmp2 = reporteTemporal
                    .get(reporteTemporal.indexOf(new CatReporteXls(sr.getEntryId())));
            caRepTmp2.setMinVistos(caRepTmp2.getMinVistos().add(new BigDecimal(sr.getTiempoVisto())));
            caRepTmp2.setTamanio((caRepTmp2.getTamanio()
                    .add(new BigDecimal((sr.getTamanio().doubleValue() / 1028) / 1028))));
            caRepTmp2.setTamUni(caRepTmp2.getTamUni().add(new BigDecimal(
                    ((sr.getTamanio().doubleValue() / 1028) / 1028) * Double.parseDouble(valorUnitarioTam))));
            caRepTmp2.setMinVisUni(caRepTmp2.getMinVisUni()
                    .add(new BigDecimal((sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)))));
            //                 caRepTmp2.setTotalEntrys(1L+caRepTmp2.getTotalEntrys());
            //                 System.out.println(caRepTmp2.getTotalEntrys());
            //                 System.out.println(caRepTmp2.getTamanio()+" "+caRepTmp2.getNombre());

        } else {
            reporteTemporal.add(new CatReporteXls(sr.getNombre(), sr.getEntryId(), sr.getNombreFabrica(),
                    sr.getNombrePrograma(), cuenta, sr.getNombre(), sr.getNombreUnidad(),
                    new BigDecimal(((sr.getTamanio().doubleValue() / 1028) / 1028)),
                    new BigDecimal(sr.getDuracion()), new BigDecimal(sr.getTiempoVisto()), sr.getFechaCorte(),
                    sr.getFechaCreacion(),
                    new BigDecimal(sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)),
                    new BigDecimal(((sr.getTamanio().doubleValue() / 1028) / 1028)
                            * Double.parseDouble(valorUnitarioTam)),
                    new BigDecimal(1L)));
        }
        if (reporteTemporalGrafica.contains(new CatReporteXlsEntry(sr.getFechaCorte()))) {
            CatReporteXlsEntry caRepTmp = reporteTemporalGrafica
                    .get(reporteTemporalGrafica.indexOf(new CatReporteXlsEntry(sr.getFechaCorte())));
            caRepTmp.setTotalEntrys(caRepTmp.getTotalEntrys() + 1L);
            caRepTmp.setTamanio(((sr.getTamanio().doubleValue() / 1028) / 1028) + caRepTmp.getTamanio());
            caRepTmp.setMinVistos(sr.getTiempoVisto() + caRepTmp.getMinVistos());
            caRepTmp.setMinVisUni(
                    (sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN)) + caRepTmp.getMinVisUni());
            caRepTmp.setTamUni((sr.getTamanio() * Double.parseDouble(valorUnitarioTam)) + caRepTmp.getTamUni());
            mapaSerieTamanio.put(sr.getFechaCorte(), caRepTmp.getTamanio());
            mapaSerieTiempoVisto.put(sr.getFechaCorte(), caRepTmp.getMinVistos());
        } else {
            reporteTemporalGrafica.add(new CatReporteXlsEntry(sr.getEntryId(), sr.getNombreUnidad(),
                    sr.getNombreFabrica(), sr.getNombrePrograma(), cuenta, sr.getNombre(), sr.getTiempoVisto(),
                    ((sr.getTamanio().doubleValue() / 1028) / 1028), Long.parseLong(sr.getDuracion() + ""),
                    sr.getFechaCorte(), sr.getFechaCreacion(),
                    sr.getTiempoVisto() * Double.parseDouble(valorUnitarioMIN),
                    sr.getTamanio() * Double.parseDouble(valorUnitarioTam), 1L));

            mapaSerieTamanio.put(sr.getFechaCorte(), ((sr.getTamanio().doubleValue() / 1028) / 1028));
            mapaSerieTiempoVisto.put(sr.getFechaCorte(), sr.getTiempoVisto());
        }

    }
    int cortes = 1;
    //        mapaSerieTamanio = new HashMap<>();
    if (fechaInicio != null && fechaFin != null) {
        cortes = consultasBDService.findCorteByFecha(fechaInicio, fechaFin).size();
    } else {
        cortes = consultasBDService.findCorteB().size();
    }

    for (CatReporteXlsEntry crtsxx : reporteTemporalGrafica) {
        BigDecimal prod;
        if (crtsxx.getTamUni() == 0) {
            prod = new BigDecimal(-1);
        } else {
            prod = new BigDecimal(crtsxx.getMinVisUni() - crtsxx.getTamUni());
            prod = prod.divide(new BigDecimal(crtsxx.getTamUni()), MathContext.DECIMAL128);
        }
        mapaSerieProductividad.put(crtsxx.getFechaCorte(), prod);
    }

    for (CatReporteXls crxls : reporteTemporal) {
        crxls.setTamanio(crxls.getTamanio().divide(new BigDecimal(cortes), MathContext.DECIMAL128));
        crxls.setTamUni(crxls.getTamUni().divide(new BigDecimal(cortes), MathContext.DECIMAL128));

    }
    //        for(CatReporteXlsEntry crxe:reporteTemporalGrafica){
    //            mapaSerieTamanio.put(crxe., cortes)
    //        }
    chartProductividad.setData(mapaSerieProductividad);
    chartStorage.setData(mapaSerieTamanio);
    chartTiempoVisto.setData(mapaSerieTiempoVisto);
    graficaProductividad.addSeries(chartProductividad);
    graficaStorage.addSeries(chartStorage);
    graficaTiempoVisto.addSeries(chartTiempoVisto);
    ReporteGeneralGranulado repGenGra = new ReporteGeneralGranulado(reporteTemporal, graficaStorage,
            graficaTiempoVisto, graficaProductividad);
    return repGenGra;
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

public BigDecimal getPricePerMinute(CalendarConfig config) {
    return config.getBasePrice().divide(new BigDecimal(config.getMinDuration().toString()),
            MathContext.DECIMAL128);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#ceil(java.lang.Object, java.lang.Class)}.
 *//* w  w  w  . ja va  2 s  . c  om*/
@SuppressWarnings("unchecked")
@Test
public void testCeilObjectClassOfT() {
    assertEquals("null", null, ceil(null, null));
    assertEquals("null", null, ceil("", null));
    assertEquals("null", null, ceil("not a number.", null));
    for (Class<?> type : NUMBERS) {
        try {
            Object expected = null;
            Class<? extends Number> typeOfN = (Class<? extends Number>) type;
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "4");
            } else {
                Constructor<?> c = type.getDeclaredConstructor(String.class);
                expected = c.newInstance("4");
            }
            assertEquals("PI: String: " + type.getSimpleName(), expected, ceil("3.14", typeOfN));
            assertEquals("PI: Float: " + type.getSimpleName(), expected, ceil(3.141592653589793f, typeOfN));
            assertEquals("PI: Double: " + type.getSimpleName(), expected, ceil(Math.PI, typeOfN));
            assertEquals("PI: BigDecimal: " + type.getSimpleName(), expected,
                    ceil(BigDecimal.valueOf(Math.PI), typeOfN));
            assertEquals("(Double) (10 / 3): " + type.getSimpleName(), expected, ceil(
                    (Object) (BigDecimal.TEN.divide(new BigDecimal("3"), MathContext.DECIMAL128)), typeOfN));
            if (ObjectUtils.isAny(wrapper, Double.class, Float.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
                assertEquals("Huge: " + type.getSimpleName(), expected,
                        ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128), typeOfN));
            } else if (BigDecimal.class.equals(type)) {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toPlainString();
                Object actual = ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128), BigDecimal.class)
                        .toPlainString();
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            } else {
                expected = INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128).toBigInteger();
                Object actual = ceil((Object) INFINITY_DOUBLE.pow(10, MathContext.DECIMAL128),
                        BigInteger.class);
                assertEquals("Huge: " + type.getSimpleName(), expected, actual);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
        }
    }
}