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:Main.java

public static void main(String[] args) {
    Duration duration = Duration.ZERO;
    System.out.println(duration);
}

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.from(Duration.ZERO);
    System.out.println(duration);
}

From source file:viewmodel.TeamResult.java

public TeamResult() {
    this.teamDuration = Duration.ZERO;
}

From source file:com.przemo.projectmanagementweb.services.TimeLogService.java

public Duration getTimeLoggedForTask(int taskId) {
    List<Double> t = HibernateUtil.runQuery("select sum(tl.time) from TimeLog tl where tl.task=" + taskId);
    if (t != null && !t.isEmpty() && t.get(0) != null) {
        return Duration.of((int) ((t.get(0)) * 60), ChronoUnit.MINUTES);
    } else {//from  w  w  w.  j  ava 2 s .  c o  m
        return Duration.ZERO;
    }
}

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

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }//from   www.  j ava2 s  . co  m
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}

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

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Activity", "Booking number", "Hours", "%"));
    Duration totalMinutes = Duration.ZERO;
    Map<Activity, Duration> activityToMinutesMap = Maps.newHashMap();
    for (Booking current : getRelevantBookings(parameter)) {
        if (current.hasEndtime()) {
            Activity currentActivity = current.getActivity();
            Duration accumulatedMinutes = activityToMinutesMap.get(currentActivity);
            if (accumulatedMinutes == null) {
                accumulatedMinutes = Duration.ZERO;
            }//  ww w.  j a  v  a  2 s  .co m
            Duration activityLength = current.calculateTimeSpan().getLengthInMinutes();
            totalMinutes = totalMinutes.plus(activityLength);
            accumulatedMinutes = accumulatedMinutes.plus(activityLength);
            activityToMinutesMap.put(currentActivity, accumulatedMinutes);
        }
    }
    for (Entry<Activity, Duration> currentActivity : activityToMinutesMap.entrySet()) {
        Activity activity = currentActivity.getKey();
        Duration totalMinutesId = currentActivity.getValue();
        double percentage = (double) totalMinutesId.toMinutes() / (double) totalMinutes.toMinutes();
        String percentageString = String.format("%2.1f", percentage * 100.0);
        result.add(Arrays.asList(activity.getActivityName(), activity.getBookingNumber(),
                formatDuration(totalMinutesId), percentageString));
    }
    return result;
}

From source file:tibano.entity.ParkingTransactionRepositoryTest.java

@Test
public void findOpenTransactionByAreaAndLicensePlate() {
    // when there is a closed TX
    Car car = carRepository.save(new Car(LIC_PLATE + "1", user));
    ParkingTransaction pt = new ParkingTransaction(area, car);
    pt.end(new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0)));
    pt = target.save(pt);/*  www  . j av a 2  s.  co m*/
    // and an open TX
    pt = new ParkingTransaction(area, car);
    pt = target.save(pt);
    // then I get only the open TX
    pt = target.findOpenTransactionByAreaAndLicensePlate(pt.getArea().getId(), car.getLicensePlate());
}

From source file:io.github.resilience4j.ratelimiter.RateLimiterAutoConfigurationTest.java

/**
 * The test verifies that a RateLimiter instance is created and configured properly when the DummyService is invoked and
 * that the RateLimiter records successful and failed calls.
 *//* ww w .j a v a 2 s  .c  om*/
@Test
public void testRateLimiterAutoConfiguration() throws IOException {
    assertThat(rateLimiterRegistry).isNotNull();
    assertThat(rateLimiterProperties).isNotNull();

    RateLimiter rateLimiter = rateLimiterRegistry.rateLimiter(DummyService.BACKEND);
    assertThat(rateLimiter).isNotNull();
    rateLimiter.getPermission(Duration.ZERO);
    await().atMost(2, TimeUnit.SECONDS).until(() -> rateLimiter.getMetrics().getAvailablePermissions() == 10);

    try {
        dummyService.doSomething(true);
    } catch (IOException ex) {
        // Do nothing.
    }
    dummyService.doSomething(false);

    assertThat(rateLimiter.getMetrics().getAvailablePermissions()).isEqualTo(8);
    assertThat(rateLimiter.getMetrics().getNumberOfWaitingThreads()).isEqualTo(0);

    assertThat(rateLimiter.getRateLimiterConfig().getLimitForPeriod()).isEqualTo(10);
    assertThat(rateLimiter.getRateLimiterConfig().getLimitRefreshPeriod()).isEqualTo(Duration.ofSeconds(1));
    assertThat(rateLimiter.getRateLimiterConfig().getTimeoutDuration()).isEqualTo(Duration.ofSeconds(0));

    // Test Actuator endpoints

    ResponseEntity<RateLimiterEndpointResponse> rateLimiterList = restTemplate
            .getForEntity("/actuator/ratelimiters", RateLimiterEndpointResponse.class);

    assertThat(rateLimiterList.getBody().getRateLimitersNames()).hasSize(2).containsExactly("backendA",
            "backendB");

    try {
        for (int i = 0; i < 11; i++) {
            dummyService.doSomething(false);
        }
    } catch (RequestNotPermitted e) {
        // Do nothing
    }

    ResponseEntity<RateLimiterEventsEndpointResponse> rateLimiterEventList = restTemplate
            .getForEntity("/actuator/ratelimiter-events", RateLimiterEventsEndpointResponse.class);

    List<RateLimiterEventDTO> eventsList = rateLimiterEventList.getBody().getEventsList();
    assertThat(eventsList).isNotEmpty();
    RateLimiterEventDTO lastEvent = eventsList.get(eventsList.size() - 1);
    assertThat(lastEvent.getRateLimiterEventType()).isEqualTo(RateLimiterEvent.Type.FAILED_ACQUIRE);

    await().atMost(2, TimeUnit.SECONDS).until(() -> rateLimiter.getMetrics().getAvailablePermissions() == 10);

    assertThat(rateLimiterAspect.getOrder()).isEqualTo(401);
}

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

/**
 * Test to make sure can build a valid Job using the builder.
 *//*  w  w  w .  j a  v a 2 s.c om*/
@Test
@SuppressWarnings("deprecation")
public void canBuildJobDeprecatedConstructor() {
    final Job job = new Job.Builder(NAME, USER, VERSION, StringUtils.join(COMMAND_ARGS, StringUtils.SPACE))
            .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().orElseThrow(IllegalArgumentException::new),
            Matchers.is(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE)));
    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:it.tidalwave.northernwind.core.model.spi.AvailabilityEnforcerRequestProcessor.java

@Override
@Nonnull//from   ww w.j  a  v  a 2s . c o m
public Status process(final @Nonnull Request request)
        throws NotFoundException, IOException, HttpStatusException {
    if (siteProvider.get().isSiteAvailable()) {
        return CONTINUE;
    }

    log.warn("Site unavailable, sending maintenance page");
    // TODO: use a resource
    final String page = String.format("<!DOCTYPE html>%n" + "<html>\n" + "<head>\n"
            + "<meta http-equiv=\"Refresh\" content=\"15; url=%s%s\"/>\n" + "</head>\n" + "<body>\n"
            + "<div style=\"padding: 5%% 0pt;\">\n" + "<div style=\"padding: 10%% 0pt; text-align: center\">"
            + "<p style=\"font-family: sans-serif; font-size: 24px\">"
            + "Site under maintenance, please retry later.<br/>" + "This page will reload automatically.</p>"
            + "</div>\n" + "</div>\n" + "</body>\n" + "</html>", request.getBaseUrl(),
            request.getOriginalRelativeUri());
    responseHolder.response().withContentType("text/html").withStatus(503).withExpirationTime(Duration.ZERO)
            .withBody(page).put();
    return BREAK;
}