當前位置: 首頁>>代碼示例>>Java>>正文


Java Duration.compareTo方法代碼示例

本文整理匯總了Java中java.time.Duration.compareTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.compareTo方法的具體用法?Java Duration.compareTo怎麽用?Java Duration.compareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Duration的用法示例。


在下文中一共展示了Duration.compareTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getReport

import java.time.Duration; //導入方法依賴的package包/類
@Override
public Report getReport() {
    Instant timestamp = lastPollTimestamp;
    if (timestamp != null) {
        Duration duration = Duration.between(timestamp, Instant.now(clock));
        if (duration.compareTo(criticalThreshold) > 0) {
            return new Report(CRITICAL, format("potentially stale. Last up-to-date at at %s. (%s ago).", timestamp, duration));
        } else if (duration.compareTo(warningThreshold) > 0) {
            return new Report(WARNING, format("potentially stale. Last up-to-date at at %s. (%s ago).", timestamp, duration));
        } else {
            return new Report(OK, format("up-to-date at at %s. (%s ago). Current version: %s", timestamp, duration, currentPosition));
        }
    }

    return new Report(INFO, "Awaiting initial catchup. Current version: " + currentPosition);
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:17,代碼來源:ChaserHealth.java

示例2: render

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void render(Instant now, Graphics2D g, CharacterPosition pos, Riho riho) {
    Duration currentLoopTime = Duration.between(getLoopStartTime(), now);
    long millis = currentLoopTime.toMillis();
    boolean visible = true;
    if (millis < 800) {
        visible = ((millis / 200) % 2) == 0;
    }

    if (visible) {
        ImageUtil.drawImage(g, image, pos.getX() - ImageUtil.defaultScale(25), pos.getY() + ImageUtil.defaultScale(10), fadeAnim.getValue(now));
    }

    if (currentLoopTime.compareTo(ANIM_DURATION) > 0) {
        nextLoop();
        fadeAnim.resetAndRestart(now);
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:19,代碼來源:SurprisedRenderer.java

示例3: render

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void render(Instant now, Graphics2D g, CharacterPosition pos, Riho riho) {
    Duration time = currentLoopDuration(now);

    int x = (int) moveX.getValue(now);
    int y = (int) moveY.getValue(now);
    double alpha = fade.getValue(now);

    x += ImageUtil.defaultScale(40);
    y += ImageUtil.defaultScale(130);

    ImageUtil.drawImage(g, emotionImage, pos.getX() + x, pos.getY() + y, alpha);

    if (time.compareTo(animationTime) > 0) {
        nextLoop();
        moveX.resetAndRestart(now);
        moveY.resetAndRestart(now);
        fade.resetAndRestart(now);
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:21,代碼來源:MojaRenderer.java

示例4: render

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void render(Instant now, Graphics2D g, CharacterPosition pos, Riho riho) {
    Duration time = currentLoopDuration(now);

    int x = (int) moveX.getValue(now);
    int y = (int) moveY.getValue(now);
    double alpha = fade.getValue(now);

    x += ImageUtil.defaultScale(350);

    ImageUtil.drawImage(g, emotionImage, pos.getX() + x, pos.getY() + y, alpha);

    if (time.compareTo(animationTime) > 0) {
        nextLoop();
        moveX.resetAndRestart(now);
        moveY.resetAndRestart(now);
        fade.resetAndRestart(now);
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:20,代碼來源:AngerRenderer.java

示例5: calculateLastPassedThreshold

import java.time.Duration; //導入方法依賴的package包/類
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,代碼行數:20,代碼來源:OfflineDevicesJobImpl.java

示例6: calculateLastPassedThreshold

import java.time.Duration; //導入方法依賴的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

示例7: classify

import java.time.Duration; //導入方法依賴的package包/類
public Status classify(Duration duration) {
    if (duration.compareTo(critical) > 0)
        return Status.CRITICAL;
    else if (duration.compareTo(warning) > 0)
        return Status.WARNING;
    else
        return Status.OK;
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:9,代碼來源:DurationThreshold.java

示例8: BlockProcessResult

import java.time.Duration; //導入方法依賴的package包/類
public BlockProcessResult(boolean additionalValidations, Map<ByteArrayWrapper, ImportResult> result, String blockHash, Duration processingTime) {
    this.additionalValidationsOk = additionalValidations;
    this.result = result;
    if (processingTime.compareTo(LOG_TIME_LIMIT) >= 0) {
        logResult(blockHash, processingTime);
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:8,代碼來源:BlockProcessResult.java

示例9: render

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void render(Instant now, Graphics2D g, CharacterPosition pos, Riho riho) {
    Duration time = currentLoopDuration(now);
    double y = move.getValue(now) - ImageUtil.defaultScale(80);
    double alpha = time.compareTo(fadeOutDelay) > 0 ? fadeOut.getValue(now) : fadeIn.getValue(now);

    ImageUtil.drawImage(g, emotionImage, pos.getX() - ImageUtil.defaultScale(100), (int) (pos.getY() + y), alpha);

    if (time.compareTo(animationTime) > 0) {
        nextLoop();
        fadeIn.resetAndRestart(now);
        fadeOut.resetAndRestart(now);
        move.resetAndRestart(now);
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:16,代碼來源:SadRenderer.java

示例10: render

import java.time.Duration; //導入方法依賴的package包/類
@Override
public void render(Instant now, Graphics2D g, CharacterPosition pos, Riho riho) {
    Duration currentLoopTime = Duration.between(getLoopStartTime(), now);
    long millis = currentLoopTime.toMillis();

    BufferedImage image = images[(int) ((millis / 200) % 2)];
    ImageUtil.drawImage(g, image, pos.getX() - ImageUtil.defaultScale(25), pos.getY() + ImageUtil.defaultScale(200), fadeAnim.getValue(now));

    if (currentLoopTime.compareTo(ANIM_DURATION) > 0) {
        nextLoop();
        fadeAnim.resetAndRestart(now);
    }
}
 
開發者ID:orekyuu,項目名稱:Riho,代碼行數:14,代碼來源:SweatRenderer.java

示例11: RegistrationManager

import java.time.Duration; //導入方法依賴的package包/類
public RegistrationManager(CoapServer server, URI registrationUri, ScheduledExecutorService scheduledExecutor,
        Duration minRetryDelay, Duration maxRetryDelay) {

    if (minRetryDelay.compareTo(maxRetryDelay) > 0) {
        throw new IllegalArgumentException();
    }

    this.epName = epNameFrom(registrationUri);
    this.client = new CoapClient(new InetSocketAddress(registrationUri.getHost(), registrationUri.getPort()), server);
    this.scheduledExecutor = scheduledExecutor;
    this.registrationUri = registrationUri;
    this.registrationLinks = () -> LinkFormatBuilder.toString(server.getResourceLinks());
    this.minRetryDelay = minRetryDelay;
    this.maxRetryDelay = maxRetryDelay;
}
 
開發者ID:ARMmbed,項目名稱:java-coap,代碼行數:16,代碼來源:RegistrationManager.java

示例12: nextDelay

import java.time.Duration; //導入方法依賴的package包/類
Duration nextDelay(Duration lastDelay) {
    Duration newDelay = lastDelay.multipliedBy(2);

    if (newDelay.compareTo(minRetryDelay) < 0) {
        return minRetryDelay;
    }
    if (newDelay.compareTo(maxRetryDelay) > 0) {
        return maxRetryDelay;
    }
    return newDelay;
}
 
開發者ID:ARMmbed,項目名稱:java-coap,代碼行數:12,代碼來源:RegistrationManager.java

示例13: min

import java.time.Duration; //導入方法依賴的package包/類
public static Duration min(Duration a, Duration b) {
    return a.compareTo(b) <= 0 ? a : b;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:4,代碼來源:TimeUtils.java

示例14: max

import java.time.Duration; //導入方法依賴的package包/類
public static Duration max(Duration a, Duration b) {
    return a.compareTo(b) >= 0 ? a : b;
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:4,代碼來源:TimeUtils.java

示例15: DurationThreshold

import java.time.Duration; //導入方法依賴的package包/類
public DurationThreshold(Duration warning, Duration critical) {
    this.warning = requireNonNull(warning);
    this.critical = requireNonNull(critical);
    if (critical.compareTo(warning) < 0)
        throw new IllegalArgumentException("Critical threshold must not be less than warning threshold");
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:7,代碼來源:DurationThreshold.java


注:本文中的java.time.Duration.compareTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。