当前位置: 首页>>代码示例>>Java>>正文


Java Duration.isZero方法代码示例

本文整理汇总了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";
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:22,代码来源:DurationConverter.java

示例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;
}
 
开发者ID:ta4j,项目名称:ta4j,代码行数:22,代码来源:WalkForward.java

示例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);
    }
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:8,代码来源:SqsConsumer.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:18,代码来源:Validate.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:15,代码来源:ValidationUtils.java

示例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);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:7,代码来源:DurationIs.java

示例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);

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:23,代码来源:LastEstimator.java

示例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.");
    }
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:47,代码来源:LongRunningMessageHandler.java


注:本文中的java.time.Duration.isZero方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。