Example usage for java.time.temporal ChronoUnit SECONDS

List of usage examples for java.time.temporal ChronoUnit SECONDS

Introduction

In this page you can find the example usage for java.time.temporal ChronoUnit SECONDS.

Prototype

ChronoUnit SECONDS

To view the source code for java.time.temporal ChronoUnit SECONDS.

Click Source Link

Document

Unit that represents the concept of a second.

Usage

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testAddTagEvent() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamTagMap().tagToTeam("ABCD").get(), Matchers.equalTo(0));
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEvents_ShouldAddLap() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS));
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 0L);//from   ww  w  .  ja  va  2s.c  om
    snapshot = tagSeenEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(60, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(0), Matchers.equalTo(1));
}

From source file:com.otway.picasasync.syncutil.ImageSync.java

public UpdateAction evaluateAction(Settings settings, boolean isAutoBackup) {

    boolean canDownloadNew = settings.getDownloadNew();
    boolean canDownloadChanged = settings.getDownloadChanged();
    boolean canUploadNew = settings.getUploadNew();
    boolean canUploadChanged = settings.getUploadChanged();

    if (isAutoBackup) {
        canDownloadNew = settings.getAutoBackupDownload();
        canUploadChanged = canUploadNew = settings.getAutoBackupUpload();
    }//from ww w.  j av  a 2 s  .c om

    UpdateAction action = UpdateAction.none;
    boolean hasLocalFile = localFile.exists();
    boolean hasRemoteFile = remotePhoto != null;
    boolean isNewFile = false;

    if (hasLocalFile)
        generateMd5CheckSum();

    if (hasLocalFile && hasRemoteFile) {
        // We have both. See if they're the same...
        if (remotePhoto.getChecksum() != null && remotePhoto.getChecksum().equals(localMd5CheckSum)) {
            // We have an MD5 checksum, and it matches. Happy days.
            log.debug("MD5 checksum matched. No action required");
            action = UpdateAction.none;
        } else {
            // There's a remote photo. See which is newer.
            LocalDateTime localMod = getTimeFromMS(localFile.lastModified());
            LocalDateTime remoteMod = getTimeFromMS(remotePhoto.getUpdated().getValue());
            long seconds = ChronoUnit.SECONDS.between(remoteMod, localMod);
            if (Math.abs(seconds) > TIME_DELTA_SECS) {
                if (seconds > 0) {
                    log.info("Image " + localFile.getName() + " is " + seconds
                            + "s newer than remote image, so will be uploaded");
                    action = UpdateAction.upload;
                } else {
                    log.info("Image " + localFile.getName() + " is " + seconds
                            + "s older than remote image, so will be downloaded");
                    action = UpdateAction.download;
                }
            }
        }
    } else {
        if (hasLocalFile) {
            // No remote file. It's a new file to upload
            action = UpdateAction.upload;
            isNewFile = true;
        } else if (hasRemoteFile) {
            // No local file. It's a new file to download
            action = UpdateAction.download;
            isNewFile = true;
        }
    }

    // Now we've established what the action we'd *like* to
    // do is, now see if we're actually allowed to do it.
    if (action == UpdateAction.download) {
        if (isNewFile) {
            if (!canDownloadNew)
                action = UpdateAction.none;
        } else {
            if (!canDownloadChanged)
                action = UpdateAction.none;
        }
    } else {
        if (isNewFile) {
            if (!canUploadNew)
                action = UpdateAction.none;
        } else {
            if (!canUploadChanged)
                action = UpdateAction.none;
        }
    }

    return action;
}

From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java

/** Returns the suffix of a time-based index given the grouping period
 * @param grouping_period - the grouping period
 * @param lowest_granularity/* w ww  .  j a v  a  2  s.c  om*/
 * @return the index suffix, ie added to the base index
 */
public static String getTimeBasedSuffix(final ChronoUnit grouping_period,
        final Optional<ChronoUnit> lowest_granularity) {
    return lowest_granularity
            .map(lg -> grouping_period.compareTo(lg) < 0 ? getTimeBasedSuffix(lg, Optional.empty()) : null)
            .orElse(Patterns.match(grouping_period).<String>andReturn()
                    .when(p -> ChronoUnit.SECONDS == p, __ -> "yyyy.MM.dd.HH:mm:ss")
                    .when(p -> ChronoUnit.MINUTES == p, __ -> "yyyy.MM.dd.HH:mm")
                    .when(p -> ChronoUnit.HOURS == p, __ -> "yyyy.MM.dd.HH")
                    .when(p -> ChronoUnit.DAYS == p, __ -> "yyyy.MM.dd")
                    .when(p -> ChronoUnit.WEEKS == p, __ -> "YYYY-ww") // (deliberately 'Y' (week-year) not 'y' since 'w' is week-of-year 
                    .when(p -> ChronoUnit.MONTHS == p, __ -> "yyyy.MM")
                    .when(p -> ChronoUnit.YEARS == p, __ -> "yyyy").otherwise(__ -> ""));
}

From source file:com.github.aptd.simulation.elements.train.CDoor.java

@Override
protected Instant determinenextstatechange() {
    switch (m_state) {
    case CLOSED_LOCKED:
    case CLOSED_RELEASED:
    case OPEN_BUSY:
    case OPEN_BUSY_SHALL_CLOSE:
    case OPEN_CLOSEABLE:
        return Instant.MAX;
    case OPENING:
    case OPENING_SHALL_CLOSE:
        return m_lastcontinuousupdate.plus(Math.round((m_width - m_openwidth) / m_openingspeed),
                ChronoUnit.SECONDS);
    case OPEN_FREE:
    case OPEN_FREE_SHALL_CLOSE:
        return m_lastcontinuousupdate.plus(Math.round(m_minfreetimetoclose - m_freetime), ChronoUnit.SECONDS);
    case CLOSING:
    case CLOSING_LOCKED:
        return m_lastcontinuousupdate.plus(Math.round(m_openwidth / m_closingspeed), ChronoUnit.SECONDS);
    default:/*from ww w.j av a2  s. c om*/
        return Instant.MAX;
    }
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEventBeforeStart_ShouldBeIgnored() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("ABCD"), 0);
    snapshot = addTagEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 0L);//from  w w  w.ja  va 2 s .co m
    snapshot = tagSeenEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("ABCD"),
            0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(0), Matchers.equalTo(0));
}

From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java

/** Low level util because java8 time "plus" is odd
 * @param to_adjust//w w w  . j a  v  a2s.  co m
 * @param increment
 * @return
 */
private static Date adjustTime(Date to_adjust, ChronoUnit increment) {
    return Patterns.match(increment).<Date>andReturn()
            .when(t -> t == ChronoUnit.SECONDS, __ -> DateUtils.addSeconds(to_adjust, 1))
            .when(t -> t == ChronoUnit.MINUTES, __ -> DateUtils.addMinutes(to_adjust, 1))
            .when(t -> t == ChronoUnit.HOURS, __ -> DateUtils.addHours(to_adjust, 1))
            .when(t -> t == ChronoUnit.DAYS, __ -> DateUtils.addDays(to_adjust, 1))
            .when(t -> t == ChronoUnit.WEEKS, __ -> DateUtils.addWeeks(to_adjust, 1))
            .when(t -> t == ChronoUnit.MONTHS, __ -> DateUtils.addMonths(to_adjust, 1))
            .when(t -> t == ChronoUnit.YEARS, __ -> DateUtils.addYears(to_adjust, 1)).otherwiseAssert();
}

From source file:org.ulyssis.ipp.snapshot.TestSnapshot.java

@Test
public void testTagSeenEventAfterEnd_ShouldBeIgnored() throws Exception {
    Snapshot snapshot = new Snapshot(Instant.EPOCH);
    AddTagEvent addTagEvent = new AddTagEvent(Instant.EPOCH.plus(1, ChronoUnit.SECONDS), new TagId("DCBA"), 3);
    snapshot = addTagEvent.doApply(snapshot);
    StartEvent startEvent = new StartEvent(Instant.EPOCH.plus(2, ChronoUnit.SECONDS));
    snapshot = startEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent = new TagSeenEvent(Instant.EPOCH.plus(3, ChronoUnit.SECONDS), new TagId("DCBA"),
            0, 0L);/*from www.j a v  a2 s. c om*/
    snapshot = tagSeenEvent.doApply(snapshot);
    EndEvent endEvent = new EndEvent(Instant.EPOCH.plus(50, ChronoUnit.SECONDS));
    snapshot = endEvent.doApply(snapshot);
    TagSeenEvent tagSeenEvent2 = new TagSeenEvent(Instant.EPOCH.plus(100, ChronoUnit.SECONDS),
            new TagId("DCBA"), 0, 1L);
    snapshot = tagSeenEvent2.doApply(snapshot);
    MatcherAssert.assertThat(snapshot.getTeamStates().getNbLapsForTeam(3), Matchers.equalTo(0));
}

From source file:com.github.aptd.simulation.elements.passenger.CPassenger.java

@Override
protected Instant determinenextstatechange() {
    switch (m_state) {
    case MOVING_THROUGH_STATION:
        return m_lastcontinuousupdate.plus(
                Math.round((m_distancetonextplatform - m_distancewalked) / m_speedatstation),
                ChronoUnit.SECONDS);
    case ENTERING_TRAIN:
        return m_lastcontinuousupdate.plus(Math.round(m_entranceduration - m_dooruse), ChronoUnit.SECONDS);
    case LEAVING_TRAIN:
        return m_lastcontinuousupdate.plus(Math.round(m_exitduration - m_dooruse), ChronoUnit.SECONDS);
    default://from w  w w . j  a v a2  s  . c o m
        return Instant.MAX;
    }
}

From source file:com.github.aptd.simulation.elements.train.CTrain.java

@Override
protected final synchronized Instant determinenextstatechange() {
    switch (m_state) {
    case DRIVING:
        return m_lastcontinuousupdate.plus(
                Math.round((m_timetable.get(m_ttindex).m_tracklength - m_positionontrack) / DRIVING_SPEED),
                ChronoUnit.SECONDS);
    case WAITING_TO_DRIVE:
        return m_doorsnotclosedlocked.isEmpty() ? m_laststatechange : Instant.MAX;
    case ARRIVED:
        if (m_ttindex + 1 >= m_timetable.size())
            return Instant.MAX;
        return Collections.max(Arrays.asList(m_timetable.get(m_ttindex).m_publisheddeparture,
                m_laststatechange.plus(30, ChronoUnit.SECONDS)));
    default:/*www. j  a  v  a2 s  . com*/
        return m_laststatechange.plus(30, ChronoUnit.SECONDS);
    }
}