当前位置: 首页>>代码示例>>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;未经允许,请勿转载。