Example usage for com.google.common.math LongMath mean

List of usage examples for com.google.common.math LongMath mean

Introduction

In this page you can find the example usage for com.google.common.math LongMath mean.

Prototype

public static long mean(long x, long y) 

Source Link

Document

Returns the arithmetic mean of x and y , rounded toward negative infinity.

Usage

From source file:com.teradata.benchto.driver.listeners.BenchmarkServiceExecutionListener.java

private void checkClocksSync() {
    long timeBefore = System.currentTimeMillis();
    long serviceTime = benchmarkServiceClient.getServiceCurrentTime().toEpochMilli();
    long timeAfter = System.currentTimeMillis();

    long driftApproximation = Math.abs(LongMath.mean(timeBefore, timeAfter) - serviceTime);
    long approximationPrecision = timeAfter - LongMath.mean(timeBefore, timeAfter);

    Duration driftLowerBound = Duration.of(driftApproximation - approximationPrecision, ChronoUnit.MILLIS);

    if (driftLowerBound.compareTo(MAX_CLOCK_DRIFT) > 1) {
        throw new RuntimeException(
                format("Detected driver and service clocks drift of at least %s, assumed sane maximum is %s",
                        driftLowerBound, MAX_CLOCK_DRIFT));
    }//from www  .  j  a v a 2 s  .  c  o  m
}