Package org.drasyl.util
Class SerialNumberArithmetic
java.lang.Object
org.drasyl.util.SerialNumberArithmetic
Utility class for serial number arithmetic.
-
Method Summary
Modifier and TypeMethodDescriptionstatic long
add
(long s, long n, int serialBits) static boolean
greaterThan
(long i1, long i2, int serialBits) static boolean
greaterThanOrEqualTo
(long i1, long i2, int serialBits) static boolean
lessThan
(long i1, long i2, int serialBits) static boolean
lessThanOrEqualTo
(long i1, long i2, int serialBits)
-
Method Details
-
add
public static long add(long s, long n, int serialBits) - Parameters:
s
- sequence number we want increment. Must be non-negative.n
- number to add. Must be within range[0, (2^(serialBits - 1) - 1)]
serialBits
- size of the serial number space- Returns:
- resulting sequence number of the addition
-
lessThan
public static boolean lessThan(long i1, long i2, int serialBits) - Parameters:
i1
- first non-negative numberi2
- second non-negative numberserialBits
- size of the serial number space- Returns:
true
ifi1
is less thani2
. Otherwisefalse
-
lessThanOrEqualTo
public static boolean lessThanOrEqualTo(long i1, long i2, int serialBits) - Parameters:
i1
- first non-negative numberi2
- second non-negative numberserialBits
- size of the serial number space- Returns:
true
ifi1
is less than or equal toi2
. Otherwisefalse
-
greaterThan
public static boolean greaterThan(long i1, long i2, int serialBits) - Parameters:
i1
- first non-negative numberi2
- second non-negative numberserialBits
- size of the serial number space- Returns:
true
ifi1
is greater thani2
. Otherwisefalse
-
greaterThanOrEqualTo
public static boolean greaterThanOrEqualTo(long i1, long i2, int serialBits) - Parameters:
i1
- first non-negative numberi2
- second non-negative numberserialBits
- size of the serial number space- Returns:
true
ifi1
is greater than or equal toi2
. Otherwisefalse
-