private Instant getMax(Instant t1, Instant t2) { return t1.compareTo(t2) >= 0 ? t1 : t2; }
@Override public int compareTo(final Timestamp other) { return this.instant.compareTo(other.instant); }
public int compare(ZonedDateTime one, ZonedDateTime another) { return one.toInstant().compareTo( another.toInstant() ); } }
@Override public int compareTo(TimestampTZ o) { return zonedDateTime.toInstant().compareTo(o.zonedDateTime.toInstant()); }
@Override public int compareTo(LayerEntryTemplate otherLayerEntryTemplate) { int sourceFileComparison = sourceFile.compareTo(otherLayerEntryTemplate.sourceFile); if (sourceFileComparison != 0) { return sourceFileComparison; } int extractionPathComparison = extractionPath.compareTo(otherLayerEntryTemplate.extractionPath); if (extractionPathComparison != 0) { return extractionPathComparison; } int lastModifiedTimeComparison = lastModifiedTime.compareTo(otherLayerEntryTemplate.lastModifiedTime); if (lastModifiedTimeComparison != 0) { return lastModifiedTimeComparison; } return permissions.compareTo(otherLayerEntryTemplate.permissions); }
private boolean check6hrLogout() { if (sixHourWarningTime == null) { return false; } if (Instant.now().compareTo(sixHourWarningTime) >= 0) { if (notify6HourLogout) { notify6HourLogout = false; return true; } } else { notify6HourLogout = true; } return false; }
@Override public int compareTo(final AcceptedMessage o) { int cmpRes = acceptedTime.compareTo(o.acceptedTime); if (cmpRes == 0) { return message.compareTo(o.message); } return cmpRes; }
@Override public int compareTo(ScheduledDeadlineInfo other) { if (scheduleTime.equals(other.scheduleTime)) { return Integer.compare(counter, other.counter); } return scheduleTime.compareTo(other.scheduleTime); }
@Override public int compareTo(StubScheduleToken other) { if (scheduleTime.equals(other.scheduleTime)) { return (counter < other.counter) ? -1 : ((counter == other.counter) ? 0 : 1); } return scheduleTime.compareTo(other.scheduleTime); }
@Test public void testTimeSequence() throws Exception { Random r = new Random(); Instant[] times = new Instant[10]; for (int i = 0; i < times.length; i++) { times[i] = TimestampProviders.NANO.getTime(); if (i > 0) assertTrue(times[i] + " > " + times[i - 1], times[i].compareTo(times[i - 1])>0); Thread.sleep(r.nextInt(50) + 2); } }
private Duration timeSinceFirstMsg() { Duration sinceFirst = Duration.ZERO; if (!toSend.isEmpty()) { Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp(); Instant nowTimestamp = times.getTime(); if (firstTimestamp.compareTo(nowTimestamp) < 0) { sinceFirst = Duration.between(firstTimestamp, nowTimestamp); } } return sinceFirst; }
private boolean checkAnimationIdle(Duration waitDuration, Player local) { if (lastAnimation == IDLE) { return false; } final int animation = local.getAnimation(); if (animation == IDLE) { if (lastAnimating != null && Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0) { lastAnimation = IDLE; lastAnimating = null; return true; } } else { lastAnimating = Instant.now(); } return false; }
@Test public void testTimeSequence() throws Exception { Random r = new Random(); Instant[] times = new Instant[10]; for (int i = 0; i < times.length; i++) { times[i] = TimestampProviders.NANO.getTime(); if (i > 0) assertTrue(times[i] + " > " + times[i - 1], times[i].compareTo(times[i - 1])>0); Thread.sleep(r.nextInt(50) + 2); } }
private Duration timeSinceFirstMsg() { Duration sinceFirst = Duration.ZERO; if (!toSend.isEmpty()) { Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp(); Instant nowTimestamp = times.getTime(); if (firstTimestamp.compareTo(nowTimestamp) < 0) { sinceFirst = Duration.between(firstTimestamp, nowTimestamp); } } return sinceFirst; }
@Override public void forceCloseInstance(String instanceId) { Preconditions.checkArgument(!graph.getConfiguration().getUniqueGraphId().equals(instanceId), "Cannot force close this current instance [%s]. Properly shut down the graph instead.", instanceId); Preconditions.checkArgument(modifyConfig.has(REGISTRATION_TIME, instanceId), "Instance [%s] is not currently open", instanceId); Instant registrationTime = modifyConfig.get(REGISTRATION_TIME, instanceId); Preconditions.checkArgument(registrationTime.compareTo(txStartTime) < 0, "The to-be-closed instance [%s] was started after this transaction" + "which indicates a successful restart and can hence not be closed: %s vs %s", instanceId, registrationTime, txStartTime); modifyConfig.remove(REGISTRATION_TIME, instanceId); }
boolean isExpired(Instant now) { if (this.maxInactiveInterval.isNegative()) { return false; } return now.minus(this.maxInactiveInterval).compareTo(this.lastAccessedTime) >= 0; }
@Override public void forceCloseInstance(String instanceId) { Preconditions.checkArgument(!graph.getConfiguration().getUniqueGraphId().equals(instanceId), "Cannot force close this current instance [%s]. Properly shut down the graph instead.", instanceId); Preconditions.checkArgument(modifyConfig.has(REGISTRATION_TIME, instanceId), "Instance [%s] is not currently open", instanceId); Instant registrationTime = modifyConfig.get(REGISTRATION_TIME, instanceId); Preconditions.checkArgument(registrationTime.compareTo(txStartTime) < 0, "The to-be-closed instance [%s] was started after this transaction" + "which indicates a successful restart and can hence not be closed: %s vs %s", instanceId, registrationTime, txStartTime); modifyConfig.remove(REGISTRATION_TIME, instanceId); }
@Override public Instant sleepPast(Instant futureTime) throws InterruptedException { Instant now; ChronoUnit unit = getUnit(); /* * Distributed storage managers that rely on timestamps play with the * least significant bit in timestamp longs, turning it on or off to * ensure that deletions are logically ordered before additions within a * single batch mutation. This is not a problem at microsecond * resolution because we pretendulate microsecond resolution by * multiplying currentTimeMillis by 1000, so the LSB can vary freely. * It's also not a problem with nanosecond resolution because the * resolution is just too fine, relative to how long a mutation takes, * for it to matter in practice. But it can lead to corruption at * millisecond resolution (and does, in testing). */ if (unit.equals(TimeUnit.MILLISECONDS)) futureTime = futureTime.plusMillis(1L); while ((now = getTime()).compareTo(futureTime) <= 0) { long delta = getTime(futureTime) - getTime(now); if (0L == delta) delta = 1L; if (log.isTraceEnabled()) { log.trace("Sleeping: now={} targettime={} delta={} {}", new Object[] { now, futureTime, delta, unit }); } Temporals.timeUnit(unit).sleep(delta); } return now; }
private Optional<Period> resolveByDate(DbSession dbSession, String projectUuid, Instant date, String propertyValue) { Instant now = Instant.ofEpochMilli(system2.now()); checkPeriodProperty(date.compareTo(now) <= 0, propertyValue, "date is in the future (now: '%s')", supplierToString(() -> logDate(now))); LOG.debug("Resolving new code period by date: {}", supplierToString(() -> logDate(date))); Optional<Period> period = findFirstSnapshot(dbSession, createCommonQuery(projectUuid).setCreatedAfter(date.toEpochMilli()).setSort(BY_DATE, ASC)) .map(dto -> newPeriod(LEAK_PERIOD_MODE_DATE, DateUtils.formatDate(date), dto)); checkPeriodProperty(period.isPresent(), propertyValue, "No analysis found created after date '%s'", supplierToString(() -> logDate(date))); return period; }