本文整理汇总了Java中java.time.Instant.isBefore方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.isBefore方法的具体用法?Java Instant.isBefore怎么用?Java Instant.isBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Instant
的用法示例。
在下文中一共展示了Instant.isBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValid
import java.time.Instant; //导入方法依赖的package包/类
@Override
public boolean isValid(Observation obs) throws ProcessException {
try {
Instant latest;
Datastream ds = obs.getDatastream();
if (ds == null) {
MultiDatastream mds = obs.getMultiDatastream();
if (mds == null) {
throw new ProcessException("Observation has no Datastream of Multidatastream set!");
}
latest = getTimeForMultiDatastream(mds);
} else {
latest = getTimeForDatastream(ds);
}
TimeObject phenomenonTime = obs.getPhenomenonTime();
Instant obsInstant;
if (phenomenonTime.isInterval()) {
obsInstant = phenomenonTime.getAsInterval().getStart();
} else {
obsInstant = phenomenonTime.getAsDateTime().toInstant();
}
return latest.isBefore(obsInstant);
} catch (ServiceFailureException ex) {
throw new ProcessException("Failed to validate.", ex);
}
}
示例2: updateDateRange
import java.time.Instant; //导入方法依赖的package包/类
private void updateDateRange(final TreeNode exactNode, final Range<Instant> range) {
final Range<Instant> original = exactNode.getDateRange();
Instant start = original.getStart();
Instant finish = original.getFinish();
if (start.isAfter(range.getStart())) {
start = range.getStart();
}
if (finish.isBefore(range.getFinish())) {
finish = range.getFinish();
}
if (start.compareTo(original.getStart()) != 0 ||
finish.compareTo(original.getFinish()) != 0) {
this.nextNodes.remove(new DatedNodeKey(exactNode.getValue(), original));
exactNode.setDateRange(new Range<Instant>(start, finish));
this.nextNodes.put(
new DatedNodeKey(exactNode.getValue(), exactNode.getDateRange()), exactNode);
}
}
示例3: fold
import java.time.Instant; //导入方法依赖的package包/类
@Override
public Result fold(Result accumulator, Event.Alert value) throws Exception {
accumulator.setCount(accumulator.getCount() + 1);
accumulator.setNetworkId(value.getNetworkId());
accumulator.getIpAddress().add(Event.EventType.formatAddress(value.getEvent().getSourceAddress()));
if(accumulator.getMinTimestamp() == 0) {
accumulator.setMinTimestamp(value.getEvent().getEventTime().toEpochMilli());
accumulator.setMaxTimestamp(value.getEvent().getEventTime().toEpochMilli());
} else {
Instant d1 = Instant.ofEpochMilli(accumulator.getMinTimestamp());
Instant d2 = value.getEvent().getEventTime();
if(d1.isBefore(d2)) {
accumulator.setMinTimestamp(d1.toEpochMilli());
accumulator.setMaxTimestamp(d2.toEpochMilli());
} else {
accumulator.setMinTimestamp(d2.toEpochMilli());
accumulator.setMaxTimestamp(d1.toEpochMilli());
}
}
if(accumulator.getLocation() == null) {
accumulator.setLocation(value.getEvent().getLatlon().getLat() + "," + value.getEvent().getLatlon().getLon());
}
return accumulator;
}
示例4: calculateLastPassedThreshold
import java.time.Instant; //导入方法依赖的package包/类
/**
* Calculates the last passed threshold given a start point and a current point in time plus a list of thresholds.
* If the amount of time passed between the start and current instant is less than the first interval, it returns
* empty.
* If not, the amount is checked against each fixed interval and the calculated intervals after it. As soon
* as the last passed interval has been determined, it will be returned.
*
* @param start The start instant to compare the current instant with.
* @param current The current instant to compare with the starting point.
* @param thresholds The list of fixed push notification thresholds.
* @return The last passed threshold, or empty if no threshold has been passed yet.
*/
static Optional<Duration> calculateLastPassedThreshold(Instant start, Instant current, List<Duration> thresholds) {
if (current.isBefore(start) || start.equals(current) || thresholds == null || thresholds.isEmpty()) {
throw new IllegalArgumentException("Start must be before current and there should be at least 1 threshold");
}
Duration timePassed = Duration.between(start, current);
if (timePassed.compareTo(thresholds.get(0)) <= 0) {
return Optional.empty();
}
for (int i = 1; i < thresholds.size(); i++) {
if (timePassed.compareTo(thresholds.get(i)) <= 0) {
return Optional.of(thresholds.get(i - 1));
}
}
return Optional.of(thresholds.get(thresholds.size() - 1));
}
开发者ID:pietvandongen,项目名称:pure-bliss-with-pure-java-functions,代码行数:32,代码来源:OfflineDevicesJobImpl.java
示例5: fromFrequency
import java.time.Instant; //导入方法依赖的package包/类
/**
* Create a ChronoSeries from the given frequency information.
*
* @param minimumFrequency minimum frequency
* @param maximumFrequency maximum frequency
* @param frequencyUnit frequency unit
* @param startInstant start timestamp
* @param endInstant end stamp
* @return ChronoSeries from the given frequency information
*/
@NotNull
public static ChronoSeries fromFrequency(long minimumFrequency, long maximumFrequency, @NotNull ChronoUnit frequencyUnit,
@NotNull Instant startInstant, @NotNull Instant endInstant) {
List<Instant> instants = new ArrayList<>();
Instant itrTime = startInstant;
while (itrTime.isBefore(endInstant) || itrTime.equals(endInstant)) {
instants.add(itrTime);
itrTime = itrTime.plus(RandomRegistry.getRandom().nextInt(
(int) (maximumFrequency - minimumFrequency) + 1) + minimumFrequency, frequencyUnit);
}
return of(instants.toArray(new Instant[0]));
}
示例6: rollIfNeeded
import java.time.Instant; //导入方法依赖的package包/类
/**
* If necessary, close the current logfile and open a new one,
* updating {@link #writer}.
*/
private void rollIfNeeded() throws IOException {
// Do not roll unless record is complete, as indicated by flush
if (!flushed) return;
flushed = false;
// If we have not yet passed the roll over mark do nothing
Instant now = Instant.now();
if (now.isBefore(rollAt)) {
return;
}
// New file time, may not be the rollAt time if one or more intervals
// have passed without anything being written
Instant rollTime = now.truncatedTo(rollInterval);
// Determine the name of the file that will be written to
String name = this.baseName + format.format(LocalDateTime.ofInstant(rollTime, timeZone));
this.outPath = this.directory.resolve(name);
// Finish writing to previous log
if (writer != null) {
writer.flush();
writer.close();
}
// Ensure the parent directory always exists, even if it was removed out from under us.
// A no-op if the directory already exists.
Files.createDirectories(outPath.getParent());
// Create new file, set it as our write destination
writer = Files.newBufferedWriter(
outPath,
StandardCharsets.UTF_8,
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
// Point to the next time we want to roll the log, update rollAt
this.rollAt = rollTime.plus(1, rollInterval);
}
示例7: areInSameTimeFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) {
final OffsetDateTime localBase = instant1.atOffset(UTC).withSecond(0).withNano(0);
final OffsetDateTime localStart = localBase.withMinute(localBase.getMinute() - localBase.getMinute() % 5);
final Instant start = localStart.toInstant();
final Instant startOfNext = localStart.plusMinutes(5).toInstant();
return instant2.equals(start) || (instant2.isAfter(start) && instant2.isBefore(startOfNext));
}
示例8: ensureCacheIsFresh
import java.time.Instant; //导入方法依赖的package包/类
private void ensureCacheIsFresh()
{
_logger.info("Called ensureCacheIsFresh");
Instant lastLoading = _jsonWebKeyByKID.getLastReloadInstant().orElse(Instant.MIN);
boolean cacheIsNotFresh = lastLoading.isBefore(Instant.now()
.minus(_jsonWebKeyByKID.getMinTimeBetweenReloads()));
if (cacheIsNotFresh)
{
_logger.info("Invalidating JSON WebKeyID cache");
_jsonWebKeyByKID.clear();
}
}
示例9: duration
import java.time.Instant; //导入方法依赖的package包/类
public static Duration duration(Instant start, Instant end) {
if(isInfPast(start) || isInfFuture(end)) {
return INF_POSITIVE;
} else if(start.isBefore(end)) {
return Duration.between(start, end);
} else {
return Duration.ZERO;
}
}
示例10: tick
import java.time.Instant; //导入方法依赖的package包/类
@Override
public void tick() {
final Duration timeout = config.timeout();
final Duration warning = config.warning();
Instant now = Instant.now();
Instant kickTime = now.minus(timeout);
Instant warnTime = warning == null ? null : now.minus(warning);
Instant lastWarnTime = warning == null || lastCheck == null ? null : lastCheck.minus(warning);
// Iterate over a copy, because kicking players while iterating the original
// OnlinePlayerMapAdapter throws a ConcurrentModificationException
for(Map.Entry<Player, Instant> entry : lastActivity.entrySetCopy()) {
Player player = entry.getKey();
Instant time = entry.getValue();
if(time.isBefore(kickTime)) {
playerServerChanger.kickPlayer(player, CommonsTranslations.get().t("afk.kick", player));
} else if(warnTime != null && time.isAfter(lastWarnTime) && !time.isAfter(warnTime)) {
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_PLING, 1, 1);
player.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + CommonsTranslations.get().t(
"afk.warn", player,
ChatColor.AQUA.toString() + ChatColor.BOLD +
timeout.minus(warning).getSeconds() +
ChatColor.RED + ChatColor.BOLD
));
}
}
lastCheck = now;
}
示例11: heartbeated
import java.time.Instant; //导入方法依赖的package包/类
public Session heartbeated(Instant heartbeatedAt) {
if (heartbeatedAt.isBefore(this.heartbeatedAt)) {
throw new IllegalArgumentException("Heartbeats should be monotonic");
}
return new Session(id, createdAt, heartbeatedAt, heartbeatDelay);
}
示例12: areInSameTimeFrame
import java.time.Instant; //导入方法依赖的package包/类
@Override
public boolean areInSameTimeFrame(final Instant instant1, final Instant instant2) {
final OffsetDateTime localBase = instant1.atOffset(UTC).withSecond(0).withNano(0);
final OffsetDateTime localStart = localBase.withMinute(localBase.getMinute() - localBase.getMinute() % 15);
final Instant start = localStart.toInstant();
final Instant startOfNext = localStart.plusMinutes(15).toInstant();
return instant2.equals(start) || (instant2.isAfter(start) && instant2.isBefore(startOfNext));
}
示例13: isExpired
import java.time.Instant; //导入方法依赖的package包/类
private boolean isExpired(Authorization a) {
try {
DecodedJWT jwt = JWT.decode(a.getAccessToken());
Instant iat = jwt.getExpiresAt().toInstant();
return iat.isBefore(Instant.now());
}
catch (Exception e) {
return true;
}
}
示例14: shouldSendNotification
import java.time.Instant; //导入方法依赖的package包/类
static boolean shouldSendNotification(Instant jobStart, Instant deviceOffline, Instant lastNotification, List<Duration> thresholds) {
Optional<Duration> lastPassedThreshold = calculateLastPassedThreshold(deviceOffline, jobStart, thresholds);
return lastPassedThreshold.isPresent() && (lastNotification.isBefore(deviceOffline) || !lastPassedThreshold.equals(calculateLastPassedThreshold(deviceOffline, lastNotification, thresholds)));
}
示例15: test_isBefore_ObjectNull
import java.time.Instant; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void test_isBefore_ObjectNull() {
Instant a = Instant.ofEpochSecond(0L, 0);
a.isBefore(null);
}