Example usage for java.time Duration ZERO

List of usage examples for java.time Duration ZERO

Introduction

In this page you can find the example usage for java.time Duration ZERO.

Prototype

Duration ZERO

To view the source code for java.time Duration ZERO.

Click Source Link

Document

Constant for a duration of zero.

Usage

From source file:tibano.service.ParkService.java

@RequestMapping(path = "/getPaymentInfo")
PaymentInfo getPaymentInfo(@RequestParam(name = "areaId") Long areaId,
        @RequestParam(name = "licensePlate") String licensePlate) {
    ParkingTransaction pt = ptRepository.findOpenTransactionByAreaAndLicensePlate(areaId, licensePlate);
    if (pt != null) {
        Duration duration = Duration.between(pt.getStart(), LocalDateTime.now());
        Double amount = duration.getSeconds() * SEC_TARIF;
        BigDecimal bd = new BigDecimal(amount);
        bd = bd.setScale(2, RoundingMode.HALF_UP);
        Integer loyaltyPoints = 5 + Integer.valueOf(Double.valueOf(bd.doubleValue()).intValue());
        return new PaymentInfo(pt.getEnd(), amount, duration, loyaltyPoints);
    }// www  . j  ava2 s .co m
    return new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0));
}

From source file:com.netflix.genie.common.dto.JobTest.java

/**
 * Test to make sure can build a valid Job using the builder.
 *///from   w  ww  .j a  va  2s  . c o  m
@Test
public void canBuildJob() {
    final Job job = new Job.Builder(NAME, USER, VERSION).build();
    Assert.assertThat(job.getName(), Matchers.is(NAME));
    Assert.assertThat(job.getUser(), Matchers.is(USER));
    Assert.assertThat(job.getVersion(), Matchers.is(VERSION));
    Assert.assertThat(job.getCommandArgs(), Matchers.is(Optional.empty()));
    Assert.assertFalse(job.getArchiveLocation().isPresent());
    Assert.assertFalse(job.getClusterName().isPresent());
    Assert.assertFalse(job.getCommandName().isPresent());
    Assert.assertFalse(job.getFinished().isPresent());
    Assert.assertFalse(job.getStarted().isPresent());
    Assert.assertThat(job.getStatus(), Matchers.is(JobStatus.INIT));
    Assert.assertFalse(job.getStatusMsg().isPresent());
    Assert.assertFalse(job.getCreated().isPresent());
    Assert.assertFalse(job.getDescription().isPresent());
    Assert.assertFalse(job.getId().isPresent());
    Assert.assertThat(job.getTags(), Matchers.empty());
    Assert.assertFalse(job.getUpdated().isPresent());
    Assert.assertThat(job.getRuntime(), Matchers.is(Duration.ZERO));
    Assert.assertThat(job.getGrouping(), Matchers.is(Optional.empty()));
    Assert.assertThat(job.getGroupingInstance(), Matchers.is(Optional.empty()));
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

private Duration calculateWorktime(Collection<Booking> bookings) {
    Duration minutes = Duration.ZERO;
    for (Booking current : bookings) {
        minutes = minutes.plus(current.calculateTimeSpan().getLengthInMinutes());
    }/*from w ww.  j  a  v  a 2 s  .  c o m*/
    return minutes;
}

From source file:org.usrz.libs.webtools.resources.ServeResource.java

/**
 * Create a new {@link ServeResource} instance with the specified
 * {@link Configurations}./*  ww  w  . j av  a 2s . com*/
 */
@Inject
public ServeResource(Configurations configurations) throws IOException {
    charset = Charset.forName(configurations.get("charset", UTF8.name()));
    charsetName = charset.name();

    manager = new ResourceManager(configurations.requireFile("root_path"), charset);

    minify = configurations.get("minify", false);

    cacheDuration = configurations.get("cache", Duration.ZERO);
    cacheControl = new CacheControl();
    cacheControl.setMaxAge((int) cacheDuration.getSeconds());
    cacheControl.setNoCache(Duration.ZERO.equals(cacheDuration));

    jsonMediaType = new MediaType("application", "json").withCharset(charsetName);
    styleMediaType = new MediaType("text", "css").withCharset(charsetName);
    scriptMediaType = new MediaType("application", "javascript").withCharset(charsetName);

    executor = new KeyedExecutor<String>(SimpleExecutorProvider.create(configurations.strip("executor")));

    /* Our Json factory, able to read all sorts of weird schtuff */
    json = new JsonFactory()
            /* Factory features */
            .disable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES)
            .disable(JsonFactory.Feature.INTERN_FIELD_NAMES)
            /* Parser features */
            .enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)
            .enable(JsonParser.Feature.ALLOW_COMMENTS).enable(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS)
            .enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES)
            .enable(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS)
            .enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
            .disable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS)
            .disable(JsonParser.Feature.ALLOW_YAML_COMMENTS)
            .disable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION)
            /* Generator features */
            .disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT)
            .enable(JsonGenerator.Feature.ESCAPE_NON_ASCII).enable(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)
            .enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES)
            .enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN)
            .disable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS)
            .disable(JsonGenerator.Feature.STRICT_DUPLICATE_DETECTION)
            .disable(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService.java

private Duration determineDeviceTimeOffset(AppActivitiesDto appActivities) {
    Duration offset = Duration.between(ZonedDateTime.now(), appActivities.getDeviceDateTime());
    return (offset.abs().compareTo(DEVICE_TIME_INACCURACY_MARGIN) > 0) ? offset : Duration.ZERO; // Ignore if less than 10
    // seconds/*from   w  w  w . j a va2  s  .  co m*/
}

From source file:nu.yona.server.subscriptions.service.PinResetRequestService.java

private ConfirmationCode createConfirmationCode(Moment moment) {
    String confirmationCode = (moment == Moment.IMMEDIATELY)
            || yonaProperties.getSecurity().getPinResetRequestConfirmationCodeDelay().equals(Duration.ZERO)
                    ? userService.generateConfirmationCode()
                    : null;//from   w  w w .  j ava 2 s .  c o  m
    return ConfirmationCode.createInstance(confirmationCode);
}

From source file:de.metas.ui.web.dashboard.UserDashboardRepository.java

private KPI getKPIOrNull(final int WEBUI_KPI_ID) {
    if (WEBUI_KPI_ID <= 0) {
        return null;
    }//from   ww  w. j av  a  2s  .  co  m
    return kpisCache.getOrLoad(WEBUI_KPI_ID, () -> {
        final I_WEBUI_KPI kpiDef = InterfaceWrapperHelper.create(Env.getCtx(), WEBUI_KPI_ID, I_WEBUI_KPI.class,
                ITrx.TRXNAME_None);
        if (kpiDef == null) {
            return null;
        }

        final IModelTranslationMap trls = InterfaceWrapperHelper.getModelTranslationMap(kpiDef);

        final String timeRangeStr = kpiDef.getES_TimeRange();
        final Duration timeRange = Check.isEmpty(timeRangeStr, true) ? Duration.ZERO
                : Duration.parse(timeRangeStr);

        return KPI.builder().setId(kpiDef.getWEBUI_KPI_ID())
                .setCaption(trls.getColumnTrl(I_WEBUI_KPI.COLUMNNAME_Name, kpiDef.getName()))
                .setDescription(trls.getColumnTrl(I_WEBUI_KPI.COLUMNNAME_Description, kpiDef.getDescription()))
                .setChartType(KPIChartType.forCode(kpiDef.getChartType()))
                .setFields(retrieveKPIFields(WEBUI_KPI_ID))
                //
                .setTimeRange(timeRange)
                //
                .setESSearchIndex(kpiDef.getES_Index()).setESSearchTypes(kpiDef.getES_Type())
                .setESQuery(kpiDef.getES_Query()).setElasticsearchClient(elasticsearchClient)
                //
                .build();
    });
}

From source file:com.drunkendev.io.recurse.tests.RecursionTest.java

/**
 * Used to perform a timed average of a repeated set of runs.
 *
 * @param   count//from  ww w.ja va 2 s. c  o m
 *          Amount of times to run {@code r}.
 * @param   r
 *          {@link Runnable} object to perform tests against.
 */
public void averageTest(int count, Runnable r) {
    Duration total = Duration.ZERO;
    for (int i = 0; i < count; i++) {
        total = total.plus(time(() -> r.run()));
    }
    System.out.format("%nAverage duration: %s%n%n", total.dividedBy(count));
}

From source file:com.netflix.genie.common.dto.JobTest.java

/**
 * Test to make sure a Job can be successfully built when nulls are inputted.
 *//*  w ww. j a  va2 s .  c  o m*/
@Test
public void canBuildJobWithNulls() {
    final Job.Builder builder = new Job.Builder(NAME, USER, VERSION);
    builder.withCommandArgs((List<String>) null);
    builder.withArchiveLocation(null);
    builder.withClusterName(null);
    builder.withCommandName(null);
    builder.withFinished(null);
    builder.withStarted(null);
    builder.withStatus(JobStatus.INIT);
    builder.withStatusMsg(null);
    builder.withCreated(null);
    builder.withDescription(null);
    builder.withId(null);
    builder.withTags(null);
    builder.withUpdated(null);

    final Job job = builder.build();
    Assert.assertThat(job.getName(), Matchers.is(NAME));
    Assert.assertThat(job.getUser(), Matchers.is(USER));
    Assert.assertThat(job.getVersion(), Matchers.is(VERSION));
    Assert.assertFalse(job.getCommandArgs().isPresent());
    Assert.assertFalse(job.getArchiveLocation().isPresent());
    Assert.assertFalse(job.getClusterName().isPresent());
    Assert.assertFalse(job.getCommandName().isPresent());
    Assert.assertFalse(job.getFinished().isPresent());
    Assert.assertFalse(job.getStarted().isPresent());
    Assert.assertThat(job.getStatus(), Matchers.is(JobStatus.INIT));
    Assert.assertFalse(job.getStatusMsg().isPresent());
    Assert.assertFalse(job.getCreated().isPresent());
    Assert.assertFalse(job.getDescription().isPresent());
    Assert.assertFalse(job.getId().isPresent());
    Assert.assertThat(job.getTags(), Matchers.empty());
    Assert.assertFalse(job.getUpdated().isPresent());
    Assert.assertThat(job.getRuntime(), Matchers.is(Duration.ZERO));
}

From source file:org.edgexfoundry.scheduling.ScheduleContext.java

private void parsePeriodAndDuration(String frequency) {

    int periodStart = frequency.indexOf('P');
    int timeStart = frequency.indexOf('T');
    String freq = frequency;//from  w w w  .  j  ava 2s . co m

    this.period = Period.ZERO;
    this.duration = Duration.ZERO;

    // Parse out the period (date)
    try {
        // If there is a duration 'T', remove it
        if (timeStart != -1)
            freq = frequency.substring(periodStart, timeStart);
        this.period = Period.parse(freq);
    } catch (IndexOutOfBoundsException | DateTimeParseException e) {
        logger.error("parsePeriodAndDuration() failed to parse period from '" + freq + "'");
    }

    // Parse out the duration (time)
    try {
        // Make sure there is both a 'P' and 'T'
        if (periodStart != -1 && timeStart != -1) {
            freq = frequency.substring(timeStart, frequency.length());
            this.duration = Duration.parse("P" + freq);
        }
    } catch (IndexOutOfBoundsException | DateTimeParseException e) {
        logger.error("parsePeriodAndDuration() failed to parse duration from 'P" + freq + "'");
    }
}