Example usage for com.google.common.primitives UnsignedLong compareTo

List of usage examples for com.google.common.primitives UnsignedLong compareTo

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedLong compareTo.

Prototype

@Override
    public int compareTo(UnsignedLong o) 

Source Link

Usage

From source file:org.opennms.newts.api.Counter.java

@Override
public ValueType<UnsignedLong> delta(Number value) {

    UnsignedLong previous = toUnsignedLong(value);

    // If previous value is greater-than this one, we've wrapped
    if (previous.compareTo(getValue()) > 0) {
        UnsignedLong count32 = getValue().plus(MAX32).plus(UnsignedLong.ONE);

        // Still smaller, this is a 64-bit counter wrap
        if (previous.compareTo(count32) > 0) {
            return new Counter(MAX64.minus(previous).plus(getValue()).plus(UnsignedLong.ONE));
        }//from ww  w.jav  a2  s  . c o m
        // Process as 32-bit counter wrap
        else {
            return new Counter(MAX32.minus(previous).plus(getValue())).plus(UnsignedLong.ONE);
        }
    }
    // ...no counter wrap has occurred.
    else {
        return new Counter(getValue().minus(previous));
    }
}