本文整理汇总了Java中java.time.Duration.isZero方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.isZero方法的具体用法?Java Duration.isZero怎么用?Java Duration.isZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.isZero方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: format
import java.time.Duration; //导入方法依赖的package包/类
public String format(Duration object) {
if (object.isZero()) {
return "0";
}
if (Duration.ofDays(object.toDays()).equals(object)) {
return object.toDays() + "d";
}
if (Duration.ofHours(object.toHours()).equals(object)) {
return object.toHours() + "h";
}
if (Duration.ofMinutes(object.toMinutes()).equals(object)) {
return object.toMinutes() + "m";
}
if (Duration.ofSeconds(object.getSeconds()).equals(object)) {
return object.getSeconds() + "s";
}
if (Duration.ofMillis(object.toMillis()).equals(object)) {
return object.toMillis() + "ms";
}
return object.toNanos() + "ns";
}
示例2: splitSeries
import java.time.Duration; //导入方法依赖的package包/类
/**
* Splits the time series into sub-series lasting sliceDuration.<br>
* The current time series is splitted every splitDuration.<br>
* The last sub-series may last less than sliceDuration.
* @param series the time series to split
* @param splitDuration the duration between 2 splits
* @param sliceDuration the duration of each sub-series
* @return a list of sub-series
*/
public static List<TimeSeries> splitSeries(TimeSeries series, Duration splitDuration, Duration sliceDuration) {
ArrayList<TimeSeries> subseries = new ArrayList<>();
if (splitDuration != null && !splitDuration.isZero()
&& sliceDuration != null && !sliceDuration.isZero()) {
List<Integer> beginIndexes = getSplitBeginIndexes(series, splitDuration);
for (Integer subseriesBegin : beginIndexes) {
subseries.add(subseries(series, subseriesBegin, sliceDuration));
}
}
return subseries;
}
示例3: checkIfBackoffDelayNeeded
import java.time.Duration; //导入方法依赖的package包/类
void checkIfBackoffDelayNeeded() {
Duration delay = backoffStrategy.getDelayTime(failureAverage.getAverage());
if (!delay.isZero() && !delay.isNegative()) {
backoffEndTime = Clock.systemUTC().instant().plus(delay);
manager.scheduleTask(new UpdateTimerTask(), delay);
}
}
示例4: isPositive
import java.time.Duration; //导入方法依赖的package包/类
/**
* Asserts that the given duration is positive (non-negative and non-zero).
*
* @param duration Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Duration if positive.
*/
public static Duration isPositive(Duration duration, String fieldName) {
if (duration == null) {
throw new IllegalArgumentException(String.format("%s cannot be null", fieldName));
}
if (duration.isNegative() || duration.isZero()) {
throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
}
return duration;
}
示例5: assertIsPositive
import java.time.Duration; //导入方法依赖的package包/类
/**
* Asserts that the given duration is positive (non-negative and non-zero).
*
* @param duration Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Duration if positive.
*/
public static Duration assertIsPositive(Duration duration, String fieldName) {
assertNotNull(duration, fieldName);
if (duration.isNegative() || duration.isZero()) {
throw new IllegalArgumentException(String.format("%s must be positive", fieldName));
}
return duration;
}
示例6: validate
import java.time.Duration; //导入方法依赖的package包/类
@Override
public void validate(Duration value, @Nullable Node node) throws InvalidXMLException {
if(value.isZero()) {
throw new InvalidXMLException("Time cannot be zero", node);
}
}
示例7: calculateConfidence
import java.time.Duration; //导入方法依赖的package包/类
@VisibleForTesting
BigDecimal calculateConfidence(Instant time, Instant now) {
Duration duration = Duration.between(time, now);
if (duration.isZero() || duration.isNegative()) {
return ONE;
}
// Number from 0 to 29 (= 100 years)
double scaled = Math.log(duration.toMillis());
// Number from 0.00 to 0.79
double multiplied = scaled * Math.E / 100;
// Number from 100.00 to 0.21
double confidence = 1 - multiplied;
// Sanitize in case if +3000 years...
return BigDecimal.valueOf(confidence).max(ZERO).setScale(SCALE, HALF_UP);
}
示例8: LongRunningMessageHandler
import java.time.Duration; //导入方法依赖的package包/类
LongRunningMessageHandler(@NonNull ScheduledExecutorService timeoutExtensionExecutor,
int maxNumberOfMessages, int numberOfThreads,
@NonNull MessageHandlingRunnableFactory messageHandlingRunnableFactory,
@NonNull VisibilityTimeoutExtenderFactory timeoutExtenderFactory,
@NonNull MessageWorkerWithHeaders<I, O> worker, @NonNull Queue queue,
@NonNull FinishedMessageCallback<I, O> finishedMessageCallback,
@NonNull Duration timeUntilVisibilityTimeoutExtension,
@NonNull Duration awaitShutDown) {
if (timeUntilVisibilityTimeoutExtension.isZero() || timeUntilVisibilityTimeoutExtension
.isNegative()) {
throw new IllegalArgumentException("the timeout has to be > 0");
}
this.timeoutExtensionExecutor = timeoutExtensionExecutor;
this.messageHandlingRunnableFactory = messageHandlingRunnableFactory;
this.timeoutExtenderFactory = timeoutExtenderFactory;
this.worker = worker;
this.queue = queue;
this.finishedMessageCallback = finishedMessageCallback;
this.timeUntilVisibilityTimeoutExtension = timeUntilVisibilityTimeoutExtension;
messageProcessingExecutor = new ThreadPoolTaskExecutor();
messageProcessingExecutor.setMaxPoolSize(numberOfThreads);
messageProcessingExecutor.setCorePoolSize(numberOfThreads);
/*
* Since we only accept new messages if one slot in the messagesInProcessing-Set
* / executor is free we can schedule at least one message for instant execution
* while (maxNumberOfMessages - 1) will be put into the queue
*/
messageProcessingExecutor.setQueueCapacity(maxNumberOfMessages - 1);
messageProcessingExecutor.setAwaitTerminationSeconds((int) awaitShutDown.getSeconds());
if (awaitShutDown.getSeconds() > 0) {
Runtime.getRuntime().addShutdownHook(new Thread(messageProcessingExecutor::shutdown));
}
messageProcessingExecutor.afterPropertiesSet();
messagesInProcessing = new SetWithUpperBound<>(numberOfThreads);
if (queue.getDefaultVisibilityTimeout().minusSeconds(5).compareTo(
timeUntilVisibilityTimeoutExtension) < 0) {
throw new IllegalStateException("The extension interval of "
+ timeUntilVisibilityTimeoutExtension.getSeconds()
+ " is too close to the VisibilityTimeout of " + queue
.getDefaultVisibilityTimeout().getSeconds()
+ " seconds of the queue, has to be at least 5 seconds less.");
}
}