Example usage for java.math BigDecimal intValue

List of usage examples for java.math BigDecimal intValue

Introduction

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

Prototype

@Override
public int intValue() 

Source Link

Document

Converts this BigDecimal to an int .

Usage

From source file:com.gs.obevo.db.impl.platforms.oracle.OracleDeployIT.java

License:asdf

private Integer toInteger(Object obj) throws SQLException {
    BigDecimal val = (BigDecimal) obj;
    return val != null ? val.intValue() : null;
}

From source file:org.openmhealth.shim.fitbit.mapper.FitbitIntradayStepCountDataPointMapper.java

@Override
protected Optional<DataPoint<StepCount>> asDataPoint(JsonNode listEntryNode) {

    BigDecimal stepCountValue = asRequiredBigDecimal(listEntryNode, "value");

    if (stepCountValue.intValue() == 0) {
        return Optional.empty();
    }//  w w  w  .j  ava 2s. c  o  m

    StepCount.Builder stepCountBuilder = new StepCount.Builder(stepCountValue);

    Optional<LocalDate> dateFromParent = getDateFromSummaryForDay();

    if (dateFromParent.isPresent()) {

        // Set the effective time frame only if we have access to the date and time
        asOptionalString(listEntryNode, "time").ifPresent(time -> stepCountBuilder.setEffectiveTimeFrame(
                ofStartDateTimeAndDuration(dateFromParent.get().atTime(LocalTime.parse(time)).atOffset(UTC),
                        new DurationUnitValue(MINUTE, 1)))); // We use 1 minute since the shim requests data at 1 minute granularity
    }

    return Optional.of(newDataPoint(stepCountBuilder.build(), null));
}

From source file:org.libreplan.business.workingday.ResourcesPerDay.java

private ResourcesPerDay(BigDecimal amount) {
    Validate.isTrue(amount.intValue() >= 0);
    this.amount = amount.setScale(4, RoundingMode.HALF_UP);
}

From source file:org.kalypso.kalypsomodel1d2d.conv.results.ResultMeta1d2dHelper.java

public static Date parseTimelineHour(final String hourString, final int year) {
    final BigDecimal hours = NumberUtils.parseQuietDecimal(hourString);
    if (hours == null)
        return null;

    // REMARK: we read the calculation core time with the time zone, as defined in Kalypso Preferences
    final Calendar calendar = Calendar.getInstance(KalypsoCorePlugin.getDefault().getTimeZone());
    calendar.clear();/*from ww w.  j av a  2s.  c o  m*/
    calendar.set(year, 0, 1);

    BigDecimal wholeHours = hours.setScale(0, BigDecimal.ROUND_DOWN);
    final BigDecimal wholeMinutes = hours.subtract(wholeHours).multiply(new BigDecimal("60")); //$NON-NLS-1$
    if (wholeHours.intValue() > 1) {
        wholeHours = new BigDecimal(wholeHours.intValue() - 1);
    }
    calendar.add(Calendar.HOUR, wholeHours.intValue());
    calendar.add(Calendar.MINUTE, wholeMinutes.intValue());

    final boolean lBoolLeapYear = DateUtilities.isLeapYear(calendar);
    if (lBoolLeapYear && calendar.get(Calendar.DAY_OF_YEAR) > 59) {
        calendar.clear();
        calendar.set(year, 0, 1);
        calendar.add(Calendar.HOUR, wholeHours.intValue() - 24);
        calendar.add(Calendar.MINUTE, wholeMinutes.intValue());
    }

    return calendar.getTime();
}

From source file:org.openmhealth.shim.ihealth.mapper.IHealthStepCountDataPointMapper.java

@Override
protected Optional<DataPoint<StepCount>> asDataPoint(JsonNode listEntryNode, Integer measureUnitMagicNumber) {

    BigDecimal steps = asRequiredBigDecimal(listEntryNode, "Steps");

    if (steps.intValue() == 0) {
        return Optional.empty();
    }/*from   w w w. jav a  2s.co  m*/

    StepCount.Builder stepCountBuilder = new StepCount.Builder(steps);

    Optional<Long> dateTimeString = asOptionalLong(listEntryNode, "MDate");

    if (dateTimeString.isPresent()) {

        Optional<String> timeZone = asOptionalString(listEntryNode, "TimeZone");

        if (timeZone.isPresent()) {

            /* iHealth provides daily summaries for step counts and timestamp the datapoint at either the end of
            the day (23:50) or at the latest time that datapoint was synced */
            stepCountBuilder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(
                    getDateTimeAtStartOfDayWithCorrectOffset(dateTimeString.get(), timeZone.get()),
                    new DurationUnitValue(DAY, 1)));
        }
    }

    getUserNoteIfExists(listEntryNode).ifPresent(stepCountBuilder::setUserNotes);

    StepCount stepCount = stepCountBuilder.build();

    return Optional.of(new DataPoint<>(createDataPointHeader(listEntryNode, stepCount), stepCount));
}

From source file:be.ordina.springbatch.batch.processor.TrajectInformationProcessor.java

@Override
public Fine process(TrajectInformation trajectInformation) throws Exception {
    BigDecimal kmPerHour = calculator.calculateKmPerHour(trajectInformation.getIncomingTime(),
            trajectInformation.getOutgoingTime());
    if (kmPerHour.intValue() > Fine.MAX_SPEED) {
        return new Fine(trajectInformation.getLicensePlate(), kmPerHour.intValue());
    } else {/*w w w.j av  a2  s .  com*/
        return null;
    }
}

From source file:com.sequenceiq.ambari.shell.flash.InstallProgress.java

@Override
public String getText() {
    StringBuilder sb = new StringBuilder();
    if (!done) {//from   w w w.  ja  v a2  s. com
        BigDecimal progress = client.getRequestProgress();
        if (progress != null) {
            BigDecimal decimal = progress.setScale(2, BigDecimal.ROUND_HALF_UP);
            int intValue = decimal.intValue();
            if (intValue != SUCCESS && intValue != FAILED) {
                sb.append("Installation: ").append(decimal).append("% ");
                int rounded = round(progress.setScale(0, BigDecimal.ROUND_UP).intValue() / 10);
                for (int i = 0; i < 10; i++) {
                    if (i < rounded) {
                        sb.append("=");
                    } else {
                        sb.append("-");
                    }
                }
            } else if (intValue == FAILED) {
                sb.append("Installation: FAILED");
                done = true;
            } else {
                sb.append("Installation: COMPLETE");
                done = true;
            }
        } else {
            sb.append("Installation: WAITING..");
        }
    } else {
        if (exit) {
            System.exit(0);
        }
    }
    return sb.toString();
}

From source file:org.libreplan.business.workingday.ResourcesPerDay.java

public boolean isZero() {
    BigDecimal withoutDecimalpart = amount.movePointRight(4);
    return withoutDecimalpart.intValue() == 0;
}

From source file:com.silverpeas.util.MetadataExtractor.java

private void computeMp4Duration(Metadata metadata, MovieHeaderBox movieHeaderBox) {
    BigDecimal duration = BigDecimal.valueOf(movieHeaderBox.getDuration());
    if (duration.intValue() > 0) {
        BigDecimal divisor = BigDecimal.valueOf(movieHeaderBox.getTimescale());

        // Duration
        duration = duration.divide(divisor, 10, BigDecimal.ROUND_HALF_DOWN);
        // get duration in ms
        duration = duration.multiply(BigDecimal.valueOf(1000));
        metadata.add(XMPDM.DURATION, duration.toString());
    }//  w ww  .  j  a v  a 2  s . c  o m
}

From source file:org.jbpm.process.workitem.bpmn2.BusinessRuleTaskTest.java

@Test
public void testDecisionTaskProcess() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createSession(kbase);

    BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION);
    ksession.getWorkItemManager().registerWorkItemHandler("DecisionTask", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("age", 16);
    params.put("yearsOfService", 1);

    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession
            .startProcess("BPMN2-BusinessRuleTask", params);
    BigDecimal variable = (BigDecimal) processInstance.getVariable("vacationDays");

    assertEquals(27, variable.intValue());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}