當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。